You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2022/01/07 12:57:40 UTC
[echarts] branch enhance-map created (now 2c7692d)
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a change to branch enhance-map
in repository https://gitbox.apache.org/repos/asf/echarts.git.
at 2c7692d refact(map): remove map dependency in core
This branch includes the following new commits:
new 2c7692d refact(map): remove map dependency in core
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[echarts] 01/01: refact(map): remove map dependency in core
Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch enhance-map
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 2c7692d6b7c4075d343b9a8ab15bc5c8a5fd9348
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Jan 7 20:56:39 2022 +0800
refact(map): remove map dependency in core
---
src/component/geo/install.ts | 15 +++++++++++++++
src/coord/geo/Region.ts | 1 -
src/core/echarts.ts | 16 +++++++++------
src/core/impl.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++
src/extension.ts | 3 +++
5 files changed, 74 insertions(+), 7 deletions(-)
diff --git a/src/component/geo/install.ts b/src/component/geo/install.ts
index 0db971a..ad9234e 100644
--- a/src/component/geo/install.ts
+++ b/src/component/geo/install.ts
@@ -26,6 +26,16 @@ import GlobalModel from '../../model/Global';
import { updateCenterAndZoom, RoamPaylod } from '../../action/roamHelper';
import MapSeries from '../../chart/map/MapSeries';
import GeoView from './GeoView';
+import geoSourceManager from '../../coord/geo/geoSourceManager';
+
+type RegisterMapParams = Parameters<typeof geoSourceManager.registerMap>;
+function registerMap(
+ mapName: RegisterMapParams[0],
+ geoJson: RegisterMapParams[1],
+ specialAreas?: RegisterMapParams[2]
+) {
+ geoSourceManager.registerMap(mapName, geoJson, specialAreas);
+}
export function install(registers: EChartsExtensionInstallRegisters) {
@@ -34,6 +44,11 @@ export function install(registers: EChartsExtensionInstallRegisters) {
registers.registerComponentModel(GeoModel);
registers.registerComponentView(GeoView);
+ registers.registerImpl('registerMap', registerMap);
+ registers.registerImpl('getMap', (mapName: string) => {
+ geoSourceManager.getMapForUser(mapName);
+ });
+
function makeAction(
method: 'toggleSelected' | 'select' | 'unSelect',
diff --git a/src/coord/geo/Region.ts b/src/coord/geo/Region.ts
index 2e5248e..185698b 100644
--- a/src/coord/geo/Region.ts
+++ b/src/coord/geo/Region.ts
@@ -47,7 +47,6 @@ export class Region {
getCenter(): number[] {
return;
}
-
}
diff --git a/src/core/echarts.ts b/src/core/echarts.ts
index bb1dd88..a0f53b0 100644
--- a/src/core/echarts.ts
+++ b/src/core/echarts.ts
@@ -122,7 +122,6 @@ import { findEventDispatcher } from '../util/event';
import decal from '../visual/decal';
import CanvasPainter from 'zrender/src/canvas/Painter';
import SVGPainter from 'zrender/src/svg/Painter';
-import geoSourceManager from '../coord/geo/geoSourceManager';
import lifecycle, {
LifecycleEvents,
UpdateLifecycleTransitionItem,
@@ -130,6 +129,8 @@ import lifecycle, {
UpdateLifecycleTransitionOpt
} from './lifecycle';
import { platformApi, setPlatformAPI } from 'zrender/src/core/platform';
+import { getImpl } from './impl';
+import type geoSourceManager from '../coord/geo/geoSourceManager';
declare let global: any;
@@ -2936,20 +2937,23 @@ export function setCanvasCreator(creator: () => HTMLCanvasElement): void {
});
}
+type RegisterMapParams = Parameters<typeof geoSourceManager.registerMap>;
/**
* The parameters and usage: see `geoSourceManager.registerMap`.
* Compatible with previous `echarts.registerMap`.
*/
export function registerMap(
- mapName: Parameters<typeof geoSourceManager.registerMap>[0],
- geoJson: Parameters<typeof geoSourceManager.registerMap>[1],
- specialAreas?: Parameters<typeof geoSourceManager.registerMap>[2]
+ mapName: RegisterMapParams[0],
+ geoJson: RegisterMapParams[1],
+ specialAreas?: RegisterMapParams[2]
): void {
- geoSourceManager.registerMap(mapName, geoJson, specialAreas);
+ const registerMap = getImpl('registerMap');
+ registerMap && registerMap(mapName, geoJson, specialAreas);
}
export function getMap(mapName: string) {
- return geoSourceManager.getMapForUser(mapName);
+ const getMap = getImpl('getMap');
+ return getMap && getMap(mapName);
}
export const registerTransform = registerExternalTransform;
diff --git a/src/core/impl.ts b/src/core/impl.ts
new file mode 100644
index 0000000..4fecd09
--- /dev/null
+++ b/src/core/impl.ts
@@ -0,0 +1,46 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+import { error } from '../util/log';
+
+
+// Implementation of exported APIs. For example registerMap, getMap.
+// The implentations will be registered when installing the component.
+// Avoid these code being bundled to the core module.
+
+const implsStore: Record<string, any> = {};
+
+// TODO Type
+export function registerImpl(name: string, impl: any) {
+ if (__DEV__) {
+ if (implsStore[name]) {
+ error(`Already has an implementation of ${name}.`);
+ }
+ }
+ implsStore[name] = impl;
+}
+
+export function getImpl(name: string) {
+ if (__DEV__) {
+ if (!implsStore[name]) {
+ error(`Implementation of ${name} doesn't exists.`);
+ }
+ }
+ return implsStore[name];
+}
\ No newline at end of file
diff --git a/src/extension.ts b/src/extension.ts
index f781f51..a04ef54 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -39,6 +39,7 @@ import SeriesModel from './model/Series';
import { isFunction, indexOf, isArray, each } from 'zrender/src/core/util';
import { Constructor } from './util/clazz';
import { SubTypeDefaulter } from './util/component';
+import { registerImpl } from './core/impl';
import { registerPainter } from 'zrender/src/zrender';
const extensions: (EChartsExtensionInstaller | EChartsExtension)[] = [];
@@ -56,6 +57,8 @@ const extensionRegisters = {
registerTransform,
registerLoading,
registerMap,
+ registerImpl,
+
PRIORITY,
ComponentModel,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org