Skip to content

Commit fba744b

Browse files
committed
Force mode when !trace.mode, but _fullTrace.mode is present
1 parent 8ca3d89 commit fba744b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/components/fields/TraceSelector.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ class TraceSelector extends Component {
5252
'tonext',
5353
];
5454
}
55-
55+
this.setTraceDefaults(
56+
props.container,
57+
props.fullContainer,
58+
props.updateContainer
59+
);
5660
this.setLocals(props, context);
5761
}
5862

@@ -64,17 +68,30 @@ class TraceSelector extends Component {
6468
} else {
6569
this.traceOptions = [{label: 'Scatter', value: 'scatter'}];
6670
}
71+
this.fullValue = plotlyTraceToCustomTrace(props.container);
72+
}
6773

68-
this.fullValue = plotlyTraceToCustomTrace(props.fullContainer);
74+
setTraceDefaults(container, fullContainer, updateContainer) {
75+
if (
76+
(container.type === 'scatter' && !container.mode) ||
77+
(!container.type && fullContainer.type === 'scatter')
78+
) {
79+
updateContainer({
80+
type: 'scatter',
81+
mode: fullContainer.mode || 'markers',
82+
fill: fullContainer.fill || container.fill,
83+
});
84+
}
6985
}
7086

7187
componentWillReceiveProps(nextProps, nextContext) {
88+
const {container, fullContainer, updateContainer} = nextProps;
89+
this.setTraceDefaults(container, fullContainer, updateContainer);
7290
this.setLocals(nextProps, nextContext);
7391
}
7492

7593
updatePlot(value) {
7694
const update = customTraceToPlotlyTrace(value);
77-
7895
if (this.props.updateContainer) {
7996
this.props.updateContainer(update);
8097
}
@@ -97,6 +114,7 @@ TraceSelector.contextTypes = {
97114

98115
TraceSelector.propTypes = {
99116
getValObject: PropTypes.func,
117+
container: PropTypes.object.isRequired,
100118
fullContainer: PropTypes.object.isRequired,
101119
fullValue: PropTypes.any.isRequired,
102120
updateContainer: PropTypes.func,

src/lib/customTraceType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
export function plotlyTraceToCustomTrace(trace) {
22
if (
33
trace.type === 'scatter' &&
4+
trace.fill &&
45
['tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'].includes(
56
trace.fill
67
)
78
) {
89
return 'area';
910
} else if (
1011
trace.type === 'scatter' &&
12+
trace.mode &&
1113
(trace.mode === 'lines' || trace.mode === 'lines+markers')
1214
) {
1315
return 'line';

0 commit comments

Comments
 (0)