@@ -1973,13 +1973,22 @@ var ChartComponent = function (_React$Component) {
19731973 return true ;
19741974 }
19751975
1976- return ! ( 0 , _lodash2 . default ) ( this . shadowDataProp , nextProps . data ) ;
1976+ var nextData = this . transformDataProp ( ) ;
1977+ return ! ( 0 , _lodash2 . default ) ( this . shadowDataProp , nextData ) ;
19771978 }
19781979 } , {
19791980 key : 'componentWillUnmount' ,
19801981 value : function componentWillUnmount ( ) {
19811982 this . chart_instance . destroy ( ) ;
19821983 }
1984+ } , {
1985+ key : 'transformDataProp' ,
1986+ value : function transformDataProp ( ) {
1987+ var data = this . props . data ;
1988+
1989+ var node = _reactDom2 . default . findDOMNode ( this ) ;
1990+ return typeof data == "function" ? data ( node ) : data ;
1991+ }
19831992
19841993 // Chart.js directly mutates the data.dataset objects by adding _meta proprerty
19851994 // this makes impossible to compare the current and next data changes
@@ -1989,28 +1998,27 @@ var ChartComponent = function (_React$Component) {
19891998 } , {
19901999 key : 'memoizeDataProps' ,
19912000 value : function memoizeDataProps ( ) {
1992- var data = this . props . data ;
1993-
1994-
1995- if ( ! data ) {
2001+ if ( ! this . props . data ) {
19962002 return ;
19972003 }
19982004
2005+ var data = this . transformDataProp ( ) ;
2006+
19992007 this . shadowDataProp = _extends ( { } , data , {
20002008 datasets : data . datasets && data . datasets . map ( function ( set ) {
20012009 return _extends ( { } , set ) ;
20022010 } )
20032011 } ) ;
2012+
2013+ return data ;
20042014 }
20052015 } , {
20062016 key : 'updateChart' ,
20072017 value : function updateChart ( ) {
2008- var _props2 = this . props ,
2009- data = _props2 . data ,
2010- options = _props2 . options ;
2018+ var options = this . props . options ;
20112019
20122020
2013- this . memoizeDataProps ( ) ;
2021+ var data = this . memoizeDataProps ( ) ;
20142022
20152023 if ( ! this . chart_instance ) return ;
20162024
@@ -2023,6 +2031,11 @@ var ChartComponent = function (_React$Component) {
20232031 var currentDatasets = this . chart_instance . config . data && this . chart_instance . config . data . datasets || [ ] ;
20242032 var nextDatasets = data . datasets || [ ] ;
20252033
2034+ // Prevent charting of legend items that no longer exist
2035+ while ( currentDatasets . length > nextDatasets . length ) {
2036+ currentDatasets . pop ( ) ;
2037+ }
2038+
20262039 nextDatasets . forEach ( function ( dataset , sid ) {
20272040 if ( currentDatasets [ sid ] && currentDatasets [ sid ] . data ) {
20282041 currentDatasets [ sid ] . data . splice ( nextDatasets [ sid ] . data . length ) ;
@@ -2052,16 +2065,14 @@ var ChartComponent = function (_React$Component) {
20522065 } , {
20532066 key : 'renderChart' ,
20542067 value : function renderChart ( ) {
2055- var _props3 = this . props ,
2056- data = _props3 . data ,
2057- options = _props3 . options ,
2058- legend = _props3 . legend ,
2059- type = _props3 . type ,
2060- redraw = _props3 . redraw ;
2068+ var _props2 = this . props ,
2069+ options = _props2 . options ,
2070+ legend = _props2 . legend ,
2071+ type = _props2 . type ,
2072+ redraw = _props2 . redraw ;
20612073
20622074 var node = _reactDom2 . default . findDOMNode ( this ) ;
2063-
2064- this . memoizeDataProps ( ) ;
2075+ var data = this . memoizeDataProps ( ) ;
20652076
20662077 this . chart_instance = new _chart2 . default ( node , {
20672078 type : type ,
@@ -2072,10 +2083,10 @@ var ChartComponent = function (_React$Component) {
20722083 } , {
20732084 key : 'render' ,
20742085 value : function render ( ) {
2075- var _props4 = this . props ,
2076- height = _props4 . height ,
2077- width = _props4 . width ,
2078- onElementsClick = _props4 . onElementsClick ;
2086+ var _props3 = this . props ,
2087+ height = _props3 . height ,
2088+ width = _props3 . width ,
2089+ onElementsClick = _props3 . onElementsClick ;
20792090
20802091
20812092 return _react2 . default . createElement ( 'canvas' , {
@@ -2090,7 +2101,7 @@ var ChartComponent = function (_React$Component) {
20902101} ( _react2 . default . Component ) ;
20912102
20922103ChartComponent . propTypes = {
2093- data : _react . PropTypes . object . isRequired ,
2104+ data : _react . PropTypes . oneOfType ( [ _react . PropTypes . object , _react . PropTypes . func ] ) . isRequired ,
20942105 getDatasetAtEvent : _react . PropTypes . func ,
20952106 getElementAtEvent : _react . PropTypes . func ,
20962107 getElementsAtEvent : _react . PropTypes . func ,
0 commit comments