Skip to content

Commit c4ad483

Browse files
author
Cindy Wang
committed
DM-11477 update the logic for rendering tool bar 'select' button and XY options for chart options side bar.
1 parent 93d8631 commit c4ad483

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

src/firefly/js/charts/ui/PlotlyToolbar.jsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {get, isEmpty} from 'lodash';
44

55
import {dispatchChartUpdate, dispatchChartFilterSelection, dispatchChartSelect, getChartData, dispatchSetActiveTrace, dispatchChartExpanded} from '../ChartsCntlr.js';
66
import {SimpleComponent} from '../../ui/SimpleComponent.jsx';
7-
import {getTblById, clearFilters, getColumnIdx} from '../../tables/TableUtil.js';
7+
import {getTblById, clearFilters, getColumnIdx, getColumnType} from '../../tables/TableUtil.js';
88
import {dispatchSetLayoutMode, LO_MODE, LO_VIEW} from '../../core/LayoutCntlr.js';
99
import {downloadChart} from './PlotlyWrapper.jsx';
1010

@@ -45,29 +45,36 @@ export class ScatterToolbar extends SimpleComponent {
4545
}
4646
}
4747

48-
function isSelectable(tbl_id, chartId, type, activeTrace) {
49-
const typeWithX = ['heatmap', 'histogram2dcontour', 'histogram2d'];
50-
const typeWithY = ['heatmap', 'histogram2dcontour', 'histogram2d'];
48+
function isSelectable(tbl_id, chartId, type) {
49+
const typeWithX = ['heatmap', 'histogram2dcontour', 'histogram2d', 'scatter'];
50+
const typeWithY = ['heatmap', 'histogram2dcontour', 'histogram2d', 'scatter'];
5151

5252
if (!tbl_id) return false;
53+
5354
const checkX = typeWithX.includes(type);
5455
const checkY = typeWithY.includes(type);
55-
5656
if (!checkX&&!checkY) return false; // chart type has no selection box in tool bar
5757

58-
const {x, y} = get(getChartData(chartId), `tablesources.${activeTrace}.mappings`) || {};
58+
const {tablesources} = getChartData(chartId);
59+
const strCol = ['str', 's', 'char', 'c'];
5960
const tableModel = getTblById(tbl_id);
60-
const dataExp = [x, y];
61-
62-
const noSelectionIdx = [checkX, checkY].findIndex((checkItem, idx) => {
63-
if (!checkItem) return false; // ignore
64-
if (dataExp[idx]) {
65-
return getColumnIdx(tableModel, dataExp[idx]) < 0;
66-
} else {
67-
return true; // not qualified to have selection box
68-
}
61+
const noSelectionTraceIdx = tablesources.findIndex((tablesource) => {
62+
const {x, y} = get(tablesource, 'mappings') || {};
63+
const dataExp = [x, y];
64+
65+
const noSelectionIdx = [checkX, checkY].findIndex((checkItem, idx) => {
66+
if (!checkItem) return false; // ignore
67+
68+
if (dataExp[idx]) {
69+
return getColumnIdx(tableModel, dataExp[idx]) < 0 ||
70+
strCol.includes(getColumnType(tableModel, dataExp[idx]));
71+
} else {
72+
return true; // not qualified to have selection box
73+
}
74+
});
75+
return noSelectionIdx >= 0;
6976
});
70-
return (noSelectionIdx < 0);
77+
return (noSelectionTraceIdx < 0);
7178
}
7279

7380
export class BasicToolbar extends SimpleComponent {
@@ -83,7 +90,7 @@ export class BasicToolbar extends SimpleComponent {
8390
const {activeTrace, hasFilter, hasSelection, tbl_id, dragmode} = this.state;
8491

8592
const type = get(getChartData(chartId), `data.${activeTrace}.type`, '');
86-
const showSelectionPart = isSelectable(tbl_id, chartId, type, activeTrace);
93+
const showSelectionPart = isSelectable(tbl_id, chartId, type);
8794
const showDragPart = !type.includes('pie');
8895
const is3d = type.endsWith('3d') || type === 'surface'; // scatter3d, mesh3d, surface
8996

src/firefly/js/charts/ui/options/BasicOptions.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ export function hasMarkerColor(type) {
6767
return type.startsWith('scatter') || ['histogram', 'box', 'bar', 'area', 'plotcloud'].includes(type);
6868
}
6969

70-
function hasNoXY(type, tablesources) {
70+
/*
71+
* check if the trace is not 3d-like chart or pie and has x and y defined
72+
*/
73+
function hasNoXY(type, tablesource) {
7174
if (type.endsWith('3d') || ['pie', 'surface'].includes(type)) return true;
7275

73-
const noXYtrace = tablesources.findIndex((trace) => {
74-
return (!get(trace, ['mappings', 'x']) || !get(trace, ['mappings', 'y']));
75-
});
76-
77-
return noXYtrace >= 0;
76+
return (!get(tablesource, ['mappings', 'x']) || !get(tablesource, ['mappings', 'y']));
7877
}
7978

8079
export class BasicOptions extends SimpleComponent {
@@ -94,7 +93,7 @@ export class BasicOptions extends SimpleComponent {
9493
const tbl_id = get(tablesource, 'tbl_id');
9594
const type = get(data, `${activeTrace}.type`, 'scatter');
9695
const noColor = !hasMarkerColor(type);
97-
const noXY = hasNoXY(type, tablesources);
96+
const noXY = hasNoXY(type, tablesource);
9897
const xColType = noXY ? '' : getColumnType(getTblById(tbl_id), get(tablesource, ['mappings', 'x'], ''));
9998
const yColType = noXY ? '' : getColumnType(getTblById(tbl_id), get(tablesource, ['mappings', 'y'], ''));
10099
const xNoLog = type.includes('histogram') ? true : undefined; // histogram2d or histogram2dcontour

0 commit comments

Comments
 (0)