|
1 | 1 | import DefaultEditor from './DefaultEditor'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | import React, {Component} from 'react'; |
4 | | -import {bem, localizeString} from './lib'; |
| 4 | +import {bem, localizeString, plotlyTraceToCustomTrace, traceTypeToPlotlyInitFigure} from './lib'; |
5 | 5 | import { |
6 | 6 | shamefullyClearAxisTypes, |
7 | 7 | shamefullyAdjustAxisRef, |
@@ -143,14 +143,22 @@ class EditorControls extends Component { |
143 | 143 |
|
144 | 144 | // can't use default prop because plotly.js mutates it: |
145 | 145 | // 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 | + } |
154 | 162 |
|
155 | 163 | if (this.props.afterAddTrace) { |
156 | 164 | this.props.afterAddTrace(payload); |
|
0 commit comments