@@ -3,63 +3,44 @@ import ReactDOM from 'react-dom';
33import Heatmap from 'heatmap.js' ;
44
55class 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
5332ReactHeatmap . 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
5939ReactHeatmap . defaultProps = {
6040 max : 5 ,
41+ min : 0 ,
6142 data : [ ] ,
62- unit : 'percent'
63- }
43+ configObject : { }
44+ } ;
6445
6546export default ReactHeatmap ;
0 commit comments