@@ -16,10 +16,7 @@ import {
16
16
childrenToProps ,
17
17
depsConfig ,
18
18
genRandomKey ,
19
- JSONObject ,
20
- JSONValue ,
21
19
NameConfig ,
22
- ToViewReturn ,
23
20
UICompBuilder ,
24
21
withDefault ,
25
22
withExposingConfigs ,
@@ -36,7 +33,6 @@ import {
36
33
echartsConfigOmitChildren ,
37
34
getEchartsConfig ,
38
35
getSelectedPoints ,
39
- loadGoogleMapsScript ,
40
36
} from "comps/chartComp/chartUtils" ;
41
37
import 'echarts-extension-gmap' ;
42
38
import log from "loglevel" ;
@@ -57,20 +53,12 @@ let ChartTmpComp = (function () {
57
53
} ) ( ) ;
58
54
59
55
ChartTmpComp = withViewFn ( ChartTmpComp , ( comp ) => {
60
- const apiKey = comp . children . mapApiKey . getView ( ) ;
61
56
const mode = comp . children . mode . getView ( ) ;
62
- const mapCenterPosition = {
63
- lng : comp . children . mapCenterLng . getView ( ) ,
64
- lat : comp . children . mapCenterLat . getView ( ) ,
65
- }
66
- const mapZoomlevel = comp . children . mapZoomLevel . getView ( ) ;
67
57
const onUIEvent = comp . children . onUIEvent . getView ( ) ;
68
- const onMapEvent = comp . children . onMapEvent . getView ( ) ;
69
58
const onEvent = comp . children . onEvent . getView ( ) ;
70
59
71
60
const echartsCompRef = useRef < ReactECharts | null > ( ) ;
72
61
const [ chartSize , setChartSize ] = useState < ChartSize > ( ) ;
73
- const [ mapScriptLoaded , setMapScriptLoaded ] = useState ( false ) ;
74
62
const firstResize = useRef ( true ) ;
75
63
const theme = useContext ( ThemeContext ) ;
76
64
const defaultChartTheme = {
@@ -95,45 +83,13 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
95
83
}
96
84
97
85
useEffect ( ( ) => {
98
- // click events for JSON/Map mode
99
- if ( mode === 'ui' ) return ;
100
-
101
- const echartsCompInstance = echartsCompRef ?. current ?. getEchartsInstance ( ) ;
102
- if ( ! echartsCompInstance ) {
103
- return _ . noop ;
104
- }
105
- echartsCompInstance ?. on ( "click" , ( param : any ) => {
106
- document . dispatchEvent ( new CustomEvent ( "clickEvent" , {
107
- bubbles : true ,
108
- detail : {
109
- action : 'click' ,
110
- data : param . data ,
111
- }
112
- } ) ) ;
113
- triggerClickEvent (
114
- comp . dispatch ,
115
- changeChildAction ( "lastInteractionData" , param . data , false )
116
- ) ;
117
- } ) ;
118
- return ( ) => {
119
- echartsCompInstance ?. off ( "click" ) ;
120
- document . removeEventListener ( 'clickEvent' , clickEventCallback )
121
- } ;
122
- } , [ mode , mapScriptLoaded ] ) ;
123
-
124
- useEffect ( ( ) => {
125
- // click events for UI mode
126
- if ( mode !== 'ui' ) return ;
127
-
128
86
// bind events
129
87
const echartsCompInstance = echartsCompRef ?. current ?. getEchartsInstance ( ) ;
130
88
if ( ! echartsCompInstance ) {
131
89
return _ . noop ;
132
90
}
133
91
echartsCompInstance ?. on ( "selectchanged" , ( param : any ) => {
134
92
const option : any = echartsCompInstance ?. getOption ( ) ;
135
- //log.log("chart select change", param);
136
- // trigger click event listener
137
93
138
94
document . dispatchEvent ( new CustomEvent ( "clickEvent" , {
139
95
bubbles : true ,
@@ -161,7 +117,7 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
161
117
echartsCompInstance ?. off ( "selectchanged" ) ;
162
118
document . removeEventListener ( 'clickEvent' , clickEventCallback )
163
119
} ;
164
- } , [ mode , onUIEvent ] ) ;
120
+ } , [ onUIEvent ] ) ;
165
121
166
122
const echartsConfigChildren = _ . omit ( comp . children , echartsConfigOmitChildren ) ;
167
123
const option = useMemo ( ( ) => {
@@ -171,55 +127,9 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
171
127
) ;
172
128
} , [ chartSize , ...Object . values ( echartsConfigChildren ) ] ) ;
173
129
174
- const isMapScriptLoaded = useMemo ( ( ) => {
175
- return mapScriptLoaded || window ?. google ;
176
- } , [ mapScriptLoaded ] )
177
-
178
- const loadGoogleMapData = ( ) => {
179
- const echartsCompInstance = echartsCompRef ?. current ?. getEchartsInstance ( ) ;
180
- if ( ! echartsCompInstance ) {
181
- return _ . noop ;
182
- }
183
-
184
- comp . children . mapInstance . dispatch ( changeValueAction ( echartsCompInstance ) )
185
- onMapEvent ( 'mapReady' )
186
- }
187
-
188
- const handleOnMapScriptLoad = ( ) => {
189
- setMapScriptLoaded ( true ) ;
190
- setTimeout ( ( ) => {
191
- loadGoogleMapData ( ) ;
192
- } )
193
- }
194
-
195
- useEffect ( ( ) => {
196
- if ( mode !== 'map' ) {
197
- comp . children . mapInstance . dispatch ( changeValueAction ( null , false ) )
198
- return ;
199
- }
200
-
201
- if ( comp . children . mapInstance . value ) return ;
202
-
203
- const gMapScript = loadGoogleMapsScript ( apiKey ) ;
204
- if ( isMapScriptLoaded ) {
205
- handleOnMapScriptLoad ( ) ;
206
- return ;
207
- }
208
- gMapScript . addEventListener ( 'load' , handleOnMapScriptLoad ) ;
209
- return ( ) => {
210
- gMapScript . removeEventListener ( 'load' , handleOnMapScriptLoad ) ;
211
- }
212
- } , [ mode , apiKey , option ] )
213
-
214
- useEffect ( ( ) => {
215
- if ( mode !== 'map' ) return ;
216
- onMapEvent ( 'centerPositionChange' ) ;
217
- } , [ mode , mapCenterPosition . lat , mapCenterPosition . lng ] )
218
-
219
130
useEffect ( ( ) => {
220
- if ( mode !== 'map' ) return ;
221
- onMapEvent ( 'zoomLevelChange' ) ;
222
- } , [ mode , mapZoomlevel ] )
131
+ comp . children . mapInstance . dispatch ( changeValueAction ( null , false ) )
132
+ } , [ option ] )
223
133
224
134
return (
225
135
< ReactResizeDetector
@@ -235,18 +145,16 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
235
145
}
236
146
} }
237
147
>
238
- { ( mode !== 'map' || ( mode === 'map' && isMapScriptLoaded ) ) && (
239
- < ReactECharts
148
+ < ReactECharts
240
149
ref = { ( e ) => ( echartsCompRef . current = e ) }
241
150
style = { { height : "100%" } }
242
151
notMerge
243
152
lazyUpdate
244
153
opts = { { locale : getEchartsLocale ( ) } }
245
154
option = { option }
246
- theme = { mode !== 'map' ? themeConfig : undefined }
155
+ theme = { themeConfig }
247
156
mode = { mode }
248
157
/>
249
- ) }
250
158
</ ReactResizeDetector >
251
159
) ;
252
160
} ) ;
@@ -365,74 +273,11 @@ let ChartComp = withExposingConfigs(ChartTmpComp, [
365
273
name : "data" ,
366
274
desc : trans ( "chart.dataDesc" ) ,
367
275
depKeys : [ "data" , "mode" ] ,
368
- func : ( input ) => {
369
- if ( input . mode === "ui" ) {
370
- return input . data ;
371
- } else {
372
- // no data in json mode
373
- return [ ] ;
374
- }
375
- } ,
276
+ func : ( input ) => input . data ,
376
277
} ) ,
377
278
new NameConfig ( "title" , trans ( "chart.titleDesc" ) ) ,
378
279
] ) ;
379
280
380
- ChartComp = withMethodExposing ( ChartComp , [
381
- {
382
- method : {
383
- name : "getMapInstance" ,
384
- } ,
385
- execute : ( comp ) => {
386
- return new Promise ( resolve => {
387
- let intervalCount = 0 ;
388
- const mapInstanceInterval = setInterval ( ( ) => {
389
- const instance = comp . children . mapInstance . getView ( ) ;
390
- const mapInstance = instance ?. getModel ( ) ?. getComponent ( "gmap" ) ?. getGoogleMap ( )
391
- if ( mapInstance || intervalCount === 10 ) {
392
- clearInterval ( mapInstanceInterval )
393
- resolve ( mapInstance )
394
- }
395
- intervalCount ++ ;
396
- } , 1000 ) ;
397
- } )
398
- }
399
- } ,
400
- {
401
- method : {
402
- name : "getMapZoomLevel" ,
403
- } ,
404
- execute : ( comp ) => {
405
- return comp . children . mapZoomLevel . getView ( ) ;
406
- }
407
- } ,
408
- {
409
- method : {
410
- name : "getMapCenterPosition" ,
411
- } ,
412
- execute : ( comp ) => {
413
- return Promise . resolve ( {
414
- lng : comp . children . mapCenterLng . getView ( ) ,
415
- lat : comp . children . mapCenterLat . getView ( ) ,
416
- } ) ;
417
- }
418
- } ,
419
- {
420
- method : {
421
- name : "onClick" ,
422
- params : [
423
- {
424
- name : "callback" ,
425
- type : "function" ,
426
- } ,
427
- ] ,
428
- } ,
429
- execute : ( comp , params ) => {
430
- clickEventCallback = params [ 0 ] ;
431
- document . addEventListener ( 'clickEvent' , clickEventCallback ) ;
432
- }
433
- } ,
434
- ] )
435
-
436
281
export const ChartCompWithDefault = withDefault ( ChartComp , {
437
282
xAxisKey : "date" ,
438
283
series : [
0 commit comments