@@ -2,9 +2,9 @@ import PropTypes from 'prop-types';
2
2
import React from 'react' ;
3
3
import cloneDeep from 'lodash.clonedeep' ;
4
4
5
- let createPlotlyComponent = ( plotlyInstance ) => React . createClass ( {
6
- displayName : 'Plotly' ,
7
- propTypes : {
5
+ let createPlotlyComponent = ( plotlyInstance ) => class Plotly extends React . Component {
6
+
7
+ static propTypes = {
8
8
data : PropTypes . array ,
9
9
layout : PropTypes . object ,
10
10
config : PropTypes . object ,
@@ -13,9 +13,9 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
13
13
onHover : PropTypes . func ,
14
14
onUnHover : PropTypes . func ,
15
15
onSelected : PropTypes . func
16
- } ,
16
+ } ;
17
17
18
- attachListeners : function ( ) {
18
+ attachListeners ( ) {
19
19
if ( this . props . onClick )
20
20
this . container . on ( 'plotly_click' , this . props . onClick ) ;
21
21
if ( this . props . onBeforeHover )
@@ -26,18 +26,18 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
26
26
this . container . on ( 'plotly_unhover' , this . props . onUnHover ) ;
27
27
if ( this . props . onSelected )
28
28
this . container . on ( 'plotly_selected' , this . props . onSelected ) ;
29
- } ,
29
+ }
30
30
31
31
shouldComponentUpdate ( nextProps ) {
32
32
//TODO logic for detecting change in props
33
33
return true ;
34
- } ,
34
+ }
35
35
36
36
componentDidMount ( ) {
37
37
let { data, layout, config} = this . props ;
38
38
plotlyInstance . newPlot ( this . container , data , cloneDeep ( layout ) , config ) ; //We clone the layout as plotly mutates it.
39
39
this . attachListeners ( ) ;
40
- } ,
40
+ }
41
41
42
42
componentDidUpdate ( prevProps ) {
43
43
//TODO use minimal update for given changes
@@ -46,17 +46,17 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
46
46
plotlyInstance . newPlot ( this . container , data , cloneDeep ( layout ) , config ) ; //We clone the layout as plotly mutates it.
47
47
this . attachListeners ( ) ;
48
48
}
49
- } ,
49
+ }
50
50
51
- componentWillUnmount : function ( ) {
51
+ componentWillUnmount ( ) {
52
52
plotlyInstance . purge ( this . container ) ;
53
- } ,
53
+ }
54
54
55
- resize : function ( ) {
55
+ resize ( ) {
56
56
plotlyInstance . Plots . resize ( this . container ) ;
57
- } ,
57
+ }
58
58
59
- render : function ( ) {
59
+ render ( ) {
60
60
let { data, layout, config, ...other } = this . props ;
61
61
//Remove props that would cause React to warn for unknown props.
62
62
delete other . onClick ;
@@ -67,6 +67,6 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
67
67
68
68
return < div { ...other } ref = { ( node ) => this . container = node } />
69
69
}
70
- } ) ;
70
+ } ;
71
71
72
72
export default createPlotlyComponent ;
0 commit comments