1
1
import React from 'react' ;
2
- import Plotly from 'plotly.js' ;
3
2
import cloneDeep from 'lodash.clonedeep' ;
4
3
5
- var PlotlyComponent = React . createClass ( {
6
-
4
+ let createPlotlyComponent = ( plotlyInstance ) => React . createClass ( {
7
5
displayName : 'Plotly' ,
8
6
propTypes : {
9
7
data : React . PropTypes . array ,
@@ -36,24 +34,24 @@ var PlotlyComponent = React.createClass({
36
34
37
35
componentDidMount ( ) {
38
36
let { data, layout, config} = this . props ;
39
- Plotly . newPlot ( this . container , data , cloneDeep ( layout ) , config ) ; //We clone the layout as plotly mutates it.
37
+ plotlyInstance . newPlot ( this . container , data , cloneDeep ( layout ) , config ) ; //We clone the layout as plotly mutates it.
40
38
this . attachListeners ( ) ;
41
39
} ,
42
40
43
41
componentDidUpdate ( prevProps ) {
44
42
//TODO use minimal update for given changes
45
43
if ( prevProps . data !== this . props . data || prevProps . layout !== this . props . layout ) {
46
- Plotly . newPlot ( this . container , this . props . data , this . props . layout ) ;
44
+ plotlyInstance . newPlot ( this . container , this . props . data , this . props . layout ) ;
47
45
this . attachListeners ( ) ;
48
46
}
49
47
} ,
50
48
51
49
componentWillUnmount : function ( ) {
52
- Plotly . purge ( this . container ) ;
50
+ plotlyInstance . purge ( this . container ) ;
53
51
} ,
54
52
55
53
resize : function ( ) {
56
- Plotly . Plots . resize ( this . container ) ;
54
+ plotlyInstance . Plots . resize ( this . container ) ;
57
55
} ,
58
56
59
57
render : function ( ) {
@@ -69,4 +67,4 @@ var PlotlyComponent = React.createClass({
69
67
}
70
68
} ) ;
71
69
72
- module . exports = PlotlyComponent ;
70
+ export default createPlotlyComponent ;
0 commit comments