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 2020/05/14 11:04:14 UTC

[incubator-echarts] branch label-enhancement updated: fix(state): fix some state issues on pie.

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

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


The following commit(s) were added to refs/heads/label-enhancement by this push:
     new e201982  fix(state): fix some state issues on pie.
e201982 is described below

commit e201982d38158d6c7f380f676153705ce31cfefa
Author: pissang <bm...@gmail.com>
AuthorDate: Thu May 14 19:03:53 2020 +0800

    fix(state): fix some state issues on pie.
---
 src/chart/funnel/FunnelSeries.ts |  3 +--
 src/chart/pie/PieView.ts         | 28 +++++++++++---------
 src/util/graphic.ts              | 55 ++++++++++++++++++++--------------------
 3 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/src/chart/funnel/FunnelSeries.ts b/src/chart/funnel/FunnelSeries.ts
index a679788..a54d967 100644
--- a/src/chart/funnel/FunnelSeries.ts
+++ b/src/chart/funnel/FunnelSeries.ts
@@ -172,8 +172,7 @@ class FunnelSeriesModel extends SeriesModel<FunnelSeriesOption> {
             length: 20,
             lineStyle: {
                 // color: 各异,
-                width: 1,
-                type: 'solid'
+                width: 1
             }
         },
         itemStyle: {
diff --git a/src/chart/pie/PieView.ts b/src/chart/pie/PieView.ts
index b36be3c..56d1ac6 100644
--- a/src/chart/pie/PieView.ts
+++ b/src/chart/pie/PieView.ts
@@ -28,6 +28,7 @@ import { Payload, ColorString } from '../../util/types';
 import List from '../../data/List';
 import PieSeriesModel, {PieDataItemOption} from './PieSeries';
 import { ElementAnimateConfig } from 'zrender/src/Element';
+import labelLayout from './labelLayout';
 
 function updateDataSelected(
     this: PiePiece,
@@ -143,12 +144,6 @@ class PiePiece extends graphic.Sector {
         sectorSelectState.x = dx;
         sectorSelectState.y = dy;
 
-
-        sector.toggleState('select', seriesModel.isSelected(data.getName(idx)), {
-            duration: seriesModel.get('animation') ? 200 : 0,
-            easing: 'cubicOut'
-        });
-
         const cursorStyle = itemModel.getShallow('cursor');
         cursorStyle && sector.attr('cursor', cursorStyle);
 
@@ -165,14 +160,23 @@ class PiePiece extends graphic.Sector {
         const labelLine = sector.getTextGuideLine();
         const labelText = sector.getTextContent();
 
-        const labelLineSelectState = labelLine.ensureState('select');
-        const labelTextSelectState = labelText.ensureState('select');
-        labelLineSelectState.x = dx;
-        labelLineSelectState.y = dy;
-        labelTextSelectState.x = dx;
-        labelTextSelectState.y = dy;
+        labelLine.states.select = {
+            x: dx, y: dy
+        };
+        if (layout.label) {
+            labelText.states.select = {
+                x: layout.label.x + dx,
+                y: layout.label.y + dy
+            };
+        }
 
         graphic.enableHoverEmphasis(this);
+
+        // Switch after `select` state updated.
+        sector.toggleState('select', seriesModel.isSelected(data.getName(idx)), {
+            duration: seriesModel.get('animation') ? 200 : 0,
+            easing: 'cubicOut'
+        });
     }
 
     private _updateLabel(data: List, idx: number, withAnimation: boolean): void {
diff --git a/src/util/graphic.ts b/src/util/graphic.ts
index a1a84e8..ea75df7 100644
--- a/src/util/graphic.ts
+++ b/src/util/graphic.ts
@@ -72,7 +72,8 @@ import {
     trim,
     isArrayLike,
     map,
-    defaults
+    defaults,
+    indexOf
 } from 'zrender/src/core/util';
 
 
@@ -383,11 +384,6 @@ function singleEnterEmphasis(el: Element) {
         // TODO Configuration
         easing: 'cubicOut'
     });
-
-    const textContent = el.getTextContent();
-    if (textContent) {
-        textContent.z2 += Z2_EMPHASIS_LIFT;
-    }
     // TODO hover layer
 }
 
@@ -446,36 +442,41 @@ export function clearStates(el: Element) {
 function elementStateProxy(this: Displayable, stateName: string): DisplayableState {
     let state = this.states[stateName];
     if (stateName === 'emphasis' && this.style) {
-        const currentFill = this.style.fill;
-        const currentStroke = this.style.stroke;
-        if (currentFill || currentStroke) {
-            state = state || {};
-            // Apply default color lift
-            let emphasisStyle = state.style || {};
-            let cloned = false;
-            if (!hasFillOrStroke(emphasisStyle.fill)) {
-                cloned = true;
-                // Not modify the original value.
-                state = extend({}, state);
-                emphasisStyle = extend({}, emphasisStyle);
-                emphasisStyle.fill = liftColor(currentFill);
-            }
-            if (!hasFillOrStroke(emphasisStyle.stroke)) {
-                if (!cloned) {
+        const hasEmphasis = indexOf(this.currentStates, stateName) >= 0;
+        if (!(this instanceof ZRText)) {
+            const currentFill = this.style.fill;
+            const currentStroke = this.style.stroke;
+            if (currentFill || currentStroke) {
+                state = state || {};
+                // Apply default color lift
+                let emphasisStyle = state.style || {};
+                let cloned = false;
+                if (!hasFillOrStroke(emphasisStyle.fill)) {
+                    cloned = true;
+                    // Not modify the original value.
                     state = extend({}, state);
                     emphasisStyle = extend({}, emphasisStyle);
+                    // Already being applied 'emphasis'. DON'T lift color multiple times.
+                    emphasisStyle.fill = hasEmphasis ? currentFill : liftColor(currentFill);
+                }
+                if (!hasFillOrStroke(emphasisStyle.stroke)) {
+                    if (!cloned) {
+                        state = extend({}, state);
+                        emphasisStyle = extend({}, emphasisStyle);
+                    }
+                    emphasisStyle.stroke = hasEmphasis ? currentStroke : liftColor(currentStroke);
                 }
-                emphasisStyle.stroke = liftColor(currentStroke);
-            }
 
-            state.style = emphasisStyle;
+                state.style = emphasisStyle;
+            }
         }
+        state.z2 = this.z2 + Z2_EMPHASIS_LIFT;
     }
 
     return state;
 }
 
-/**
+/**FI
  * Set hover style (namely "emphasis style") of element.
  * @param el Should not be `zrender/graphic/Group`.
  */
@@ -694,7 +695,7 @@ type LabelModelForText = Model<Omit<
  * And create a new style object.
  *
  * NOTICE: Because the style on ZRText will be replaced with new(only x, y are keeped).
- * So please use the style on ZRText after use this method.
+ * So please update the style on ZRText after use this method.
  */
 // eslint-disable-next-line
 function setLabelStyle<LDI>(targetEl: ZRText, normalModel: LabelModelForText, emphasisModel: LabelModelForText, opt?: SetLabelStyleOpt<LDI>, normalSpecified?: TextStyleProps, emphasisSpecified?: TextStyleProps): void;


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