@@ -29,6 +29,10 @@ var _chartJs = require('chart.js');
2929
3030var _chartJs2 = _interopRequireDefault ( _chartJs ) ;
3131
32+ var _utilsDeepEqual = require ( './utils/deepEqual' ) ;
33+
34+ var _utilsDeepEqual2 = _interopRequireDefault ( _utilsDeepEqual ) ;
35+
3236var ChartComponent = _react2 [ 'default' ] . createClass ( {
3337
3438 displayName : 'ChartComponent' ,
@@ -52,7 +56,7 @@ var ChartComponent = _react2['default'].createClass({
5256 type : 'doughnut' ,
5357 height : 200 ,
5458 width : 200 ,
55- redraw : true
59+ redraw : false
5660 } ;
5761 } ,
5862
@@ -68,23 +72,55 @@ var ChartComponent = _react2['default'].createClass({
6872 if ( this . props . redraw ) {
6973 this . chart_instance . destroy ( ) ;
7074 this . renderChart ( ) ;
75+ } else {
76+ this . updateChart ( ) ;
77+ }
78+ } ,
79+
80+ _objectWithoutProperties : function _objectWithoutProperties ( obj , keys ) {
81+ var target = { } ;
82+ for ( var i in obj ) {
83+ if ( keys . indexOf ( i ) >= 0 ) continue ;
84+ if ( ! Object . prototype . hasOwnProperty . call ( obj , i ) ) continue ;
85+ target [ i ] = obj [ i ] ;
7186 }
87+ return target ;
7288 } ,
7389
74- shouldComponentUpdate : function shouldComponentUpdate ( nextProps ) {
75- return this . props !== nextProps ;
90+ shouldComponentUpdate : function shouldComponentUpdate ( nextProps , nextState ) {
91+ var compareNext = this . _objectWithoutProperties ( nextProps , [ "id" , "width" , "height" ] ) ;
92+ var compareNow = this . _objectWithoutProperties ( this . props , [ "id" , "width" , "height" ] ) ;
93+ return ! ( 0 , _utilsDeepEqual2 [ 'default' ] ) ( compareNext , compareNow , { strict : true } ) ;
7694 } ,
7795
7896 componentWillUnmount : function componentWillUnmount ( ) {
7997 this . chart_instance . destroy ( ) ;
8098 } ,
8199
82- renderChart : function renderChart ( ) {
100+ updateChart : function updateChart ( ) {
101+ var _this = this ;
102+
83103 var _props = this . props ;
84104 var data = _props . data ;
85105 var options = _props . options ;
86- var legend = _props . legend ;
87- var type = _props . type ;
106+
107+ this . chart_instance . options . scales . xAxes [ 0 ] . ticks . min = options . scales . xAxes [ 0 ] . ticks . min ;
108+ this . chart_instance . options . scales . xAxes [ 0 ] . ticks . max = options . scales . xAxes [ 0 ] . ticks . max ;
109+ this . chart_instance . options . scales . xAxes [ 0 ] . fixedBarWidth = options . scales . xAxes [ 0 ] . fixedBarWidth ;
110+
111+ data . datasets . forEach ( function ( dataset , index ) {
112+ _this . chart_instance . data . datasets [ index ] . backgroundColor = dataset . backgroundColor ;
113+ } ) ;
114+
115+ this . chart_instance . update ( ) ;
116+ } ,
117+
118+ renderChart : function renderChart ( ) {
119+ var _props2 = this . props ;
120+ var data = _props2 . data ;
121+ var options = _props2 . options ;
122+ var legend = _props2 . legend ;
123+ var type = _props2 . type ;
88124
89125 var node = _reactDom2 [ 'default' ] . findDOMNode ( this ) ;
90126
@@ -96,9 +132,9 @@ var ChartComponent = _react2['default'].createClass({
96132 } ,
97133
98134 render : function render ( ) {
99- var _props2 = this . props ;
100- var height = _props2 . height ;
101- var width = _props2 . width ;
135+ var _props3 = this . props ;
136+ var height = _props3 . height ;
137+ var width = _props3 . width ;
102138
103139 return _react2 [ 'default' ] . createElement ( 'canvas' , {
104140 height : height ,
@@ -134,5 +170,59 @@ function Polar(props) {
134170}
135171
136172} ) . call ( this , typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
137- } , { "chart.js" :undefined , "react-dom" :undefined } ] } , { } , [ 1 ] ) ( 1 )
173+ } , { "./utils/deepEqual" :2 , "chart.js" :undefined , "react-dom" :undefined } ] , 2 :[ function ( require , module , exports ) {
174+ 'use strict' ;
175+
176+ Object . defineProperty ( exports , '__esModule' , {
177+ value : true
178+ } ) ;
179+ var hasOwnProperty = Object . prototype . hasOwnProperty ;
180+
181+ var is = function is ( x , y ) {
182+ // SameValue algorithm
183+ if ( x === y ) {
184+ // Steps 1-5, 7-10
185+ // Steps 6.b-6.e: +0 != -0
186+ return x !== 0 || 1 / x === 1 / y ;
187+ } else {
188+ // Step 6.a: NaN == NaN
189+ return x !== x && y !== y ;
190+ }
191+ } ;
192+
193+ var deepEqual = function deepEqual ( objA , objB ) {
194+ if ( is ( objA , objB ) ) {
195+ return true ;
196+ }
197+
198+ if ( typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null ) {
199+ return false ;
200+ }
201+
202+ var keysA = Object . keys ( objA ) ;
203+
204+ // Test for A's keys different from B.
205+ for ( var i = 0 ; i < keysA . length ; i ++ ) {
206+ if ( ! hasOwnProperty . call ( objB , keysA [ i ] ) ) {
207+ return false ;
208+ }
209+ }
210+
211+ for ( var propty in objA ) {
212+ if ( objB . hasOwnProperty ( propty ) ) {
213+ if ( ! deepEqual ( objA [ propty ] , objB [ propty ] ) ) {
214+ return false ;
215+ }
216+ } else {
217+ return false ;
218+ }
219+ }
220+
221+ return true ;
222+ } ;
223+
224+ exports [ 'default' ] = deepEqual ;
225+ module . exports = exports [ 'default' ] ;
226+
227+ } , { } ] } , { } , [ 1 ] ) ( 1 )
138228} ) ;
0 commit comments