Skip to content

Commit 5566c58

Browse files
committed
simplify the component
1 parent 92f2286 commit 5566c58

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

lib/ReactHeatmap.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.jsx

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,44 @@ import ReactDOM from 'react-dom';
33
import Heatmap from 'heatmap.js';
44

55
class ReactHeatmap extends React.Component {
6-
constructor(props) {
7-
super(props);
8-
this.setData = this.setData.bind(this);
9-
}
106

117
componentDidMount() {
12-
this.heatmap = Heatmap.create({
8+
const configObject = Object.assign({
139
container: ReactDOM.findDOMNode(this)
14-
});
15-
this.setData(this.props.max, this.props.data);
10+
}, this.props.configObject);
11+
12+
this.heatmap = Heatmap.create(configObject);
13+
14+
this.setData(this.props.min, this.props.max, this.props.data);
1615
}
1716

1817
componentWillReceiveProps(newProps) {
1918
this.setData(newProps.max, newProps.data);
2019
}
2120

22-
setData(max, data) {
23-
this.heatmap.setData({
24-
max: max,
25-
data: this.computeData(data)
26-
});
27-
}
28-
29-
computeData(data) {
30-
if (this.props.unit === 'percent') {
31-
let container = {};
32-
container.width = ReactDOM.findDOMNode(this).offsetWidth;
33-
container.height = ReactDOM.findDOMNode(this).offsetHeight;
34-
return data.map(function (values, index) {
35-
return {
36-
x: values.x / 100 * container.width,
37-
y: values.y / 100 * container.height,
38-
value: values.value
39-
}
40-
})
41-
} else {
42-
return data;
43-
}
21+
setData = (min, max, data) => {
22+
this.heatmap.setData({ min, max, data });
4423
}
4524

4625
render() {
4726
return (
48-
<div style={{ width: '100%', height: '100%' }}></div>
27+
<div style={{ width: '100%', height: '100%' }} />
4928
);
5029
}
5130
}
5231

5332
ReactHeatmap.propTypes = {
5433
max: React.PropTypes.number,
55-
data: React.PropTypes.array,
56-
unit: React.PropTypes.string
57-
}
34+
min: React.PropTypes.number,
35+
data: React.PropTypes.arrayOf(React.PropTypes.object),
36+
configObject: React.PropTypes.object
37+
};
5838

5939
ReactHeatmap.defaultProps = {
6040
max: 5,
41+
min: 0,
6142
data: [],
62-
unit: 'percent'
63-
}
43+
configObject: {}
44+
};
6445

6546
export default ReactHeatmap;

0 commit comments

Comments
 (0)