@@ -1463,8 +1463,11 @@ function (_React$Component) {
14631463 // animate the chart to show the changes
14641464
14651465 this . chartObj . render ( ) ;
1466+ return ;
14661467 }
1467- } else if ( ! this . isSameChartData ( currData , oldData ) ) {
1468+ }
1469+
1470+ if ( ! this . isSameChartData ( currData , oldData ) ) {
14681471 if ( ! utils . isUndefined ( currData ) ) {
14691472 this . chartObj . setChartData ( currData , // When dataFormat is not given, but data is changed,
14701473 // then use 'json' as default dataFormat
@@ -1475,11 +1478,35 @@ function (_React$Component) {
14751478 } , {
14761479 key : "isSameChartData" ,
14771480 value : function isSameChartData ( currData , oldData ) {
1478- if ( utils . isObject ( currData ) && utils . isObject ( oldData ) ) {
1479- return utils . isSameObjectContent ( currData , oldData ) ;
1480- }
1481+ /* TODO
1482+ 1. Current has DataStore and Old doesn't
1483+ 2. Old has and Current doesn't
1484+ 3. Both has, check ref is equal, return false only if not equal
1485+ 4. Clone oldData for diff
1486+ 5. Clone currentData for diff
1487+ 6. return string check.
1488+ */
1489+ // 1. Current has DataStore and Old doesn't
1490+ if ( utils . checkIfDataTableExists ( currData ) && ! utils . checkIfDataTableExists ( oldData ) ) {
1491+ return false ;
1492+ } // 2. Old has and Current doesn't
1493+
1494+
1495+ if ( ! utils . checkIfDataTableExists ( currData ) && utils . checkIfDataTableExists ( oldData ) ) {
1496+ return false ;
1497+ } // 3. Both has, check ref is equal, return false only if not equal
1498+
1499+
1500+ if ( utils . checkIfDataTableExists ( currData ) && utils . checkIfDataTableExists ( oldData ) && currData . data !== oldData . data ) {
1501+ return false ;
1502+ } // 4. Clone oldData for diff
1503+
14811504
1482- return currData === oldData ;
1505+ var oldDataStringified = JSON . stringify ( utils . cloneDataSource ( oldData , 'diff' ) ) ; // 5. Clone currentData for diff
1506+
1507+ var currentDataStringified = JSON . stringify ( utils . cloneDataSource ( currData , 'diff' ) ) ; // 6. return string check.
1508+
1509+ return oldDataStringified === currentDataStringified ;
14831510 }
14841511 } , {
14851512 key : "checkAndUpdateEvents" ,
@@ -1616,8 +1643,10 @@ function (_React$Component) {
16161643
16171644 Object . assign ( inlineOptions , chartConfig ) ;
16181645
1619- if ( utils . isObject ( inlineOptions . dataSource ) ) {
1646+ if ( utils . isObject ( inlineOptions . dataSource ) && ! utils . checkIfDataTableExists ( inlineOptions . dataSource ) ) {
16201647 inlineOptions . dataSource = utils . deepCopyOf ( inlineOptions . dataSource ) ;
1648+ } else if ( utils . isObject ( inlineOptions . dataSource ) && utils . checkIfDataTableExists ( inlineOptions . dataSource ) ) {
1649+ inlineOptions . dataSource = utils . cloneDataSource ( inlineOptions . dataSource , 'clone' ) ;
16211650 }
16221651
16231652 if ( utils . isObject ( inlineOptions . link ) ) {
@@ -1774,6 +1803,8 @@ exports.isCallable = isCallable;
17741803exports . isSameObjectContent = isSameObjectContent ;
17751804exports . isUndefined = isUndefined ;
17761805exports . deepCopyOf = deepCopyOf ;
1806+ exports . checkIfDataTableExists = checkIfDataTableExists ;
1807+ exports . cloneDataSource = cloneDataSource ;
17771808
17781809function _typeof ( obj ) {
17791810 if ( typeof Symbol === "function" && _typeof2 ( Symbol . iterator ) === "symbol" ) {
@@ -1788,6 +1819,8 @@ function _typeof(obj) {
17881819
17891820 return _typeof ( obj ) ;
17901821}
1822+ /* eslint-disable guard-for-in */
1823+
17911824
17921825function isObject ( value ) {
17931826 return value !== null && _typeof ( value ) === 'object' ;
@@ -1829,6 +1862,66 @@ function deepCopyOf(obj) {
18291862 return JSON . parse ( JSON . stringify ( obj ) ) ;
18301863}
18311864
1865+ function checkIfDataTableExists ( dataSource ) {
1866+ // eslint-disable-next-line no-underscore-dangle
1867+ if ( dataSource && dataSource . data && dataSource . data . _dataStore ) {
1868+ return true ;
1869+ }
1870+
1871+ return false ;
1872+ }
1873+
1874+ function cloneDataSource ( obj ) {
1875+ var purpose = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 'clone' ;
1876+
1877+ var type = _typeof ( obj ) ;
1878+
1879+ if ( type === 'string' || type === 'number' || type === 'function' || type === 'boolean' ) {
1880+ return obj ;
1881+ }
1882+
1883+ if ( obj === null || obj === undefined ) {
1884+ return obj ;
1885+ }
1886+
1887+ if ( Array . isArray ( obj ) ) {
1888+ var arr = [ ] ;
1889+
1890+ for ( var i = 0 ; i < obj . length ; i ++ ) {
1891+ arr . push ( this . cloneDataSource ( obj [ i ] ) ) ;
1892+ }
1893+
1894+ return arr ;
1895+ }
1896+
1897+ if ( _typeof ( obj ) === 'object' ) {
1898+ var clonedObj = { } ; // eslint-disable-next-line guard-for-in
1899+ // eslint-disable-next-line no-restricted-syntax
1900+
1901+ for ( var prop in obj ) {
1902+ // Edge case handling for DataTable
1903+ if ( prop === 'data' ) {
1904+ // eslint-disable-next-line no-underscore-dangle
1905+ if ( obj [ prop ] . _dataStore && purpose === 'clone' ) {
1906+ clonedObj [ prop ] = obj [ prop ] ; // eslint-disable-next-line no-underscore-dangle
1907+ } else if ( obj [ prop ] . _dataStore && purpose === 'diff' ) {
1908+ clonedObj [ prop ] = '-' ;
1909+ } else {
1910+ clonedObj [ prop ] = this . cloneDataSource ( obj [ prop ] ) ;
1911+ }
1912+
1913+ continue ;
1914+ }
1915+
1916+ clonedObj [ prop ] = this . cloneDataSource ( obj [ prop ] ) ;
1917+ }
1918+
1919+ return clonedObj ;
1920+ }
1921+
1922+ return undefined ;
1923+ }
1924+
18321925/***/ } ) ,
18331926/* 14 */
18341927/***/ ( function ( module , exports , __webpack_require__ ) {
0 commit comments