1
- import React , { Component } from " react" ;
2
- import PropTypes from " prop-types" ;
3
- import isNumeric from " fast-isnumeric" ;
4
- import objectAssign from " object-assign" ;
1
+ import React , { Component } from ' react' ;
2
+ import PropTypes from ' prop-types' ;
3
+ import isNumeric from ' fast-isnumeric' ;
4
+ import objectAssign from ' object-assign' ;
5
5
// import throttle from "throttle-debounce/throttle";
6
6
7
7
// The naming convention is:
8
8
// - events are attached as `'plotly_' + eventName.toLowerCase()`
9
9
// - react props are `'on' + eventName`
10
10
const eventNames = [
11
- " AfterExport" ,
12
- " AfterPlot" ,
13
- " Animated" ,
14
- " AnimatingFrame" ,
15
- " AnimationInterrupted" ,
16
- " AutoSize" ,
17
- " BeforeExport" ,
18
- " ButtonClicked" ,
19
- " Click" ,
20
- " ClickAnnotation" ,
21
- " Deselect" ,
22
- " DoubleClick" ,
23
- " Framework" ,
24
- " Hover" ,
25
- " Relayout" ,
26
- " Restyle" ,
27
- " Redraw" ,
28
- " Selected" ,
29
- " Selecting" ,
30
- " SliderChange" ,
31
- " SliderEnd" ,
32
- " SliderStart" ,
33
- " Transitioning" ,
34
- " TransitionInterrupted" ,
35
- " Unhover" ,
11
+ ' AfterExport' ,
12
+ ' AfterPlot' ,
13
+ ' Animated' ,
14
+ ' AnimatingFrame' ,
15
+ ' AnimationInterrupted' ,
16
+ ' AutoSize' ,
17
+ ' BeforeExport' ,
18
+ ' ButtonClicked' ,
19
+ ' Click' ,
20
+ ' ClickAnnotation' ,
21
+ ' Deselect' ,
22
+ ' DoubleClick' ,
23
+ ' Framework' ,
24
+ ' Hover' ,
25
+ ' Relayout' ,
26
+ ' Restyle' ,
27
+ ' Redraw' ,
28
+ ' Selected' ,
29
+ ' Selecting' ,
30
+ ' SliderChange' ,
31
+ ' SliderEnd' ,
32
+ ' SliderStart' ,
33
+ ' Transitioning' ,
34
+ ' TransitionInterrupted' ,
35
+ ' Unhover' ,
36
36
] ;
37
37
38
38
const updateEvents = [
39
- " plotly_restyle" ,
40
- " plotly_redraw" ,
41
- " plotly_relayout" ,
42
- " plotly_doubleclick" ,
43
- " plotly_animated" ,
39
+ ' plotly_restyle' ,
40
+ ' plotly_redraw' ,
41
+ ' plotly_relayout' ,
42
+ ' plotly_doubleclick' ,
43
+ ' plotly_animated' ,
44
44
] ;
45
45
46
46
// Check if a window is available since SSR (server-side rendering)
47
47
// breaks unnecessarily if you try to use it server-side.
48
- const isBrowser = typeof window !== " undefined" ;
48
+ const isBrowser = typeof window !== ' undefined' ;
49
49
50
50
export default function plotComponentFactory ( Plotly ) {
51
51
const hasReactAPIMethod = ! ! Plotly . react ;
@@ -93,7 +93,7 @@ export default function plotComponentFactory(Plotly) {
93
93
( ) => this . props . onInitialized && this . props . onInitialized ( this . el )
94
94
)
95
95
. catch ( e => {
96
- console . error ( " Error while plotting:" , e ) ;
96
+ console . error ( ' Error while plotting:' , e ) ;
97
97
return this . props . onError && this . props . onError ( ) ;
98
98
} ) ;
99
99
}
@@ -125,14 +125,14 @@ export default function plotComponentFactory(Plotly) {
125
125
. then ( this . attachUpdateEvents )
126
126
. then ( ( ) => this . handleUpdate ( nextProps ) )
127
127
. catch ( err => {
128
- console . error ( " Error while plotting:" , err ) ;
128
+ console . error ( ' Error while plotting:' , err ) ;
129
129
this . props . onError && this . props . onError ( err ) ;
130
130
} ) ;
131
131
}
132
132
133
133
componentWillUnmount ( ) {
134
134
if ( this . resizeHandler && isBrowser ) {
135
- window . removeEventListener ( " resize" , this . handleResize ) ;
135
+ window . removeEventListener ( ' resize' , this . handleResize ) ;
136
136
this . resizeHandler = null ;
137
137
}
138
138
@@ -163,7 +163,7 @@ export default function plotComponentFactory(Plotly) {
163
163
164
164
handleUpdate ( props ) {
165
165
props = props || this . props ;
166
- if ( props . onUpdate && typeof props . onUpdate === " function" ) {
166
+ if ( props . onUpdate && typeof props . onUpdate === ' function' ) {
167
167
props . onUpdate ( this . el ) ;
168
168
}
169
169
}
@@ -176,11 +176,11 @@ export default function plotComponentFactory(Plotly) {
176
176
this . resizeHandler = ( ) => {
177
177
return Plotly . relayout ( this . el , this . getSize ( ) ) ;
178
178
} ;
179
- window . addEventListener ( " resize" , this . resizeHandler ) ;
179
+ window . addEventListener ( ' resize' , this . resizeHandler ) ;
180
180
181
181
if ( invoke ) return this . resizeHandler ( ) ;
182
182
} else if ( ! props . fit && this . resizeHandler ) {
183
- window . removeEventListener ( " resize" , this . resizeHandler ) ;
183
+ window . removeEventListener ( ' resize' , this . resizeHandler ) ;
184
184
this . resizeHandler = null ;
185
185
}
186
186
}
@@ -200,16 +200,16 @@ export default function plotComponentFactory(Plotly) {
200
200
201
201
for ( let i = 0 ; i < eventNames . length ; i ++ ) {
202
202
const eventName = eventNames [ i ] ;
203
- const prop = props [ "on" + eventName ] ;
203
+ const prop = props [ 'on' + eventName ] ;
204
204
const hasHandler = ! ! this . handlers [ eventName ] ;
205
205
206
206
if ( prop && ! hasHandler ) {
207
- let handler = ( this . handlers [ eventName ] = props [ "on" + eventName ] ) ;
208
- this . el . on ( " plotly_" + eventName . toLowerCase ( ) , handler ) ;
207
+ let handler = ( this . handlers [ eventName ] = props [ 'on' + eventName ] ) ;
208
+ this . el . on ( ' plotly_' + eventName . toLowerCase ( ) , handler ) ;
209
209
} else if ( ! prop && hasHandler ) {
210
210
// Needs to be removed:
211
211
this . el . off (
212
- " plotly_" + eventName . toLowerCase ( ) ,
212
+ ' plotly_' + eventName . toLowerCase ( ) ,
213
213
this . handlers [ eventName ]
214
214
) ;
215
215
delete this . handlers [ eventName ] ;
@@ -252,8 +252,8 @@ export default function plotComponentFactory(Plotly) {
252
252
return (
253
253
< div
254
254
style = { {
255
- position : " relative" ,
256
- display : " inline-block" ,
255
+ position : ' relative' ,
256
+ display : ' inline-block' ,
257
257
} }
258
258
ref = { this . getRef }
259
259
/>
@@ -275,7 +275,7 @@ export default function plotComponentFactory(Plotly) {
275
275
} ;
276
276
277
277
for ( let i = 0 ; i < eventNames . length ; i ++ ) {
278
- PlotlyComponent . propTypes [ "on" + eventNames [ i ] ] = PropTypes . func ;
278
+ PlotlyComponent . propTypes [ 'on' + eventNames [ i ] ] = PropTypes . func ;
279
279
}
280
280
281
281
PlotlyComponent . defaultProps = {
0 commit comments