Skip to content

Commit a95e12a

Browse files
authored
Merge pull request #37 from rohanoid5/feature/timeseries-support
Added timeseries support
2 parents 0eb6717 + c3c0739 commit a95e12a

File tree

10 files changed

+511
-62
lines changed

10 files changed

+511
-62
lines changed

dist/drill-down.js

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
17741803
exports.isSameObjectContent = isSameObjectContent;
17751804
exports.isUndefined = isUndefined;
17761805
exports.deepCopyOf = deepCopyOf;
1806+
exports.checkIfDataTableExists = checkIfDataTableExists;
1807+
exports.cloneDataSource = cloneDataSource;
17771808

17781809
function _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

17921825
function 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__) {

dist/drill-down.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-fusioncharts.js

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ function (_React$Component) {
263263
// animate the chart to show the changes
264264

265265
this.chartObj.render();
266+
return;
266267
}
267-
} else if (!this.isSameChartData(currData, oldData)) {
268+
}
269+
270+
if (!this.isSameChartData(currData, oldData)) {
268271
if (!_utils_utils__WEBPACK_IMPORTED_MODULE_3__["isUndefined"](currData)) {
269272
this.chartObj.setChartData(currData, // When dataFormat is not given, but data is changed,
270273
// then use 'json' as default dataFormat
@@ -275,11 +278,35 @@ function (_React$Component) {
275278
}, {
276279
key: "isSameChartData",
277280
value: function isSameChartData(currData, oldData) {
278-
if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["isObject"](currData) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__["isObject"](oldData)) {
279-
return _utils_utils__WEBPACK_IMPORTED_MODULE_3__["isSameObjectContent"](currData, oldData);
280-
}
281+
/* TODO
282+
1. Current has DataStore and Old doesn't
283+
2. Old has and Current doesn't
284+
3. Both has, check ref is equal, return false only if not equal
285+
4. Clone oldData for diff
286+
5. Clone currentData for diff
287+
6. return string check.
288+
*/
289+
// 1. Current has DataStore and Old doesn't
290+
if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](currData) && !_utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](oldData)) {
291+
return false;
292+
} // 2. Old has and Current doesn't
293+
294+
295+
if (!_utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](currData) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](oldData)) {
296+
return false;
297+
} // 3. Both has, check ref is equal, return false only if not equal
298+
299+
300+
if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](currData) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](oldData) && currData.data !== oldData.data) {
301+
return false;
302+
} // 4. Clone oldData for diff
281303

282-
return currData === oldData;
304+
305+
var oldDataStringified = JSON.stringify(_utils_utils__WEBPACK_IMPORTED_MODULE_3__["cloneDataSource"](oldData, 'diff')); // 5. Clone currentData for diff
306+
307+
var currentDataStringified = JSON.stringify(_utils_utils__WEBPACK_IMPORTED_MODULE_3__["cloneDataSource"](currData, 'diff')); // 6. return string check.
308+
309+
return oldDataStringified === currentDataStringified;
283310
}
284311
}, {
285312
key: "checkAndUpdateEvents",
@@ -414,8 +441,10 @@ function (_React$Component) {
414441
}, {});
415442
Object.assign(inlineOptions, chartConfig);
416443

417-
if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["isObject"](inlineOptions.dataSource)) {
444+
if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["isObject"](inlineOptions.dataSource) && !_utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](inlineOptions.dataSource)) {
418445
inlineOptions.dataSource = _utils_utils__WEBPACK_IMPORTED_MODULE_3__["deepCopyOf"](inlineOptions.dataSource);
446+
} else if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["isObject"](inlineOptions.dataSource) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__["checkIfDataTableExists"](inlineOptions.dataSource)) {
447+
inlineOptions.dataSource = _utils_utils__WEBPACK_IMPORTED_MODULE_3__["cloneDataSource"](inlineOptions.dataSource, 'clone');
419448
}
420449

421450
if (_utils_utils__WEBPACK_IMPORTED_MODULE_3__["isObject"](inlineOptions.link)) {
@@ -571,8 +600,11 @@ __webpack_require__.r(__webpack_exports__);
571600
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isSameObjectContent", function() { return isSameObjectContent; });
572601
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isUndefined", function() { return isUndefined; });
573602
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deepCopyOf", function() { return deepCopyOf; });
603+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkIfDataTableExists", function() { return checkIfDataTableExists; });
604+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cloneDataSource", function() { return cloneDataSource; });
574605
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
575606

607+
/* eslint-disable guard-for-in */
576608
function isObject(value) {
577609
return value !== null && _typeof(value) === 'object';
578610
}
@@ -608,6 +640,64 @@ function isUndefined(value) {
608640
function deepCopyOf(obj) {
609641
return JSON.parse(JSON.stringify(obj));
610642
}
643+
function checkIfDataTableExists(dataSource) {
644+
// eslint-disable-next-line no-underscore-dangle
645+
if (dataSource && dataSource.data && dataSource.data._dataStore) {
646+
return true;
647+
}
648+
649+
return false;
650+
}
651+
function cloneDataSource(obj) {
652+
var purpose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'clone';
653+
654+
var type = _typeof(obj);
655+
656+
if (type === 'string' || type === 'number' || type === 'function' || type === 'boolean') {
657+
return obj;
658+
}
659+
660+
if (obj === null || obj === undefined) {
661+
return obj;
662+
}
663+
664+
if (Array.isArray(obj)) {
665+
var arr = [];
666+
667+
for (var i = 0; i < obj.length; i++) {
668+
arr.push(this.cloneDataSource(obj[i]));
669+
}
670+
671+
return arr;
672+
}
673+
674+
if (_typeof(obj) === 'object') {
675+
var clonedObj = {}; // eslint-disable-next-line guard-for-in
676+
// eslint-disable-next-line no-restricted-syntax
677+
678+
for (var prop in obj) {
679+
// Edge case handling for DataTable
680+
if (prop === 'data') {
681+
// eslint-disable-next-line no-underscore-dangle
682+
if (obj[prop]._dataStore && purpose === 'clone') {
683+
clonedObj[prop] = obj[prop]; // eslint-disable-next-line no-underscore-dangle
684+
} else if (obj[prop]._dataStore && purpose === 'diff') {
685+
clonedObj[prop] = '-';
686+
} else {
687+
clonedObj[prop] = this.cloneDataSource(obj[prop]);
688+
}
689+
690+
continue;
691+
}
692+
693+
clonedObj[prop] = this.cloneDataSource(obj[prop]);
694+
}
695+
696+
return clonedObj;
697+
}
698+
699+
return undefined;
700+
}
611701

612702
/***/ }),
613703
/* 8 */

0 commit comments

Comments
 (0)