@@ -55,7 +55,7 @@ export default function plotComponentFactory(Plotly) {
55
55
super ( props ) ;
56
56
57
57
this . p = Promise . resolve ( ) ;
58
- this . resizeHandler = null ;
58
+ this . fitHandler = null ;
59
59
this . handlers = { } ;
60
60
61
61
this . syncWindowResize = this . syncWindowResize . bind ( this ) ;
@@ -134,9 +134,9 @@ export default function plotComponentFactory(Plotly) {
134
134
if ( this . props . onPurge ) {
135
135
this . props . onPurge ( this . el ) ;
136
136
}
137
- if ( this . resizeHandler && isBrowser ) {
137
+ if ( this . fitHandler && isBrowser ) {
138
138
window . removeEventListener ( 'resize' , this . handleResize ) ;
139
- this . resizeHandler = null ;
139
+ this . fitHandler = null ;
140
140
}
141
141
142
142
this . removeUpdateEvents ( ) ;
@@ -175,14 +175,24 @@ export default function plotComponentFactory(Plotly) {
175
175
props = props || this . props ;
176
176
if ( ! isBrowser ) return ;
177
177
178
- if ( props . fit && ! this . resizeHandler ) {
179
- this . resizeHandler = ( ) => {
178
+ if ( props . fit && ! this . fitHandler ) {
179
+ this . fitHandler = ( ) => {
180
180
return Plotly . relayout ( this . el , this . getSize ( ) ) ;
181
181
} ;
182
- window . addEventListener ( 'resize' , this . resizeHandler ) ;
182
+ window . addEventListener ( 'resize' , this . fitHandler ) ;
183
+
184
+ if ( invoke ) return this . fitHandler ( ) ;
185
+ } else if ( ! props . fit && this . fitHandler ) {
186
+ window . removeEventListener ( 'resize' , this . fitHandler ) ;
187
+ this . fitHandler = null ;
188
+ }
183
189
184
- if ( invoke ) return this . resizeHandler ( ) ;
185
- } else if ( ! props . fit && this . resizeHandler ) {
190
+ if ( props . useResizeHandler && ! this . resizeHandler ) {
191
+ this . resizeHandler = ( ) => {
192
+ return Plotly . Plots . resize ( this . el ) ;
193
+ } ;
194
+ window . addEventListener ( 'resize' , this . resizeHandler ) ;
195
+ } else if ( ! props . useResizeHandler && this . resizeHandler ) {
186
196
window . removeEventListener ( 'resize' , this . resizeHandler ) ;
187
197
this . resizeHandler = null ;
188
198
}
@@ -269,6 +279,7 @@ export default function plotComponentFactory(Plotly) {
269
279
onUpdate : PropTypes . func ,
270
280
debug : PropTypes . bool ,
271
281
style : PropTypes . object ,
282
+ useResizeHandler : PropTypes . bool ,
272
283
} ;
273
284
274
285
for ( let i = 0 ; i < eventNames . length ; i ++ ) {
@@ -278,6 +289,7 @@ export default function plotComponentFactory(Plotly) {
278
289
PlotlyComponent . defaultProps = {
279
290
debug : false ,
280
291
fit : false ,
292
+ useResizeHandler : false ,
281
293
data : [ ] ,
282
294
style : { position : 'relative' , display : 'inline-block' } ,
283
295
} ;
0 commit comments