Skip to content

Commit 5b590ec

Browse files
committed
Merge branch 'dev' of https://github.com/Caltech-IPAC/Firefly into dev
2 parents 0c305c0 + f2d57a5 commit 5b590ec

22 files changed

+1651
-1023
lines changed

src/firefly/js/api/ApiBuild.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import {ApiExpandedDisplay} from '../visualize/ui/ApiExpandedDisplay.jsx';
3333
import {TablesContainer} from '../tables/ui/TablesContainer.jsx';
3434
import {TablePanel} from '../tables/ui/TablePanel.jsx';
3535
import {ChartsContainer} from '../charts/ui/ChartsContainer.jsx';
36-
import {ChartsTableViewPanel} from '../charts/ui/ChartsTableViewPanel.jsx';
36+
import {ChartPanel} from '../charts/ui/ChartPanel.jsx';
37+
3738
import {Histogram} from '../charts/ui/Histogram.jsx';
3839
import {PopupMouseReadoutMinimal} from '../visualize/ui/PopupMouseReadoutMinimal.jsx';
3940
import {PopupMouseReadoutFull} from '../visualize/ui/PopupMouseReadoutFull.jsx';
@@ -183,7 +184,7 @@ export function buildLowlevelAPI() {
183184
TablesContainer,
184185
TablePanel,
185186
ChartsContainer,
186-
ChartsTableViewPanel,
187+
ChartPanel,
187188
Histogram,
188189
PopupMouseReadoutMinimal,
189190
PopupMouseReadoutFull

src/firefly/js/api/ApiExpandedView.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {ChartsContainer} from '../charts/ui/ChartsContainer.jsx';
1111
import {ApiExpandedDisplay} from '../visualize/ui/ApiExpandedDisplay.jsx';
1212
import {dispatchChangeExpandedMode, ExpandType} from '../visualize/ImagePlotCntlr.js';
1313
import {dispatchSetLayoutMode, getExpandedMode, LO_MODE, LO_VIEW} from '../core/LayoutCntlr.js';
14+
import {getExpandedChartProps} from '../charts/ChartsCntlr.js';
1415

1516
// import {deepDiff} from '../util/WebUtil.js';
1617

@@ -23,9 +24,8 @@ export class ApiExpandedView extends Component {
2324
dispatchSetLayoutMode(LO_MODE.expanded, LO_VIEW.none);
2425
};
2526
const images = (<ApiExpandedDisplay closeFunc={closeFunc}/>);
26-
const xyPlots = (<ChartsContainer expandedMode={true} closeable={true}/>);
2727
const tables = (<TablesContainer mode='expanded' />);
28-
this.state = {images, xyPlots, tables};
28+
this.state = {images, tables};
2929
}
3030

3131
componentDidMount() {
@@ -55,10 +55,11 @@ export class ApiExpandedView extends Component {
5555
// }
5656

5757
render() {
58-
var {expanded, images, xyPlots, tables} = this.state;
58+
var {expanded, images, tables} = this.state;
5959
expanded = LO_VIEW.get(expanded) || LO_VIEW.none;
60+
const {chartId} = expanded === LO_VIEW.xyPlots ? getExpandedChartProps() : {};
6061
const view = expanded === LO_VIEW.tables ? tables
61-
: expanded === LO_VIEW.xyPlots ? xyPlots
62+
: expanded === LO_VIEW.xyPlots ? (<ChartsContainer key='api' expandedMode={true} closeable={true} chartId={chartId}/>)
6263
: images;
6364
if (expanded === LO_VIEW.none) {
6465
document.body.style.overflow= this.saveOverflow;

src/firefly/js/api/ApiHighlevelBuild.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ function doShowXYPlot(llApi, targetDiv, params={}) {
394394
const {renderDOM} = llApi.util;
395395
const {makeFileRequest, getActiveTableId} = llApi.util.table;
396396
const {makeXYPlotParams, uniqueChartId} = llApi.util.chart;
397-
const {ChartsTableViewPanel}= llApi.ui;
397+
const {ChartsContainer}= llApi.ui;
398398
const {addActionListener} = llApi.util;
399399

400400
if ((typeof targetDiv).match(/string|HTMLDivElement/) === null) {
@@ -423,7 +423,7 @@ function doShowXYPlot(llApi, targetDiv, params={}) {
423423
dispatchTableFetch(searchRequest);
424424
}
425425

426-
const chartId = uniqueChartId();
426+
const chartId = targetDiv;
427427

428428
if (tblGroup) {
429429
tblId = getActiveTableId(tblGroup);
@@ -455,10 +455,9 @@ function doShowXYPlot(llApi, targetDiv, params={}) {
455455
}
456456
]});
457457

458-
renderDOM(targetDiv, ChartsTableViewPanel,
458+
renderDOM(targetDiv, ChartsContainer,
459459
{
460460
key: `${targetDiv}-xyplot`,
461-
tblId,
462461
chartId,
463462
closeable: false,
464463
expandedMode: false
@@ -472,7 +471,7 @@ function doShowHistogram(llApi, targetDiv, params={}) {
472471
const {renderDOM} = llApi.util;
473472
const {makeFileRequest, getActiveTableId} = llApi.util.table;
474473
const {makeHistogramParams, uniqueChartId} = llApi.util.chart;
475-
const {ChartsTableViewPanel}= llApi.ui;
474+
const {ChartsContainer}= llApi.ui;
476475
const {addActionListener} = llApi.util;
477476

478477
const histogramParams = makeHistogramParams(params);
@@ -494,7 +493,7 @@ function doShowHistogram(llApi, targetDiv, params={}) {
494493
dispatchTableFetch(searchRequest);
495494
}
496495

497-
const chartId = uniqueChartId();
496+
const chartId = targetDiv;
498497

499498
if (tblGroup) {
500499
tblId = getActiveTableId(tblGroup);
@@ -525,10 +524,9 @@ function doShowHistogram(llApi, targetDiv, params={}) {
525524
}
526525
]});
527526

528-
renderDOM(targetDiv, ChartsTableViewPanel,
527+
renderDOM(targetDiv, ChartsContainer,
529528
{
530529
key: `${targetDiv}-histogram`,
531-
tblId,
532530
chartId,
533531
closeable: false,
534532
expandedMode: false

src/firefly/js/charts/ChartType.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
3+
*/
4+
5+
6+
import {logError} from '../util/WebUtil.js';
7+
8+
/**
9+
* @global
10+
* @public
11+
* @typedef {Object} ChartType - an object which specifies how to render a chart type
12+
* @prop {string} id - unique chart type id
13+
* @prop {Function} Chart - React functional component to render chart part: Chart({chartId, ...chartProps, widthPx, heightPx})
14+
* @prop {Function} Options - React functional component to render chart options: Options({chartId, optionsKey})
15+
* @prop {Function} Toolbar - React functional component to render toolbar: Toolbar({chartId, expandable, expandedMode, toggleOptions})
16+
* @prop {Function} getChartProperties - function to get chart properties: getChartProperties(chartId)
17+
* @prop {Function} updateOnStoreChange - function with returns true if chart needs to update on store update: updateOnStoreChange(prevChartProps)
18+
*/
19+
20+
const chartTypes = [];
21+
22+
23+
/**
24+
* Get chart data type
25+
* @param id
26+
* @returns {ChartType}
27+
*/
28+
function getChartType(id) {
29+
return chartTypes.find((el) => {
30+
return el.id === id;
31+
});
32+
}
33+
34+
/**
35+
* Add chart data type
36+
* @param {ChartType} chartType
37+
*/
38+
function addChartType(chartType) {
39+
const id = {chartType};
40+
if (!id) {
41+
logError('[ChartTypes] unable to add: missing id');
42+
return;
43+
}
44+
if (chartTypes.find((el) => {
45+
return el.id === id;
46+
})) {
47+
logError(`[ChartTypes] unable to add: id ${id} is already used`);
48+
return;
49+
}
50+
// more validation?
51+
chartTypes.push(chartType);
52+
}
53+
54+
/**
55+
* Create a factory to manage chart data types
56+
* @param {Array<ChartType>} predefinedTypes
57+
* @return {{getChartType:Function, addChartType:Function}}
58+
*/
59+
export function chartTypeFactory(predefinedTypes)
60+
{
61+
predefinedTypes.forEach((cdt) => addChartType(cdt));
62+
return {
63+
getChartType,
64+
addChartType
65+
};
66+
}

src/firefly/js/charts/ChartsCntlr.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ const FIRST_CDEL_ID = '0'; // first data element id (if missing)
5959
* @function dispatchChartAdd
6060
* @memberof firefly.action
6161
*/
62-
export function dispatchChartAdd({chartId, chartType, chartDataElements, groupId='main', deletable, help_id, dispatcher= flux.process}) {
63-
dispatcher({type: CHART_ADD, payload: {chartId, chartType, chartDataElements, deletable, help_id, groupId}});
62+
export function dispatchChartAdd({chartId, chartType, chartDataElements, groupId='main', deletable, help_id, mounted=0, dispatcher= flux.process}) {
63+
dispatcher({type: CHART_ADD, payload: {chartId, chartType, chartDataElements, groupId, deletable, help_id, mounted}});
6464
}
6565

6666
/*
@@ -144,6 +144,7 @@ export function dispatchChartExpanded(chartId, dispatcher=flux.process) {
144144
dispatcher( {type: CHART_UI_EXPANDED, payload: {chartId}});
145145
}
146146

147+
147148
/*
148149
* Dispatched when chart becomes visible (is rendered for the first time after being invisible)
149150
* When chart is mounted, its data need to be in sync with the related table
@@ -368,13 +369,20 @@ function reduceData(state={}, action={}) {
368369
//if (chartActions.indexOf(action.type) < 0) { return state; } // useful when debugging
369370
switch (action.type) {
370371
case (CHART_ADD) :
371-
const {chartId, chartType, groupId, deletable, help_id, chartDataElements} = action.payload;
372+
{
373+
const {chartId, chartType, chartDataElements, ...rest} = action.payload;
372374

373375
state = updateSet(state, chartId,
374-
omitBy({chartType, chartDataElements: chartDataElementsToObj(chartDataElements), groupId, deletable, help_id}, isUndefined));
376+
omitBy({
377+
chartType,
378+
chartDataElements: chartDataElementsToObj(chartDataElements),
379+
...rest
380+
}, isUndefined));
375381
return state;
382+
}
376383
case (CHART_REMOVE) :
377-
{ const {chartId} = action.payload;
384+
{
385+
const {chartId} = action.payload;
378386
return omit(state, chartId);
379387
}
380388
case (CHART_DATA_FETCH) :
@@ -564,11 +572,13 @@ export function updateRelatedData(tblId, invokedBy) {
564572
});
565573
}
566574

567-
export function updateChartData(chartId) {
575+
export function updateChartData(chartId, tblId) {
568576
const chartDataElements = get(flux.getState(), [CHART_SPACE_PATH, 'data', chartId, 'chartDataElements']);
569577
if (chartDataElements) {
570578
Object.keys(chartDataElements).forEach((id) => {
571-
dispatchChartDataFetch({chartId, chartDataElement: chartDataElements[id]});
579+
if (chartDataElements[id].tblId === tblId) {
580+
dispatchChartDataFetch({chartId, chartDataElement: chartDataElements[id]});
581+
}
572582
});
573583
}
574584
}

0 commit comments

Comments
 (0)