@@ -6,8 +6,8 @@ import fusionChartsOptions from './utils/options';
6
6
7
7
class ReactFC extends React . Component {
8
8
static fcRoot ( core , ...modules ) {
9
- modules . forEach ( ( m ) => {
10
- if ( m . getName || m . name ) {
9
+ modules . forEach ( m => {
10
+ if ( ( m . getName && m . getType ) || ( m . name && m . type ) ) {
11
11
core . addDep ( m ) ;
12
12
} else {
13
13
m ( core ) ;
@@ -21,15 +21,18 @@ class ReactFC extends React.Component {
21
21
22
22
this . containerId = uuid ( ) ;
23
23
this . oldOptions = null ;
24
- this . FusionCharts = props . fcLibrary || ReactFC . fusionChartsCore || FusionCharts ;
24
+ this . FusionCharts =
25
+ props . fcLibrary || ReactFC . fusionChartsCore || FusionCharts ;
25
26
}
26
27
27
28
componentDidMount ( ) {
28
29
this . renderChart ( ) ;
29
30
}
30
31
31
32
componentWillReceiveProps ( nextProps ) {
32
- if ( ! this . oldOptions ) { return ; }
33
+ if ( ! this . oldOptions ) {
34
+ return ;
35
+ }
33
36
this . detectChanges ( nextProps ) ;
34
37
}
35
38
@@ -46,17 +49,19 @@ class ReactFC extends React.Component {
46
49
'type' ,
47
50
'dataFormat' ,
48
51
'dataSource' ,
49
- 'events' ,
52
+ 'events'
50
53
] ;
51
54
52
55
this . checkAndUpdateChartDimensions ( currentOptions , oldOptions ) ;
53
56
this . checkAndUpdateChartType ( currentOptions , oldOptions ) ;
54
57
this . checkAndUpdateChartData ( currentOptions , oldOptions ) ;
55
58
this . checkAndUpdateEvents ( currentOptions , oldOptions ) ;
56
59
this . checkAndUpdateRestOptions (
57
- fusionChartsOptions . filter ( option => optionsUpdatedNatively . indexOf ( option ) === - 1 ) ,
60
+ fusionChartsOptions . filter (
61
+ option => optionsUpdatedNatively . indexOf ( option ) === - 1
62
+ ) ,
58
63
currentOptions ,
59
- oldOptions ,
64
+ oldOptions
60
65
) ;
61
66
62
67
this . oldOptions = currentOptions ;
@@ -68,18 +73,21 @@ class ReactFC extends React.Component {
68
73
const oldWidth = oldOptions . width ;
69
74
const oldHeight = oldOptions . height ;
70
75
71
- if ( String ( currWidth ) !== String ( oldWidth ) || String ( currHeight ) !== String ( oldHeight ) ) {
76
+ if (
77
+ String ( currWidth ) !== String ( oldWidth ) ||
78
+ String ( currHeight ) !== String ( oldHeight )
79
+ ) {
72
80
if ( ! utils . isUndefined ( currWidth ) && ! utils . isUndefined ( currHeight ) ) {
73
81
this . chartObj . resizeTo ( currWidth , currHeight ) ;
74
82
} else {
75
83
if ( ! utils . isUndefined ( currWidth ) ) {
76
84
this . chartObj . resizeTo ( {
77
- w : currWidth ,
85
+ w : currWidth
78
86
} ) ;
79
87
}
80
88
if ( ! utils . isUndefined ( currHeight ) ) {
81
89
this . chartObj . resizeTo ( {
82
- h : currHeight ,
90
+ h : currHeight
83
91
} ) ;
84
92
}
85
93
}
@@ -103,9 +111,15 @@ class ReactFC extends React.Component {
103
111
const oldDataFormat = oldOptions . dataFormat ;
104
112
const oldData = oldOptions . dataSource ;
105
113
106
- if ( String ( currDataFormat ) . toLowerCase ( ) !== String ( oldDataFormat ) . toLowerCase ( ) ) {
114
+ if (
115
+ String ( currDataFormat ) . toLowerCase ( ) !==
116
+ String ( oldDataFormat ) . toLowerCase ( )
117
+ ) {
107
118
if ( ! utils . isUndefined ( currDataFormat ) && ! utils . isUndefined ( currData ) ) {
108
- this . chartObj . setChartData ( currData , String ( currDataFormat ) . toLowerCase ( ) ) ;
119
+ this . chartObj . setChartData (
120
+ currData ,
121
+ String ( currDataFormat ) . toLowerCase ( )
122
+ ) ;
109
123
// If the chart dataFormat is changed then
110
124
// animate the chart to show the changes
111
125
this . chartObj . render ( ) ;
@@ -116,7 +130,7 @@ class ReactFC extends React.Component {
116
130
currData ,
117
131
// When dataFormat is not given, but data is changed,
118
132
// then use 'json' as default dataFormat
119
- currDataFormat ? String ( currDataFormat ) . toLowerCase ( ) : 'json' ,
133
+ currDataFormat ? String ( currDataFormat ) . toLowerCase ( ) : 'json'
120
134
) ;
121
135
}
122
136
}
@@ -138,15 +152,17 @@ class ReactFC extends React.Component {
138
152
if ( this . detectChartEventsChange ( currEvents , oldEvents ) ) {
139
153
if ( ! utils . isUndefined ( currEvents ) ) {
140
154
temp1 = Object . assign ( { } , currEvents ) ;
141
- temp2 = utils . isUndefined ( oldEvents ) ? { } : Object . assign ( { } , oldEvents ) ;
142
- Object . keys ( temp2 ) . forEach ( ( eventName ) => {
155
+ temp2 = utils . isUndefined ( oldEvents )
156
+ ? { }
157
+ : Object . assign ( { } , oldEvents ) ;
158
+ Object . keys ( temp2 ) . forEach ( eventName => {
143
159
if ( temp2 [ eventName ] === temp1 [ eventName ] ) {
144
160
temp1 [ eventName ] = undefined ;
145
161
} else {
146
162
this . chartObj . removeEventListener ( eventName , temp2 [ eventName ] ) ;
147
163
}
148
164
} ) ;
149
- Object . keys ( temp1 ) . forEach ( ( eventName ) => {
165
+ Object . keys ( temp1 ) . forEach ( eventName => {
150
166
if ( temp1 [ eventName ] ) {
151
167
this . chartObj . addEventListener ( eventName , temp1 [ eventName ] ) ;
152
168
}
@@ -157,13 +173,15 @@ class ReactFC extends React.Component {
157
173
158
174
detectChartEventsChange ( currEvents , oldEvents ) {
159
175
if ( utils . isObject ( currEvents ) && utils . isObject ( oldEvents ) ) {
160
- return ! ( this . isSameChartEvents ( currEvents , oldEvents ) ) ;
176
+ return ! this . isSameChartEvents ( currEvents , oldEvents ) ;
161
177
}
162
178
return ! ( currEvents === oldEvents ) ;
163
179
}
164
180
165
181
isSameChartEvents ( currEvents , oldEvents ) {
166
- if ( Object . keys ( currEvents ) . length !== Object . keys ( oldEvents ) . length ) { return false ; }
182
+ if ( Object . keys ( currEvents ) . length !== Object . keys ( oldEvents ) . length ) {
183
+ return false ;
184
+ }
167
185
const currEventNames = Object . keys ( currEvents ) ;
168
186
for ( let i = 0 ; i < currEventNames . length ; ++ i ) {
169
187
const evName = currEventNames [ i ] ;
@@ -177,13 +195,16 @@ class ReactFC extends React.Component {
177
195
checkAndUpdateRestOptions ( restOptions , currentOptions , oldOptions ) {
178
196
let optionsUpdated = false ;
179
197
180
- restOptions . forEach ( ( optionName ) => {
198
+ restOptions . forEach ( optionName => {
181
199
const currValue = currentOptions [ optionName ] ;
182
200
const oldValue = oldOptions [ optionName ] ;
183
201
184
202
if ( ! this . isSameOptionValue ( currValue , oldValue ) ) {
185
203
if ( ! utils . isUndefined ( currValue ) ) {
186
- if ( this . chartObj . options && this . chartObj . options . hasOwnProperty ( optionName ) ) {
204
+ if (
205
+ this . chartObj . options &&
206
+ this . chartObj . options . hasOwnProperty ( optionName )
207
+ ) {
187
208
this . chartObj . options [ optionName ] = currValue ;
188
209
optionsUpdated = true ;
189
210
}
@@ -203,14 +224,13 @@ class ReactFC extends React.Component {
203
224
return String ( currValue ) === String ( oldValue ) ;
204
225
}
205
226
206
-
207
227
renderChart ( ) {
208
228
const currentOptions = this . resolveChartOptions ( this . props ) ;
209
229
const events = { } ;
210
230
211
231
currentOptions . renderAt = this . containerId ;
212
232
213
- Object . keys ( this . props ) . forEach ( ( value ) => {
233
+ Object . keys ( this . props ) . forEach ( value => {
214
234
const event = value . match ( / ^ f c E v e n t - .* / i) ;
215
235
if ( event && typeof this . props [ value ] === 'function' ) {
216
236
const eventName = value . replace ( / ^ f c E v e n t - / i, '' ) ;
@@ -256,9 +276,7 @@ class ReactFC extends React.Component {
256
276
}
257
277
258
278
render ( ) {
259
- return (
260
- < div className = { this . props . className } id = { this . containerId } />
261
- ) ;
279
+ return < div className = { this . props . className } id = { this . containerId } /> ;
262
280
}
263
281
}
264
282
0 commit comments