@@ -1463,8 +1463,11 @@ function (_React$Component) {
1463
1463
// animate the chart to show the changes
1464
1464
1465
1465
this . chartObj . render ( ) ;
1466
+ return ;
1466
1467
}
1467
- } else if ( ! this . isSameChartData ( currData , oldData ) ) {
1468
+ }
1469
+
1470
+ if ( ! this . isSameChartData ( currData , oldData ) ) {
1468
1471
if ( ! utils . isUndefined ( currData ) ) {
1469
1472
this . chartObj . setChartData ( currData , // When dataFormat is not given, but data is changed,
1470
1473
// then use 'json' as default dataFormat
@@ -1475,11 +1478,35 @@ function (_React$Component) {
1475
1478
} , {
1476
1479
key : "isSameChartData" ,
1477
1480
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
+
1481
1504
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 ;
1483
1510
}
1484
1511
} , {
1485
1512
key : "checkAndUpdateEvents" ,
@@ -1616,8 +1643,10 @@ function (_React$Component) {
1616
1643
1617
1644
Object . assign ( inlineOptions , chartConfig ) ;
1618
1645
1619
- if ( utils . isObject ( inlineOptions . dataSource ) ) {
1646
+ if ( utils . isObject ( inlineOptions . dataSource ) && ! utils . checkIfDataTableExists ( inlineOptions . dataSource ) ) {
1620
1647
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' ) ;
1621
1650
}
1622
1651
1623
1652
if ( utils . isObject ( inlineOptions . link ) ) {
@@ -1774,6 +1803,8 @@ exports.isCallable = isCallable;
1774
1803
exports . isSameObjectContent = isSameObjectContent ;
1775
1804
exports . isUndefined = isUndefined ;
1776
1805
exports . deepCopyOf = deepCopyOf ;
1806
+ exports . checkIfDataTableExists = checkIfDataTableExists ;
1807
+ exports . cloneDataSource = cloneDataSource ;
1777
1808
1778
1809
function _typeof ( obj ) {
1779
1810
if ( typeof Symbol === "function" && _typeof2 ( Symbol . iterator ) === "symbol" ) {
@@ -1788,6 +1819,8 @@ function _typeof(obj) {
1788
1819
1789
1820
return _typeof ( obj ) ;
1790
1821
}
1822
+ /* eslint-disable guard-for-in */
1823
+
1791
1824
1792
1825
function isObject ( value ) {
1793
1826
return value !== null && _typeof ( value ) === 'object' ;
@@ -1829,6 +1862,66 @@ function deepCopyOf(obj) {
1829
1862
return JSON . parse ( JSON . stringify ( obj ) ) ;
1830
1863
}
1831
1864
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
+
1832
1925
/***/ } ) ,
1833
1926
/* 14 */
1834
1927
/***/ ( function ( module , exports , __webpack_require__ ) {
0 commit comments