Skip to content

Commit 91cff7a

Browse files
authored
Merge pull request #56 from fusioncharts/feature/update-react
Feature/update react
2 parents d7b3978 + c090b2e commit 91cff7a

File tree

4 files changed

+58
-47
lines changed

4 files changed

+58
-47
lines changed

example/ChartViewer.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,59 @@ import ReactFC from '../lib/ReactFC';
77

88
ReactFC.fcRoot(FusionCharts, Charts, TimeSeries, FusionTheme);
99

10-
const dataSource = {
11-
chart: {
12-
caption: 'Countries With Most Oil Reserves [2017-18]',
13-
subCaption: 'In MMbbl = One Million barrels',
14-
xAxisName: 'Country',
15-
yAxisName: 'Reserves (MMbbl)',
16-
numberSuffix: 'K',
17-
theme: 'fusion'
18-
},
19-
data: [
20-
{ label: 'Venezuela', value: '290' },
21-
{ label: 'Saudi', value: '260' },
22-
{ label: 'Canada', value: '180' },
23-
{ label: 'Iran', value: '140' },
24-
{ label: 'Russia', value: '115' },
25-
{ label: 'UAE', value: '100' },
26-
{ label: 'US', value: '30' },
27-
{ label: 'China', value: '30' }
28-
]
29-
};
30-
31-
const chartConfigs = {
32-
type: 'column2d',
33-
width: 600,
34-
height: 400,
35-
dataFormat: 'json',
36-
dataSource
37-
};
10+
const BAR = 'bar2d';
3811

3912
class ChartViewer extends React.Component {
4013
constructor(props) {
4114
super(props);
4215

43-
this.state = {};
16+
this.state = {
17+
inverted: false,
18+
type: BAR,
19+
dataSource: {
20+
chart: {
21+
caption: 'Countries With Most Oil Reserves [2017-18]',
22+
subCaption: 'In MMbbl = One Million barrels',
23+
xAxisName: 'Country',
24+
yAxisName: 'Reserves (MMbbl)',
25+
numberSuffix: 'K',
26+
theme: 'fusion'
27+
},
28+
data: [
29+
{ label: 'Venezuela', value: '290' },
30+
{ label: 'Saudi', value: '260' },
31+
{ label: 'Canada', value: '180' },
32+
{ label: 'Iran', value: '140' },
33+
{ label: 'Russia', value: '115' },
34+
{ label: 'UAE', value: '100' },
35+
{ label: 'US', value: '30' },
36+
{ label: 'China', value: '300' }
37+
]
38+
}
39+
};
40+
this.onChange = this.onChange.bind(this);
41+
}
42+
43+
onChange() {
44+
this.setState(({ dataSource }) => ({
45+
dataSource: {
46+
...dataSource,
47+
chart: { ...dataSource.chart, caption: 'CHANGED IT!!!!!!!' }
48+
}
49+
}));
4450
}
4551

4652
render() {
4753
return (
4854
<div>
49-
<ReactFC {...chartConfigs} />
55+
<ReactFC
56+
type={this.state.type}
57+
width={this.state.inverted ? '400' : '600'}
58+
height={this.state.inverted ? '600' : '400'}
59+
dataFormat="json"
60+
dataSource={this.state.dataSource}
61+
/>
62+
<button onClick={this.onChange}>CHANGE</button>
5063
</div>
5164
);
5265
}

lib/ReactFC.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function (_React$Component) {
6666
_this = _possibleConstructorReturn(this, _getPrototypeOf(ReactFC).call(this, props));
6767
_this.containerId = (0, _v["default"])();
6868
_this.oldOptions = null;
69-
_this.FusionCharts = props.fcLibrary || ReactFC.fusionChartsCore;
69+
_this.FusionCharts = props.fcLibrary || ReactFC.fusionChartsCore || window.FusionCharts;
7070
return _this;
7171
}
7272

@@ -76,13 +76,11 @@ function (_React$Component) {
7676
this.renderChart();
7777
}
7878
}, {
79-
key: "componentWillReceiveProps",
80-
value: function componentWillReceiveProps(nextProps) {
81-
if (!this.oldOptions) {
82-
return;
79+
key: "componentDidUpdate",
80+
value: function componentDidUpdate(prevProps) {
81+
if (prevProps !== this.props) {
82+
this.detectChanges(this.props);
8383
}
84-
85-
this.detectChanges(nextProps);
8684
}
8785
}, {
8886
key: "componentWillUnmount",

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
"fusioncharts": "^3.13.5-sr.1",
5959
"jest": "^22.4.2",
6060
"lodash": "^4.17.11",
61+
"nodemon": "^2.0.2",
6162
"prop-types": "^15.6.2",
62-
"react": "^16.2.0",
63+
"react": "^16.12.0",
6364
"react-addons-test-utils": "15.3.0",
6465
"react-component-gulp-tasks": "^0.7.6",
65-
"react-dom": "^16.2.0",
66-
"react-native": "^0.54.2",
66+
"react-dom": "^16.12.0",
6767
"react-test-renderer": "^16.2.0",
6868
"serve": "^10.0.1",
6969
"webpack": "^4.20.2",
@@ -79,7 +79,8 @@
7979
"build:example": "npm run build:lib && webpack --config webpack.config.example.js",
8080
"start": "npm run build:example && serve example/",
8181
"test": "jest --coverage --verbose",
82-
"test:report": "npm test && serve coverage/lcov-report -o"
82+
"test:report": "npm test && serve coverage/lcov-report -o",
83+
"watch": "nodemon --ignore example/dist --watch example --watch src --exec \"npm run start\""
8384
},
8485
"keywords": [
8586
"react",

src/ReactFC.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
// import FusionCharts from 'fusioncharts/core';
32
import uuid from 'uuid/v4';
43
import * as utils from './utils/utils';
54
import fusionChartsOptions from './utils/options';
@@ -21,18 +20,18 @@ class ReactFC extends React.Component {
2120

2221
this.containerId = uuid();
2322
this.oldOptions = null;
24-
this.FusionCharts = props.fcLibrary || ReactFC.fusionChartsCore;
23+
this.FusionCharts =
24+
props.fcLibrary || ReactFC.fusionChartsCore || window.FusionCharts;
2525
}
2626

2727
componentDidMount() {
2828
this.renderChart();
2929
}
3030

31-
componentWillReceiveProps(nextProps) {
32-
if (!this.oldOptions) {
33-
return;
31+
componentDidUpdate(prevProps) {
32+
if (prevProps !== this.props) {
33+
this.detectChanges(this.props);
3434
}
35-
this.detectChanges(nextProps);
3635
}
3736

3837
componentWillUnmount() {

0 commit comments

Comments
 (0)