Skip to content

Commit 8d47ab7

Browse files
committed
Add customTraceType util
1 parent 11913f6 commit 8d47ab7

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

src/components/fields/TraceSelector.js

+3-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {UnconnectedDropdown} from './Dropdown';
22
import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
4-
import nestedProperty from 'plotly.js/src/lib/nested_property';
5-
import {connectToContainer} from '../../lib';
4+
import {connectToContainer, customToPlotly, plotlyToCustom} from '../../lib';
65

76
function computeTraceOptionsFromSchema(schema) {
87
const capitalize = s => s.charAt(0).toUpperCase() + s.substring(1);
@@ -62,35 +61,15 @@ class TraceSelector extends Component {
6261
this.traceOptions = [{label: 'Scatter', value: 'scatter'}];
6362
}
6463

65-
// If we used fullData mode or fill it may be undefined if the fullTrace
66-
// is not visible and therefore does not have these values computed.
67-
const mode = nestedProperty(props.container, 'mode').get();
68-
const fill = nestedProperty(props.container, 'fill').get();
69-
const fullValue = props.fullValue;
70-
if (fullValue === 'scatter' && this.fillTypes.includes(fill)) {
71-
this.fullValue = 'area';
72-
} else if (fullValue === 'scatter' && mode === 'lines') {
73-
this.fullValue = 'line';
74-
} else {
75-
this.fullValue = fullValue;
76-
}
64+
this.fullValue = plotlyToCustom(props.container);
7765
}
7866

7967
componentWillReceiveProps(nextProps, nextContext) {
8068
this.setLocals(nextProps, nextContext);
8169
}
8270

8371
updatePlot(value) {
84-
let update;
85-
if (value === 'line') {
86-
update = {type: 'scatter', mode: 'lines', fill: 'none'};
87-
} else if (value === 'scatter') {
88-
update = {type: 'scatter', mode: 'markers', fill: 'none'};
89-
} else if (value === 'area') {
90-
update = {type: 'scatter', fill: 'tozeroy'};
91-
} else {
92-
update = {type: value};
93-
}
72+
const update = customToPlotly(value);
9473

9574
if (this.props.updateContainer) {
9675
this.props.updateContainer(update);

src/lib/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import localize, {localizeString} from './localize';
1010
import tinyColor from 'tinycolor2';
1111
import unpackPlotProps from './unpackPlotProps';
1212
import walkObject, {isPlainObject} from './walkObject';
13+
import {customToPlotly, plotlyToCustom} from './customTraceType';
1314

1415
function clamp(value, min, max) {
1516
return Math.max(min, Math.min(max, value));
@@ -33,14 +34,16 @@ export {
3334
connectLayoutToPlot,
3435
connectToContainer,
3536
connectTraceToPlot,
37+
customToPlotly,
3638
dereference,
39+
findFullTraceIndex,
3740
getDisplayName,
3841
getLayoutContext,
39-
findFullTraceIndex,
4042
icon,
4143
isPlainObject,
4244
localize,
4345
localizeString,
46+
plotlyToCustom,
4447
unpackPlotProps,
4548
walkObject,
4649
};

0 commit comments

Comments
 (0)