@@ -52,7 +52,6 @@ class TraceSelector extends Component {
52
52
'tonext' ,
53
53
] ;
54
54
}
55
-
56
55
this . setLocals ( props , context ) ;
57
56
}
58
57
@@ -64,30 +63,49 @@ class TraceSelector extends Component {
64
63
} else {
65
64
this . traceOptions = [ { label : 'Scatter' , value : 'scatter' } ] ;
66
65
}
67
-
68
66
this . fullValue = plotlyTraceToCustomTrace ( props . container ) ;
69
67
}
70
68
69
+ setTraceDefaults ( container , fullContainer , updateContainer ) {
70
+ /*
71
+ * Default plotly.js mode is variable:
72
+ * https://github.com/plotly/plotly.js/blob/master/src/traces/scatter/defaults.js#L32
73
+ * take it from fullContainer, or if it's not present (i.e. when there's no data
74
+ * in the plot yet, temporarily set it to lines + markers, it will get overriden
75
+ * in componentWillReceiveProps)
76
+ */
77
+
78
+ // set plotly.js defaults explicitly into gd.data | non empty x & y cases
79
+ // we don't want to set a mode in the case of x: [], y: [], because plotly.js
80
+ // default mode changes depending on # of data points, so we wait until we
81
+ // have data to set the mode.
82
+ if (
83
+ ( container . type === 'scatter' && ! container . mode && fullContainer . mode ) ||
84
+ ( ! container . type && ! container . mode && fullContainer . mode )
85
+ ) {
86
+ updateContainer ( {
87
+ type : 'scatter' ,
88
+ mode : fullContainer . mode ,
89
+ fill : 'none' ,
90
+ } ) ;
91
+ }
92
+ this . fullValue = plotlyTraceToCustomTrace ( container ) ;
93
+ }
94
+
71
95
componentWillMount ( ) {
72
- const { container} = this . props ;
73
- const value = plotlyTraceToCustomTrace ( container ) ;
74
- this . updatePlot ( value ) ;
96
+ const { container, fullContainer, updateContainer} = this . props ;
97
+ this . setTraceDefaults ( container , fullContainer , updateContainer ) ;
75
98
}
76
99
77
100
componentWillReceiveProps ( nextProps , nextContext ) {
78
- if (
79
- ! nextProps . container . type ||
80
- ( nextProps . container . type === 'scatter' && ! nextProps . container . mode )
81
- ) {
82
- this . updatePlot ( { type : 'scatter' , mode : 'lines+markers' } ) ;
83
- }
101
+ const { container, fullContainer, updateContainer} = nextProps ;
102
+ this . setTraceDefaults ( container , fullContainer , updateContainer ) ;
84
103
this . setLocals ( nextProps , nextContext ) ;
85
104
}
86
105
87
106
updatePlot ( value ) {
88
107
const { container} = this . props ;
89
108
const update = customTraceToPlotlyTrace ( value , container ) ;
90
-
91
109
if ( this . props . updateContainer ) {
92
110
this . props . updateContainer ( update ) ;
93
111
}
@@ -111,6 +129,7 @@ TraceSelector.contextTypes = {
111
129
TraceSelector . propTypes = {
112
130
getValObject : PropTypes . func ,
113
131
container : PropTypes . object . isRequired ,
132
+ fullContainer : PropTypes . object . isRequired ,
114
133
fullValue : PropTypes . any . isRequired ,
115
134
updateContainer : PropTypes . func ,
116
135
} ;
0 commit comments