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 2021/04/07 11:39:11 UTC

[echarts] branch fix-map-label created (now 669209d)

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a change to branch fix-map-label
in repository https://gitbox.apache.org/repos/asf/echarts.git.


      at 669209d  fix(map): fix label layout may not update in map

This branch includes the following new commits:

     new 669209d  fix(map): fix label layout may not update in map

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: fix(map): fix label layout may not update in map

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch fix-map-label
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 669209d903a67644d7bc6765371ad7e974188f8a
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Apr 7 19:37:48 2021 +0800

    fix(map): fix label layout may not update in map
---
 src/chart/map/MapView.ts        |  8 ------
 src/component/helper/MapDraw.ts | 59 +++++++++++++++++------------------------
 src/util/symbol.ts              |  2 +-
 3 files changed, 25 insertions(+), 44 deletions(-)

diff --git a/src/chart/map/MapView.ts b/src/chart/map/MapView.ts
index 48df6e8..b8984c8 100644
--- a/src/chart/map/MapView.ts
+++ b/src/chart/map/MapView.ts
@@ -25,17 +25,9 @@ import MapSeries, { MapDataItemOption } from './MapSeries';
 import GlobalModel from '../../model/Global';
 import ExtensionAPI from '../../core/ExtensionAPI';
 import { Payload, DisplayState, ECElement } from '../../util/types';
-import Model from '../../model/Model';
 import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
 import { Z2_EMPHASIS_LIFT } from '../../util/states';
 
-interface HighDownRecord {
-    recordVersion: number;
-    labelModel: Model;
-    hoverLabelModel: Model;
-    emphasisText: string;
-    normalText: string;
-};
 
 class MapView extends ChartView {
 
diff --git a/src/component/helper/MapDraw.ts b/src/component/helper/MapDraw.ts
index 5388053..f592023 100644
--- a/src/component/helper/MapDraw.ts
+++ b/src/component/helper/MapDraw.ts
@@ -41,7 +41,6 @@ import Model from '../../model/Model';
 import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
 import { getECData } from '../../util/innerStore';
 import { createOrUpdatePatternFromDecal } from '../../util/decal';
-import { makeInner } from '../../util/model';
 import ZRText, {TextStyleProps} from 'zrender/src/graphic/Text';
 import { ViewCoordSysTransformInfoPart } from '../../coord/View';
 import { GeoSVGGraphicRecord, GeoSVGResource } from '../../coord/geo/GeoSVGResource';
@@ -50,11 +49,7 @@ import Element from 'zrender/src/Element';
 import List from '../../data/List';
 import { GeoJSONRegion } from '../../coord/geo/Region';
 import { SVGNodeTagLower } from 'zrender/src/tool/parseSVG';
-
-const mapLabelTransform = makeInner<{
-    x: number
-    y: number
-}, ZRText>();
+import { makeInner } from '../../util/model';
 
 interface RegionsGroup extends graphic.Group {
 }
@@ -96,6 +91,9 @@ const STATE_TRIGGER_TAG_MAP = zrUtil.createHashMap<number, SVGNodeTagLower>(
 const LABEL_HOST_MAP = zrUtil.createHashMap<number, SVGNodeTagLower>(
     OPTION_STYLE_ENABLED_TAGS.concat(['g']) as SVGNodeTagLower[]
 );
+const mapLabelRaw = makeInner<{
+    ignore: boolean
+}, ZRText>();
 
 
 function getFixedItemStyle(model: Model<GeoItemStyleOption>) {
@@ -520,30 +518,11 @@ class MapDraw {
             return action;
         }
 
-        const updateLabelTransforms = () => {
-            const group = this.group;
-            this._regionsGroup.traverse(function (el) {
-                const textContent = el.getTextContent();
-                if (textContent) {
-                    el.setTextConfig({
-                        local: true
-                    });
-                    textContent.x = mapLabelTransform(textContent).x || 0;
-                    textContent.y = mapLabelTransform(textContent).y || 0;
-                    textContent.scaleX = 1 / group.scaleX;
-                    textContent.scaleY = 1 / group.scaleY;
-                    textContent.markRedraw();
-                }
-            });
-        };
-
         controller.off('pan').on('pan', function (e) {
             this._mouseDownFlag = false;
 
             roamHelper.updateViewOnPan(controllerHost, e.dx, e.dy);
 
-            updateLabelTransforms();
-
             api.dispatchAction(zrUtil.extend(makeActionBase(), {
                 dx: e.dx,
                 dy: e.dy
@@ -555,7 +534,14 @@ class MapDraw {
 
             roamHelper.updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
 
-            updateLabelTransforms();
+            // Reset ignore, avoid ignore is changed in LabelManager and can't restored.
+            // TODO: roam action in map should not run LabelManager#addLabelsOfSeries
+            this.group.traverse(el => {
+                const label = el.getTextContent();
+                if (label) {
+                    label.ignore = mapLabelRaw(label).ignore;
+                }
+            });
 
             api.dispatchAction(zrUtil.extend(makeActionBase(), {
                 zoom: e.scale,
@@ -727,17 +713,20 @@ function resetLabelForRegion(
 
         const textEl = el.getTextContent();
         if (textEl) {
-            mapLabelTransform(textEl).x = textEl.x = labelXY ? labelXY[0] : 0;
-            mapLabelTransform(textEl).y = textEl.y = labelXY ? labelXY[1] : 0;
-            textEl.z2 = 10;
             textEl.afterUpdate = labelTextAfterUpdate;
-        }
 
-        // Need to apply the `translate`.
-        if (el.textConfig) {
-            el.textConfig.local = true;
-            if (labelXY) {
-                el.textConfig.position = null;
+            mapLabelRaw(textEl).ignore = textEl.ignore;
+
+            if (el.textConfig) {
+                if (labelXY) {
+                    // Compute a relative offset based on the el bounding rect.
+                    const rect = el.getBoundingRect().clone();
+                    rect.applyTransform(el.getComputedTransform());
+                    el.textConfig.position = [
+                        ((labelXY[0] - rect.x) / rect.width * 100) + '%',
+                        ((labelXY[1] - rect.y) / rect.height * 100) + '%'
+                    ];
+                }
             }
         }
 
diff --git a/src/util/symbol.ts b/src/util/symbol.ts
index bc8de18..dee0263 100644
--- a/src/util/symbol.ts
+++ b/src/util/symbol.ts
@@ -288,7 +288,7 @@ const SymbolClz = graphic.Path.extend({
         return res;
     },
 
-    buildPath: function (ctx, shape, inBundle) {
+    buildPath(ctx, shape, inBundle) {
         let symbolType = shape.symbolType;
         if (symbolType !== 'none') {
             let proxySymbol = symbolBuildProxies[symbolType];

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org