@@ -6,8 +6,8 @@ import fusionChartsOptions from './utils/options';
66
77class ReactFC extends React . Component {
88 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 ) ) {
1111 core . addDep ( m ) ;
1212 } else {
1313 m ( core ) ;
@@ -21,15 +21,18 @@ class ReactFC extends React.Component {
2121
2222 this . containerId = uuid ( ) ;
2323 this . oldOptions = null ;
24- this . FusionCharts = props . fcLibrary || ReactFC . fusionChartsCore || FusionCharts ;
24+ this . FusionCharts =
25+ props . fcLibrary || ReactFC . fusionChartsCore || FusionCharts ;
2526 }
2627
2728 componentDidMount ( ) {
2829 this . renderChart ( ) ;
2930 }
3031
3132 componentWillReceiveProps ( nextProps ) {
32- if ( ! this . oldOptions ) { return ; }
33+ if ( ! this . oldOptions ) {
34+ return ;
35+ }
3336 this . detectChanges ( nextProps ) ;
3437 }
3538
@@ -46,17 +49,19 @@ class ReactFC extends React.Component {
4649 'type' ,
4750 'dataFormat' ,
4851 'dataSource' ,
49- 'events' ,
52+ 'events'
5053 ] ;
5154
5255 this . checkAndUpdateChartDimensions ( currentOptions , oldOptions ) ;
5356 this . checkAndUpdateChartType ( currentOptions , oldOptions ) ;
5457 this . checkAndUpdateChartData ( currentOptions , oldOptions ) ;
5558 this . checkAndUpdateEvents ( currentOptions , oldOptions ) ;
5659 this . checkAndUpdateRestOptions (
57- fusionChartsOptions . filter ( option => optionsUpdatedNatively . indexOf ( option ) === - 1 ) ,
60+ fusionChartsOptions . filter (
61+ option => optionsUpdatedNatively . indexOf ( option ) === - 1
62+ ) ,
5863 currentOptions ,
59- oldOptions ,
64+ oldOptions
6065 ) ;
6166
6267 this . oldOptions = currentOptions ;
@@ -68,18 +73,21 @@ class ReactFC extends React.Component {
6873 const oldWidth = oldOptions . width ;
6974 const oldHeight = oldOptions . height ;
7075
71- if ( String ( currWidth ) !== String ( oldWidth ) || String ( currHeight ) !== String ( oldHeight ) ) {
76+ if (
77+ String ( currWidth ) !== String ( oldWidth ) ||
78+ String ( currHeight ) !== String ( oldHeight )
79+ ) {
7280 if ( ! utils . isUndefined ( currWidth ) && ! utils . isUndefined ( currHeight ) ) {
7381 this . chartObj . resizeTo ( currWidth , currHeight ) ;
7482 } else {
7583 if ( ! utils . isUndefined ( currWidth ) ) {
7684 this . chartObj . resizeTo ( {
77- w : currWidth ,
85+ w : currWidth
7886 } ) ;
7987 }
8088 if ( ! utils . isUndefined ( currHeight ) ) {
8189 this . chartObj . resizeTo ( {
82- h : currHeight ,
90+ h : currHeight
8391 } ) ;
8492 }
8593 }
@@ -103,9 +111,15 @@ class ReactFC extends React.Component {
103111 const oldDataFormat = oldOptions . dataFormat ;
104112 const oldData = oldOptions . dataSource ;
105113
106- if ( String ( currDataFormat ) . toLowerCase ( ) !== String ( oldDataFormat ) . toLowerCase ( ) ) {
114+ if (
115+ String ( currDataFormat ) . toLowerCase ( ) !==
116+ String ( oldDataFormat ) . toLowerCase ( )
117+ ) {
107118 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+ ) ;
109123 // If the chart dataFormat is changed then
110124 // animate the chart to show the changes
111125 this . chartObj . render ( ) ;
@@ -116,7 +130,7 @@ class ReactFC extends React.Component {
116130 currData ,
117131 // When dataFormat is not given, but data is changed,
118132 // then use 'json' as default dataFormat
119- currDataFormat ? String ( currDataFormat ) . toLowerCase ( ) : 'json' ,
133+ currDataFormat ? String ( currDataFormat ) . toLowerCase ( ) : 'json'
120134 ) ;
121135 }
122136 }
@@ -138,15 +152,17 @@ class ReactFC extends React.Component {
138152 if ( this . detectChartEventsChange ( currEvents , oldEvents ) ) {
139153 if ( ! utils . isUndefined ( currEvents ) ) {
140154 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 => {
143159 if ( temp2 [ eventName ] === temp1 [ eventName ] ) {
144160 temp1 [ eventName ] = undefined ;
145161 } else {
146162 this . chartObj . removeEventListener ( eventName , temp2 [ eventName ] ) ;
147163 }
148164 } ) ;
149- Object . keys ( temp1 ) . forEach ( ( eventName ) => {
165+ Object . keys ( temp1 ) . forEach ( eventName => {
150166 if ( temp1 [ eventName ] ) {
151167 this . chartObj . addEventListener ( eventName , temp1 [ eventName ] ) ;
152168 }
@@ -157,13 +173,15 @@ class ReactFC extends React.Component {
157173
158174 detectChartEventsChange ( currEvents , oldEvents ) {
159175 if ( utils . isObject ( currEvents ) && utils . isObject ( oldEvents ) ) {
160- return ! ( this . isSameChartEvents ( currEvents , oldEvents ) ) ;
176+ return ! this . isSameChartEvents ( currEvents , oldEvents ) ;
161177 }
162178 return ! ( currEvents === oldEvents ) ;
163179 }
164180
165181 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+ }
167185 const currEventNames = Object . keys ( currEvents ) ;
168186 for ( let i = 0 ; i < currEventNames . length ; ++ i ) {
169187 const evName = currEventNames [ i ] ;
@@ -177,13 +195,16 @@ class ReactFC extends React.Component {
177195 checkAndUpdateRestOptions ( restOptions , currentOptions , oldOptions ) {
178196 let optionsUpdated = false ;
179197
180- restOptions . forEach ( ( optionName ) => {
198+ restOptions . forEach ( optionName => {
181199 const currValue = currentOptions [ optionName ] ;
182200 const oldValue = oldOptions [ optionName ] ;
183201
184202 if ( ! this . isSameOptionValue ( currValue , oldValue ) ) {
185203 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+ ) {
187208 this . chartObj . options [ optionName ] = currValue ;
188209 optionsUpdated = true ;
189210 }
@@ -203,14 +224,13 @@ class ReactFC extends React.Component {
203224 return String ( currValue ) === String ( oldValue ) ;
204225 }
205226
206-
207227 renderChart ( ) {
208228 const currentOptions = this . resolveChartOptions ( this . props ) ;
209229 const events = { } ;
210230
211231 currentOptions . renderAt = this . containerId ;
212232
213- Object . keys ( this . props ) . forEach ( ( value ) => {
233+ Object . keys ( this . props ) . forEach ( value => {
214234 const event = value . match ( / ^ f c E v e n t - .* / i) ;
215235 if ( event && typeof this . props [ value ] === 'function' ) {
216236 const eventName = value . replace ( / ^ f c E v e n t - / i, '' ) ;
@@ -256,9 +276,7 @@ class ReactFC extends React.Component {
256276 }
257277
258278 render ( ) {
259- return (
260- < div className = { this . props . className } id = { this . containerId } />
261- ) ;
279+ return < div className = { this . props . className } id = { this . containerId } /> ;
262280 }
263281}
264282
0 commit comments