You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2021/04/08 09:02:24 UTC

[echarts] 03/04: fix: [map labelLayout] fix hideOverlap work correct in map series.

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

sushuang pushed a commit to branch fix/geo-location
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 7306b7ff3a11d45add20fae67c8792b3a37c582b
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Apr 8 16:55:53 2021 +0800

    fix: [map labelLayout] fix hideOverlap work correct in map series.
---
 src/chart/map/MapView.ts               |  4 ++
 src/component/helper/MapDraw.ts        | 29 +++++++----
 test/label-layout.html                 | 92 ++++++++++++++++++++++++++++++++++
 test/runTest/actions/__meta__.json     |  2 +-
 test/runTest/actions/label-layout.json |  2 +-
 5 files changed, 118 insertions(+), 11 deletions(-)

diff --git a/src/chart/map/MapView.ts b/src/chart/map/MapView.ts
index b8984c8..1a960d5 100644
--- a/src/chart/map/MapView.ts
+++ b/src/chart/map/MapView.ts
@@ -56,6 +56,10 @@ class MapView extends ChartView {
             return;
         }
 
+        if (this._mapDraw && payload && payload.type === 'geoRoam') {
+            this._mapDraw.resetForLabelLayout();
+        }
+
         // Not update map if it is an roam action from self
         if (!(payload && payload.type === 'geoRoam'
                 && payload.componentType === 'series'
diff --git a/src/component/helper/MapDraw.ts b/src/component/helper/MapDraw.ts
index da88c3e..b1e2341 100644
--- a/src/component/helper/MapDraw.ts
+++ b/src/component/helper/MapDraw.ts
@@ -534,15 +534,6 @@ class MapDraw {
 
             roamHelper.updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
 
-            // 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,
                 originX: e.originX,
@@ -557,6 +548,26 @@ class MapDraw {
         });
     }
 
+    /**
+     * FIXME: this is a temporarily workaround.
+     * When `geoRoam` the elements need to be reset in `MapView['render']`, because the props like
+     * `ignore` might have been modified by `LabelManager`, and `LabelManager#addLabelsOfSeries`
+     * will subsequently cache `defaultAttr` like `ignore`. If do not do this reset, the modified
+     * props will have no chance to be restored.
+     * Note: this reset should be after `clearStates` in `renderSeries` becuase `useStates` in
+     * `renderSeries` will cache the modified `ignore` to `el._normalState`.
+     * TODO:
+     * Use clone/immutable in `LabelManager`?
+     */
+    resetForLabelLayout() {
+        this.group.traverse(el => {
+            const label = el.getTextContent();
+            if (label) {
+                label.ignore = mapLabelRaw(label).ignore;
+            }
+        });
+    }
+
     private _updateMapSelectHandler(
         mapOrGeoModel: GeoModel | MapSeries,
         regionsGroup: RegionsGroup,
diff --git a/test/label-layout.html b/test/label-layout.html
index 6c49908..cf23862 100644
--- a/test/label-layout.html
+++ b/test/label-layout.html
@@ -52,6 +52,8 @@ under the License.
         <div id="main9"></div>
         <div id="main10"></div>
         <div id="main11"></div>
+        <div id="main12"></div>
+        <div id="main13"></div>
 
 
 
@@ -827,6 +829,96 @@ under the License.
                 });
             });
         </script>
+
+
+        <script>
+        require(['echarts'/*, 'map/js/china' */], function (echarts) {
+            const svg = [
+                '<?xml version="1.0" encoding="utf-8"?>',
+                '<svg viewBox="-25 0 300 100" xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" fill-rule="evenodd" xml:space="preserve">',
+                '<path name="left_rect" d="M 0,0 L 0,100 100,100 100,0 Z" fill="#765" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>',
+                '<path name="right_rect" d="M 150,0 L 150,100 250,100 250,0 Z" fill="#567" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>',
+                '</svg>'
+            ].join('')
+
+            echarts.registerMap('testGeoSVG_coord1', { svg: svg });
+
+            option = {
+                series: [{
+                    type: 'map',
+                    roam: true,
+                    top: 10,
+                    bottom: 10,
+                    left: 10,
+                    right: 10,
+                    selectedMode: 'multiple',
+                    map: 'testGeoSVG_coord1',
+                    select: {
+                        itemStyle: {
+                            color: 'red'
+                        },
+                        label: {
+                            color: '#fff'
+                        }
+                    },
+                    label: {
+                        show: true,
+                        fontSize: 30
+                    },
+                    labelLayout: {
+                        hideOverlap: true
+                    }
+                }]
+            };
+
+            var chart = testHelper.create(echarts, 'main12', {
+                title: [
+                    'Click both rect make them selected (become red)',
+                    '(1) zoom to trigger label **hideOverlap**',
+                    'zoom back, check labels should be restored',
+                    '(2) mouseover one the **right rect** and zoom to trigger label **hideOverlap**',
+                    'zoom back, mouseout, check the label should not disappear'
+                ],
+                option: option,
+                height: 200,
+            });
+        });
+        </script>
+
+
+
+        <script>
+        require(['echarts'/*, 'map/js/china' */], function (echarts) {
+            const svg = [
+                '<?xml version="1.0" encoding="utf-8"?>',
+                '<svg xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" fill-rule="evenodd" xml:space="preserve">',
+                '<path name="left_rect" d="M 0,0 L 0,100 100,100 100,0 Z" fill="#765" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>',
+                '</svg>'
+            ].join('')
+
+            echarts.registerMap('testGeoSVG_coord2', { svg: svg });
+
+            option = {
+                geo: {
+                    map: 'testGeoSVG_coord2',
+                    roam: true
+                }
+            };
+
+            var chart = testHelper.create(echarts, 'main13', {
+                title: [
+                    '(geo coordSys) label displayed only on hover',
+                    'zoom: label should keep displayed.'
+                ],
+                option: option,
+                height: 200,
+            });
+        });
+        </script>
+
+
+
+
     </body>
 </html>
 
diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json
index 69a7a44..4271bd7 100644
--- a/test/runTest/actions/__meta__.json
+++ b/test/runTest/actions/__meta__.json
@@ -94,7 +94,7 @@
   "hoverStyle": 14,
   "hoverStyle2": 1,
   "label-animation": 3,
-  "label-layout": 2,
+  "label-layout": 4,
   "label-position": 1,
   "largeLine-tooltip": 1,
   "legend": 11,
diff --git a/test/runTest/actions/label-layout.json b/test/runTest/actions/label-layout.json
index a1bd982..dbf8a20 100644
--- a/test/runTest/actions/label-layout.json
+++ b/test/runTest/actions/label-layout.json
@@ -1 +1 @@
-[{"name":"Action 1","ops":[{"type":"mousemove","time":47,"x":689,"y":417},{"type":"mousemove","time":320,"x":689,"y":415},{"type":"mousemove","time":473,"x":689,"y":415},{"type":"mousedown","time":546,"x":689,"y":415},{"type":"mousemove","time":679,"x":682,"y":380},{"type":"mousemove","time":1002,"x":675,"y":339},{"type":"mouseup","time":1054,"x":675,"y":339},{"time":1055,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":1240,"x":674,"y":339},{"type":"mousemove","time":144 [...]
\ No newline at end of file
+[{"name":"Action 1","ops":[{"type":"mousemove","time":47,"x":689,"y":417},{"type":"mousemove","time":320,"x":689,"y":415},{"type":"mousemove","time":473,"x":689,"y":415},{"type":"mousedown","time":546,"x":689,"y":415},{"type":"mousemove","time":679,"x":682,"y":380},{"type":"mousemove","time":1002,"x":675,"y":339},{"type":"mouseup","time":1054,"x":675,"y":339},{"time":1055,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":1240,"x":674,"y":339},{"type":"mousemove","time":144 [...]
\ No newline at end of file

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