Skip to content

Commit 9683a80

Browse files
committed
Use function to create new trace
1 parent cf6a44c commit 9683a80

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

dev/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class App extends Component {
157157
advancedTraceTypeSelector
158158
showFieldTooltips
159159
// traceTypesConfig={traceTypesConfig}
160-
// useAsDefaultTrace={{type: 'scattergl', mode: 'markers'}}
160+
// makeDefaultTrace={() => ({type: 'scattergl', mode: 'markers'})}
161161
>
162162
<DefaultEditor>
163163
<GraphTransformsPanel group="Dev" name="Transforms" />

src/EditorControls.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ class EditorControls extends Component {
119119
this.props.beforeAddTrace(payload);
120120
}
121121

122-
graphDiv.data.push(this.props.useAsDefaultTrace);
122+
// can't use default prop because plotly.js mutates it:
123+
// https://github.com/plotly/react-chart-editor/issues/509
124+
graphDiv.data.push(this.props.makeDefaultTrace());
123125

124126
if (this.props.afterAddTrace) {
125127
this.props.afterAddTrace(payload);
@@ -300,18 +302,18 @@ EditorControls.propTypes = {
300302
plotly: PropTypes.object,
301303
showFieldTooltips: PropTypes.bool,
302304
traceTypesConfig: PropTypes.object,
303-
useAsDefaultTrace: PropTypes.object,
305+
makeDefaultTrace: PropTypes.func,
304306
};
305307

306308
EditorControls.defaultProps = {
307309
showFieldTooltips: false,
308310
locale: 'en',
311+
makeDefaultTrace: () => ({type: 'scatter', mode: 'markers'}),
309312
traceTypesConfig: {
310313
categories: _ => categoryLayout(_),
311314
traces: _ => traceTypes(_),
312315
complex: true,
313316
},
314-
useAsDefaultTrace: {type: 'scatter', mode: 'markers'},
315317
};
316318

317319
EditorControls.childContextTypes = {

src/PlotlyEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PlotlyEditor extends Component {
2626
dictionaries={this.props.dictionaries}
2727
showFieldTooltips={this.props.showFieldTooltips}
2828
srcConverters={this.props.srcConverters}
29-
useAsDefaultTrace={this.props.useAsDefaultTrace}
29+
makeDefaultTrace={this.props.makeDefaultTrace}
3030
>
3131
{this.props.children}
3232
</EditorControls>
@@ -76,7 +76,7 @@ PlotlyEditor.propTypes = {
7676
toSrc: PropTypes.func.isRequired,
7777
fromSrc: PropTypes.func.isRequired,
7878
}),
79-
useAsDefaultTrace: PropTypes.object,
79+
makeDefaultTrace: PropTypes.func,
8080
};
8181

8282
PlotlyEditor.defaultProps = {

0 commit comments

Comments
 (0)