Skip to content

Commit 5d40c1c

Browse files
committed
Move adding default chart to a separate saga to make sure it triggers layout update.
1 parent f328037 commit 5d40c1c

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

src/firefly/js/templates/fireflyviewer/FireflyViewer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {TriViewPanel} from './TriViewPanel.jsx';
1818
import {VisHeader} from '../../visualize/ui/VisHeader.jsx';
1919
import {getActionFromUrl} from '../../core/History.js';
2020
import {launchImageMetaDataSega} from '../../visualize/ui/TriViewImageSection.jsx';
21-
import {syncChartViewer} from '../../visualize/saga/ChartsSync.js';
21+
import {syncChartViewer, addDefaultScatter} from '../../visualize/saga/ChartsSync.js';
2222
import {dispatchAddSaga} from '../../core/MasterSaga.js';
2323

2424
// import {deepDiff} from '../util/WebUtil.js';
@@ -45,6 +45,7 @@ export class FireflyViewer extends Component {
4545
this.state = this.getNextState();
4646
dispatchAddSaga(layoutManager,{views: props.views});
4747
dispatchAddSaga(syncChartViewer);
48+
dispatchAddSaga(addDefaultScatter);
4849
}
4950

5051
getNextState() {

src/firefly/js/templates/fireflyviewer/FireflyViewerManager.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import {get, filter, omitBy, isNil, isEmpty} from 'lodash';
77

88
import {LO_VIEW, LO_MODE, SHOW_DROPDOWN, SET_LAYOUT_MODE, getLayouInfo, dispatchUpdateLayoutInfo} from '../../core/LayoutCntlr.js';
99
import {clone} from '../../util/WebUtil.js';
10-
import {findGroupByTblId, getTblIdsByGroup,getActiveTableId, getTableInGroup} from '../../tables/TableUtil.js';
10+
import {findGroupByTblId, getTblIdsByGroup,getActiveTableId} from '../../tables/TableUtil.js';
1111
import {TBL_RESULTS_ADDED, TABLE_LOADED, TABLE_REMOVE, TBL_RESULTS_ACTIVE} from '../../tables/TablesCntlr.js';
12-
import {CHART_ADD, CHART_REMOVE, getNumCharts, dispatchChartAdd} from '../../charts/ChartsCntlr.js';
13-
import {getDefaultXYPlotOptions, DT_XYCOLS} from '../../charts/dataTypes/XYColsCDT.js';
14-
import {SCATTER} from '../../charts/ChartUtil.js';
12+
import {CHART_ADD, CHART_REMOVE} from '../../charts/ChartsCntlr.js';
13+
1514
import ImagePlotCntlr from '../../visualize/ImagePlotCntlr.js';
1615
import {isMetaDataTable, isCatalogTable} from '../../metaConvert/converterUtils.js';
1716
import {META_VIEWER_ID} from '../../visualize/ui/TriViewImageSection.jsx';
@@ -145,24 +144,6 @@ function handleNewTable(action, images, showImages, showTables, coverageLockedOn
145144

146145
const {tbl_id} = action.payload;
147146

148-
// check if a default chart needs to be added
149-
if (getNumCharts(tbl_id) === 0) {
150-
// how do I know the default chart should be added?
151-
// add a default chart if the group is main
152-
if (getTableInGroup(tbl_id, 'main')) {
153-
// default chart is xy plot of coordinate columns or first two numeric columns
154-
const defaultOptions = getDefaultXYPlotOptions(tbl_id);
155-
if (defaultOptions) {
156-
dispatchChartAdd({
157-
chartId: 'xyplot-' + tbl_id,
158-
chartType: SCATTER,
159-
groupId: tbl_id,
160-
chartDataElements: [{tblId: tbl_id, type: DT_XYCOLS, options: defaultOptions}]
161-
});
162-
}
163-
}
164-
}
165-
166147
// check for catalog or meta images
167148
if (!showTables) return [showImages, images, coverageLockedOn]; // ignores this if table is not visible
168149

src/firefly/js/visualize/saga/ChartsSync.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import * as TableStatsCntlr from '../../charts/TableStatsCntlr.js';
99
import * as TableUtil from '../../tables/TableUtil.js';
1010
import * as ChartsCntlr from '../../charts/ChartsCntlr.js';
1111

12+
import {getDefaultXYPlotOptions, DT_XYCOLS} from '../../charts/dataTypes/XYColsCDT.js';
13+
import {SCATTER} from '../../charts/ChartUtil.js';
14+
1215
import {PLOT2D, DEFAULT_PLOT2D_VIEWER_ID, dispatchAddViewerItems, dispatchRemoveViewerItems, getViewerItemIds, getMultiViewRoot} from '../../visualize/MultiViewCntlr.js';
1316

1417
/**
@@ -67,6 +70,33 @@ export function* syncChartViewer() {
6770
}
6871
}
6972

73+
/**
74+
* This saga adds a default chart
75+
*/
76+
export function* addDefaultScatter() {
77+
while (true) {
78+
const action = yield take([TablesCntlr.TABLE_LOADED]);
79+
const {tbl_id} = action.payload;
80+
// check if a default chart needs to be added
81+
if (ChartsCntlr.getNumCharts(tbl_id) === 0) {
82+
// how do I know the default chart should be added?
83+
// add a default chart if the group is main
84+
if (TableUtil.getTableInGroup(tbl_id, 'main')) {
85+
// default chart is xy plot of coordinate columns or first two numeric columns
86+
const defaultOptions = getDefaultXYPlotOptions(tbl_id);
87+
if (defaultOptions) {
88+
ChartsCntlr.dispatchChartAdd({
89+
chartId: 'xyplot-' + tbl_id,
90+
chartType: SCATTER,
91+
groupId: tbl_id,
92+
chartDataElements: [{tblId: tbl_id, type: DT_XYCOLS, options: defaultOptions}]
93+
});
94+
}
95+
}
96+
}
97+
}
98+
}
99+
70100

71101
function updateDefaultViewer() {
72102
const tblId = TableUtil.getActiveTableId();

0 commit comments

Comments
 (0)