Skip to content

Commit 2eccdb7

Browse files
author
Cindy Wang
committed
DM-11477 add column expression for filtering and XY options in BasicOptions.
1 parent 44af9dd commit 2eccdb7

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

src/firefly/html/demo/ffapi-slate-test3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
name: 'contour',
208208
type: 'histogram2dcontour',
209209
x: "tables::wiseCatTbl,ra",
210-
y: "tables::wiseCatTbl,dec",
210+
y: "tables::wiseCatTbl,dec",
211211
ncontours: 20
212212
}];
213213

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {SimpleComponent} from '../../ui/SimpleComponent.jsx';
77
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';
10+
import {getColValidator} from './ColumnOrExpression.jsx';
11+
import {getColValStats} from '../TableStatsCntlr.js';
1012

1113
function getToolbarStates(chartId) {
1214
const {selection, selected, activeTrace=0, tablesources, layout, data={}} = getChartData(chartId);
@@ -69,8 +71,14 @@ function isSelectable(tbl_id, chartId, type) {
6971
if (!checkItem) return false; // ignore
7072

7173
if (dataExp[idx]) {
72-
return getColumnIdx(tableModel, dataExp[idx]) < 0 ||
73-
strCol.includes(getColumnType(tableModel, dataExp[idx]));
74+
if (getColumnIdx(tableModel, dataExp[idx]) >= 0) {
75+
return strCol.includes(getColumnType(tableModel, dataExp[idx]));
76+
} else {
77+
const colValidator = getColValidator(getColValStats(tbl_id));
78+
const {valid} = colValidator(dataExp[idx]);
79+
80+
return !valid;
81+
}
7482
} else {
7583
return true; // not qualified to have selection box
7684
}

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {updateSet} from '../../../util/WebUtil.js';
1818
import {hideColSelectPopup} from '../ColSelectView.jsx';
1919
import {addColorbarChanges} from '../../dataTypes/FireflyHeatmap.js';
2020
import {getColumnType, getTblById} from '../../../tables/TableUtil.js';
21+
import {getColValStats} from '../../TableStatsCntlr.js';
22+
import {getColValidator} from '../ColumnOrExpression.jsx';
2123

2224
const fieldProps = {labelWidth: 50, size: 25};
2325
const boundariesFieldProps = {labelWidth: 35, size: 10};
@@ -75,6 +77,21 @@ function hasNoXY(type, tablesource) {
7577
return (!get(tablesource, ['mappings', 'x']) || !get(tablesource, ['mappings', 'y']));
7678
}
7779

80+
81+
function isNonNumColumn(tbl_id, colExp) {
82+
const numTypes = ['double', 'd', 'long', 'l', 'int', 'i', 'float', 'f'];
83+
const colType = getColumnType(getTblById(tbl_id), colExp);
84+
85+
if (colType) {
86+
return !numTypes.includes(colType);
87+
} else {
88+
const colValidator = getColValidator(getColValStats(tbl_id));
89+
const {valid} = colValidator(colExp);
90+
91+
return !valid;
92+
}
93+
}
94+
7895
export class BasicOptions extends SimpleComponent {
7996

8097
getNextState() {
@@ -93,8 +110,8 @@ export class BasicOptions extends SimpleComponent {
93110
const type = get(data, `${activeTrace}.type`, 'scatter');
94111
const noColor = !hasMarkerColor(type);
95112
const noXY = hasNoXY(type, tablesource);
96-
const xColType = noXY ? '' : getColumnType(getTblById(tbl_id), get(tablesource, ['mappings', 'x'], ''));
97-
const yColType = noXY ? '' : getColumnType(getTblById(tbl_id), get(tablesource, ['mappings', 'y'], ''));
113+
const isXNotNumeric = noXY ? undefined : isNonNumColumn(tbl_id, get(tablesource, ['mappings', 'x'], ''));
114+
const isYNotNumeric = noXY ? undefined : isNonNumColumn(tbl_id, get(tablesource, ['mappings', 'y'], ''));
98115
const xNoLog = type.includes('histogram') ? true : undefined; // histogram2d or histogram2dcontour
99116
const yNoLog = type.includes('histogram') ? true : undefined;
100117

@@ -103,7 +120,7 @@ export class BasicOptions extends SimpleComponent {
103120
<OptionTopBar {...{groupKey, activeTrace, chartId, tbl_id}}/>
104121
<FieldGroup className='FieldGroup__vertical' keepState={false} groupKey={groupKey}
105122
reducerFunc={basicFieldReducer({chartId, activeTrace})}>
106-
<BasicOptionFields {...{activeTrace, groupKey, noColor, noXY, xColType, yColType, xNoLog, yNoLog}}/>
123+
<BasicOptionFields {...{activeTrace, groupKey, noColor, noXY, isXNotNumeric, isYNotNumeric, xNoLog, yNoLog}}/>
107124
</FieldGroup>
108125
</div>
109126
);
@@ -304,8 +321,7 @@ export class BasicOptionFields extends Component {
304321
}
305322

306323
render() {
307-
const {activeTrace, groupKey, align='vertical', noColor, noXY, xNoLog, yNoLog, xColType, yColType} = this.props;
308-
const strT = ['str', 'char', 's', 'c'];
324+
const {activeTrace, groupKey, align='vertical', noColor, noXY, xNoLog, yNoLog, isXNotNumeric, isYNotNumeric} = this.props;
309325

310326
// TODO: need color input field
311327
const colorFldPath = `data.${activeTrace}.marker.color`;
@@ -337,16 +353,16 @@ export class BasicOptionFields extends Component {
337353
{!noXY && <div>
338354
<ValidationField fieldKey={'layout.xaxis.title'}/>
339355
<CheckboxGroupInputField fieldKey='__xoptions'
340-
options={xNoLog || strT.includes(xColType) ? X_AXIS_OPTIONS_NOLOG : X_AXIS_OPTIONS}/>
356+
options={xNoLog || isXNotNumeric ? X_AXIS_OPTIONS_NOLOG : X_AXIS_OPTIONS}/>
341357
<br/>
342358
<ValidationField fieldKey={'layout.yaxis.title'}/>
343359
<CheckboxGroupInputField fieldKey='__yoptions'
344-
options={yNoLog || strT.includes(yColType) ? Y_AXIS_OPTIONS_NOLOG : Y_AXIS_OPTIONS}/>
360+
options={yNoLog || isYNotNumeric ? Y_AXIS_OPTIONS_NOLOG : Y_AXIS_OPTIONS}/>
345361
<br/>
346362
<div style={helpStyle}>
347363
Set plot boundaries if different from data range.
348364
</div>
349-
{strT.includes(xColType) ? false :
365+
{isXNotNumeric ? false :
350366
<div style={{display: 'flex', flexDirection: 'row', padding: '5px 15px 0'}}>
351367
<div style={{paddingRight: 5}}>
352368
<ValidationField fieldKey={'fireflyLayout.xaxis.min'}/>
@@ -355,7 +371,7 @@ export class BasicOptionFields extends Component {
355371
<ValidationField fieldKey={'fireflyLayout.xaxis.max'}/>
356372
</div>
357373
</div>}
358-
{strT.includes(yColType) ? false :
374+
{isYNotNumeric ? false :
359375
<div style={{display: 'flex', flexDirection: 'row', padding: '0px 15px 15px'}}>
360376
<div style={{paddingRight: 5}}>
361377
<ValidationField fieldKey={'fireflyLayout.yaxis.min'}/>
@@ -396,8 +412,8 @@ BasicOptionFields.propTypes = {
396412
xNoLog: PropTypes.bool,
397413
yNoLog: PropTypes.bool,
398414
noXY: PropTypes.bool,
399-
xColType: PropTypes.string,
400-
yColType: PropTypes.string
415+
isXNotNumeric: PropTypes.bool,
416+
isYNotNumeric: PropTypes.bool
401417
};
402418

403419

0 commit comments

Comments
 (0)