Skip to content

Commit f88e8a7

Browse files
committed
echarts removed unused code
1 parent eb882b0 commit f88e8a7

File tree

1 file changed

+4
-113
lines changed

1 file changed

+4
-113
lines changed

client/packages/lowcoder-comps/src/comps/eChartsComp/echartsComp.tsx

Lines changed: 4 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,11 @@ EChartsTmpComp = withViewFn(EChartsTmpComp, (comp) => {
6363
lng: comp.children.mapCenterLng.getView(),
6464
lat: comp.children.mapCenterLat.getView(),
6565
}
66-
const mapZoomlevel = comp.children.mapZoomLevel.getView();
6766
const onUIEvent = comp.children.onUIEvent.getView();
68-
const onMapEvent = comp.children.onMapEvent.getView();
6967
const onEvent = comp.children.onEvent.getView();
7068

7169
const echartsCompRef = useRef<ReactECharts | null>();
7270
const [chartSize, setChartSize] = useState<ChartSize>();
73-
const [mapScriptLoaded, setMapScriptLoaded] = useState(false);
7471
const firstResize = useRef(true);
7572
const theme = useContext(ThemeContext);
7673
const defaultChartTheme = {
@@ -95,9 +92,6 @@ EChartsTmpComp = withViewFn(EChartsTmpComp, (comp) => {
9592
}
9693

9794
useEffect(() => {
98-
// click events for JSON/Map mode
99-
if (mode === 'ui') return;
100-
10195
const echartsCompInstance = echartsCompRef?.current?.getEchartsInstance();
10296
if (!echartsCompInstance) {
10397
return _.noop;
@@ -119,12 +113,9 @@ EChartsTmpComp = withViewFn(EChartsTmpComp, (comp) => {
119113
echartsCompInstance?.off("click");
120114
document.removeEventListener('clickEvent', clickEventCallback)
121115
};
122-
}, [mode, mapScriptLoaded]);
116+
}, []);
123117

124118
useEffect(() => {
125-
// click events for UI mode
126-
if(mode !== 'ui') return;
127-
128119
// bind events
129120
const echartsCompInstance = echartsCompRef?.current?.getEchartsInstance();
130121
if (!echartsCompInstance) {
@@ -161,7 +152,7 @@ EChartsTmpComp = withViewFn(EChartsTmpComp, (comp) => {
161152
echartsCompInstance?.off("selectchanged");
162153
document.removeEventListener('clickEvent', clickEventCallback)
163154
};
164-
}, [mode, onUIEvent]);
155+
}, [onUIEvent]);
165156

166157
const echartsConfigChildren = _.omit(comp.children, echartsConfigOmitChildren);
167158
const option = useMemo(() => {
@@ -171,55 +162,10 @@ EChartsTmpComp = withViewFn(EChartsTmpComp, (comp) => {
171162
);
172163
}, [chartSize, ...Object.values(echartsConfigChildren)]);
173164

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-
195165
useEffect(() => {
196-
if( mode !== 'map') {
197-
comp.children.mapInstance.dispatch(changeValueAction(null, false))
198-
return;
199-
}
200-
166+
comp.children.mapInstance.dispatch(changeValueAction(null, false))
201167
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-
useEffect(() => {
220-
if(mode !== 'map') return;
221-
onMapEvent('zoomLevelChange');
222-
}, [mode, mapZoomlevel])
168+
}, [option])
223169

224170
return (
225171
<ReactResizeDetector
@@ -375,61 +321,6 @@ let EChartsComp = withExposingConfigs(EChartsTmpComp, [
375321
new NameConfig("title", trans("chart.titleDesc")),
376322
]);
377323

378-
EChartsComp = withMethodExposing(EChartsComp, [
379-
{
380-
method: {
381-
name: "getMapInstance",
382-
},
383-
execute: (comp) => {
384-
return new Promise(resolve => {
385-
let intervalCount = 0;
386-
const mapInstanceInterval = setInterval(() => {
387-
const instance = comp.children.mapInstance.getView();
388-
const mapInstance = instance?.getModel()?.getComponent("gmap")?.getGoogleMap()
389-
if(mapInstance || intervalCount === 10) {
390-
clearInterval(mapInstanceInterval)
391-
resolve(mapInstance)
392-
}
393-
intervalCount++;
394-
}, 1000);
395-
})
396-
}
397-
},
398-
{
399-
method: {
400-
name: "getMapZoomLevel",
401-
},
402-
execute: (comp) => {
403-
return comp.children.mapZoomLevel.getView();
404-
}
405-
},
406-
{
407-
method: {
408-
name: "getMapCenterPosition",
409-
},
410-
execute: (comp) => {
411-
return Promise.resolve({
412-
lng: comp.children.mapCenterLng.getView(),
413-
lat: comp.children.mapCenterLat.getView(),
414-
});
415-
}
416-
},
417-
{
418-
method: {
419-
name: "onClick",
420-
params: [
421-
{
422-
name: "callback",
423-
type: "function",
424-
},
425-
],
426-
},
427-
execute: (comp, params) => {
428-
clickEventCallback = params[0];
429-
document.addEventListener('clickEvent', clickEventCallback);
430-
}
431-
},
432-
])
433324

434325
export const EChartsCompWithDefault = withDefault(EChartsComp, {
435326
xAxisKey: "date",

0 commit comments

Comments
 (0)