-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathchart.jsx
More file actions
50 lines (42 loc) · 1.19 KB
/
Copy pathchart.jsx
File metadata and controls
50 lines (42 loc) · 1.19 KB
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
45
46
47
48
49
50
import React, {PropTypes} from 'react';
import createVisualization from '../createVisualization';
export default React.createClass({
propTypes: {
data: PropTypes.object,
onHover: PropTypes.func,
onRender: PropTypes.func,
onUnhover: PropTypes.func
},
componentDidMount() {
if (this.props.data) {
this.createChart(this.props.data);
}
},
componentDidUpdate(prevProps) {
let shouldUpdate = this.props.data && (
this.props.data !== prevProps.data ||
this.props.labels !== prevProps.labels
);
if (shouldUpdate) {
this.createChart(this.props.data);
}
},
createChart(root) {
let details = createVisualization({
svgElement: this.refs.svg,
root,
onHover: this.props.onHover,
onUnhover: this.props.onUnhover,
labels: this.props.labels
});
if (this.props.onRender) {
this.props.onRender(details);
}
},
render() {
if (!this.props.data) {
return null;
}
return <svg ref="svg" />;
}
});