Skip to content

Commit f4b7b99

Browse files
Merge pull request #774 from plotly/trace_reuse
reuse trace type
2 parents 6c2385d + 57d283e commit f4b7b99

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/EditorControls.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import DefaultEditor from './DefaultEditor';
22
import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
4-
import {bem, localizeString} from './lib';
4+
import {bem, localizeString, plotlyTraceToCustomTrace, traceTypeToPlotlyInitFigure} from './lib';
55
import {
66
shamefullyClearAxisTypes,
77
shamefullyAdjustAxisRef,
@@ -143,14 +143,22 @@ class EditorControls extends Component {
143143

144144
// can't use default prop because plotly.js mutates it:
145145
// https://github.com/plotly/react-chart-editor/issues/509
146-
graphDiv.data.push(
147-
this.props.makeDefaultTrace
148-
? this.props.makeDefaultTrace()
149-
: {
150-
type: `scatter${this.props.glByDefault ? 'gl' : ''}`,
151-
mode: 'markers',
152-
}
153-
);
146+
if (graphDiv.data.length === 0) {
147+
graphDiv.data.push(
148+
this.props.makeDefaultTrace
149+
? this.props.makeDefaultTrace()
150+
: {
151+
type: `scatter${this.props.glByDefault ? 'gl' : ''}`,
152+
mode: 'markers',
153+
}
154+
);
155+
} else {
156+
const prevTrace = graphDiv.data[graphDiv.data.length - 1];
157+
const prevTraceType = plotlyTraceToCustomTrace(prevTrace);
158+
graphDiv.data.push(
159+
traceTypeToPlotlyInitFigure(prevTraceType, prevTrace.type.endsWith('gl') ? 'gl' : '')
160+
);
161+
}
154162

155163
if (this.props.afterAddTrace) {
156164
this.props.afterAddTrace(payload);

src/components/fields/__tests__/TraceSelector-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('TraceSelector', () => {
141141

142142
const payload = beforeUpdateTraces.mock.calls[0][0];
143143
expect(payload.update).toEqual({
144-
fill: 'none',
144+
stackgroup: null,
145145
mode: 'lines',
146146
type: 'scatter',
147147
});

src/lib/customTraceType.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export function plotlyTraceToCustomTrace(trace) {
3434
export function traceTypeToPlotlyInitFigure(traceType, gl = '') {
3535
switch (traceType) {
3636
case 'line':
37-
return {type: 'scatter' + gl, mode: 'lines', fill: 'none'};
37+
return {type: 'scatter' + gl, mode: 'lines', stackgroup: null};
3838
case 'scatter':
39-
return {type: 'scatter' + gl, mode: 'markers', fill: 'none'};
39+
return {type: 'scatter' + gl, mode: 'markers', stackgroup: null};
4040
case 'area':
4141
return {type: 'scatter' + gl, mode: 'lines', stackgroup: 1};
4242
case 'scatterpolar':

0 commit comments

Comments
 (0)