Skip to content

Commit 2b75c1b

Browse files
committed
Merge branch 'release/3.0.0'
2 parents 4f35d65 + 02e787a commit 2b75c1b

File tree

11 files changed

+605
-67
lines changed

11 files changed

+605
-67
lines changed

README.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A simple and lightweight official React component for FusionCharts JavaScript ch
2424
- [Custom Components](#custom-components)
2525
- [Drill Down](#drill-down-component)
2626
- [Going Beyond Charts](#going-beyond-charts)
27+
- [Usage and Integration of FusionTime](#usage-and-integration-of-fusionTime)
2728
- [For Contributors](#for-contributors)
2829
- [Licensing](#licensing)
2930

@@ -76,8 +77,8 @@ ReactFC.fcRoot(FusionCharts);
7677

7778
Here is a basic sample that shows how to create a chart using `react-fusioncharts`:
7879

79-
```
80-
import React from 'react;
80+
```javascript
81+
import React from 'react';
8182
import ReactDOM from 'react-dom';
8283
import FusionCharts from 'fusioncharts';
8384
import Charts from 'fusioncharts/fusioncharts.charts';
@@ -263,6 +264,96 @@ class Chart extends Component {
263264
ReactDOM.render(<Chart />, document.getElementById('root'));
264265
```
265266

267+
## Usage and integration of FusionTime
268+
269+
From `fusioncharts@3.13.3-sr.1` and `react-fusioncharts@3.0.0`, You can visualize timeseries data easily on react.
270+
271+
Learn more about FusionTime [here](https://www.fusioncharts.com/fusiontime).
272+
273+
### Consider the example below for integration of FusionTime
274+
275+
```javascript
276+
import React from 'react';
277+
import FusionCharts from 'fusioncharts';
278+
import TimeSeries from 'fusioncharts/fusioncharts.timeseries';
279+
import ReactFC from '../lib/ReactFC';
280+
281+
ReactFC.fcRoot(FusionCharts, TimeSeries);
282+
283+
const jsonify = res => res.json();
284+
const dataFetch = fetch(
285+
'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/data.json'
286+
).then(jsonify);
287+
const schemaFetch = fetch(
288+
'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/schema.json'
289+
).then(jsonify);
290+
291+
class ChartViewer extends React.Component {
292+
constructor(props) {
293+
super(props);
294+
this.onFetchData = this.onFetchData.bind(this);
295+
this.state = {
296+
timeseriesDs: {
297+
type: 'timeseries',
298+
renderAt: 'container',
299+
width: '600',
300+
height: '400',
301+
dataSource: {
302+
caption: { text: 'Online Sales of a SuperStore in the US' },
303+
data: null,
304+
yAxis: [
305+
{
306+
plot: [
307+
{
308+
value: 'Sales ($)'
309+
}
310+
]
311+
}
312+
]
313+
}
314+
}
315+
};
316+
}
317+
318+
componentDidMount() {
319+
this.onFetchData();
320+
}
321+
322+
onFetchData() {
323+
Promise.all([dataFetch, schemaFetch]).then(res => {
324+
const data = res[0];
325+
const schema = res[1];
326+
const fusionTable = new FusionCharts.DataStore().createDataTable(
327+
data,
328+
schema
329+
);
330+
const timeseriesDs = Object.assign({}, this.state.timeseriesDs);
331+
timeseriesDs.dataSource.data = fusionTable;
332+
this.setState({
333+
timeseriesDs
334+
});
335+
});
336+
}
337+
338+
render() {
339+
return (
340+
<div>
341+
{this.state.timeseriesDs.dataSource.data ? (
342+
<ReactFC {...this.state.timeseriesDs} />
343+
) : (
344+
'loading'
345+
)}
346+
</div>
347+
);
348+
}
349+
}
350+
```
351+
352+
Useful links for FusionTime
353+
354+
- [How FusionTime works](https://www.fusioncharts.com/dev/fusiontime/getting-started/how-fusion-time-works)
355+
- [Create your first chart](https://www.fusioncharts.com/dev/fusiontime/getting-started/create-your-first-chart-in-fusiontime)
356+
266357
## Drill Down Component
267358

268359
A custom component to easily add drill down to your react application.

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.

0 commit comments

Comments
 (0)