Skip to content

Commit b957fe2

Browse files
author
Ben Jeffery
committed
Allow custom plotly bundles to be used
1 parent 72cc2a9 commit b957fe2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/PlotlyComponent.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
2-
import Plotly from 'plotly.js';
32
import cloneDeep from 'lodash.clonedeep';
43

5-
var PlotlyComponent = React.createClass({
6-
4+
let createPlotlyComponent = (plotlyInstance) => React.createClass({
75
displayName: 'Plotly',
86
propTypes: {
97
data: React.PropTypes.array,
@@ -36,24 +34,24 @@ var PlotlyComponent = React.createClass({
3634

3735
componentDidMount() {
3836
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.
4038
this.attachListeners();
4139
},
4240

4341
componentDidUpdate(prevProps) {
4442
//TODO use minimal update for given changes
4543
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);
4745
this.attachListeners();
4846
}
4947
},
5048

5149
componentWillUnmount: function() {
52-
Plotly.purge(this.container);
50+
plotlyInstance.purge(this.container);
5351
},
5452

5553
resize: function() {
56-
Plotly.Plots.resize(this.container);
54+
plotlyInstance.Plots.resize(this.container);
5755
},
5856

5957
render: function () {
@@ -69,4 +67,4 @@ var PlotlyComponent = React.createClass({
6967
}
7068
});
7169

72-
module.exports = PlotlyComponent;
70+
export default createPlotlyComponent;

0 commit comments

Comments
 (0)