Skip to content

Commit dcd13b5

Browse files
committed
Use function to create new trace
1 parent 883c436 commit dcd13b5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/EditorControls.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ class EditorControls extends Component {
122122
// can't use default prop because plotly.js mutates it:
123123
// https://github.com/plotly/react-chart-editor/issues/509
124124
graphDiv.data.push(
125-
this.props.useAsDefaultTrace
126-
? this.props.useAsDefaultTrace
127-
: {type: 'scatter', mode: 'markers'}
125+
this.props.makeDefaultTrace(this.props.useAsDefaultTrace)
128126
);
129127

130128
if (this.props.afterAddTrace) {
@@ -307,11 +305,18 @@ EditorControls.propTypes = {
307305
showFieldTooltips: PropTypes.bool,
308306
traceTypesConfig: PropTypes.object,
309307
useAsDefaultTrace: PropTypes.object,
308+
makeDefaultTrace: PropTypes.func,
310309
};
311310

312311
EditorControls.defaultProps = {
313312
showFieldTooltips: false,
314313
locale: 'en',
314+
makeDefaultTrace: suppliedDefault => {
315+
if (suppliedDefault) {
316+
return suppliedDefault;
317+
}
318+
return {type: 'scatter', mode: 'markers'};
319+
},
315320
traceTypesConfig: {
316321
categories: _ => categoryLayout(_),
317322
traces: _ => traceTypes(_),

0 commit comments

Comments
 (0)