diff --git a/dev/App.js b/dev/App.js index 9fc68eff0..8c8e38b79 100644 --- a/dev/App.js +++ b/dev/App.js @@ -157,7 +157,7 @@ class App extends Component { advancedTraceTypeSelector showFieldTooltips // traceTypesConfig={traceTypesConfig} - // useAsDefaultTrace={{type: 'scattergl', mode: 'markers'}} + // makeDefaultTrace={() => ({type: 'scattergl', mode: 'markers'})} > diff --git a/src/EditorControls.js b/src/EditorControls.js index aaf291d57..f831882c1 100644 --- a/src/EditorControls.js +++ b/src/EditorControls.js @@ -119,7 +119,9 @@ class EditorControls extends Component { this.props.beforeAddTrace(payload); } - graphDiv.data.push(this.props.useAsDefaultTrace); + // can't use default prop because plotly.js mutates it: + // https://github.com/plotly/react-chart-editor/issues/509 + graphDiv.data.push(this.props.makeDefaultTrace()); if (this.props.afterAddTrace) { this.props.afterAddTrace(payload); @@ -300,18 +302,18 @@ EditorControls.propTypes = { plotly: PropTypes.object, showFieldTooltips: PropTypes.bool, traceTypesConfig: PropTypes.object, - useAsDefaultTrace: PropTypes.object, + makeDefaultTrace: PropTypes.func, }; EditorControls.defaultProps = { showFieldTooltips: false, locale: 'en', + makeDefaultTrace: () => ({type: 'scatter', mode: 'markers'}), traceTypesConfig: { categories: _ => categoryLayout(_), traces: _ => traceTypes(_), complex: true, }, - useAsDefaultTrace: {type: 'scatter', mode: 'markers'}, }; EditorControls.childContextTypes = { diff --git a/src/PlotlyEditor.js b/src/PlotlyEditor.js index 39bf3b308..0bddbf082 100644 --- a/src/PlotlyEditor.js +++ b/src/PlotlyEditor.js @@ -26,7 +26,7 @@ class PlotlyEditor extends Component { dictionaries={this.props.dictionaries} showFieldTooltips={this.props.showFieldTooltips} srcConverters={this.props.srcConverters} - useAsDefaultTrace={this.props.useAsDefaultTrace} + makeDefaultTrace={this.props.makeDefaultTrace} > {this.props.children} @@ -76,7 +76,7 @@ PlotlyEditor.propTypes = { toSrc: PropTypes.func.isRequired, fromSrc: PropTypes.func.isRequired, }), - useAsDefaultTrace: PropTypes.object, + makeDefaultTrace: PropTypes.func, }; PlotlyEditor.defaultProps = {