-
Notifications
You must be signed in to change notification settings - Fork 108
/
HighchartsReact.js
44 lines (35 loc) · 1.3 KB
/
HighchartsReact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var React = require('react')
var createReactClass = require('create-react-class')
var HighchartsReact = createReactClass({
componentDidMount: function () {
var p = this.props
var highcharts = p.highcharts || window.Highcharts
var constructorType = p.constructorType || 'chart'
// Create chart
this.chart = highcharts[constructorType](this.container, Object.assign({}, p.options))
},
shouldComponentUpdate: function (nextProps, nextState) {
var update = this.props.update
// Update if not specified or set to true
return (typeof update === 'undefined') || update
},
componentDidUpdate: function () {
this.chart.update(Object.assign({}, this.props.options), true, !(this.props.oneToOne === false))
},
componentWillReceiveProps: function () {
this.chart.update(Object.assign({}, this.props.options), true, !(this.props.oneToOne === false))
},
componentWillUnmount: function () {
// Destroy chart
this.chart.destroy()
},
render: function () {
var self = this
var containerProps = this.props.containerProps || {}
// Add ref to div props
containerProps.ref = function (container) { self.container = container }
// Create container for our chart
return React.createElement('div', containerProps)
}
})
module.exports = HighchartsReact