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

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

commit 51387f56e56053a27b7f2fa827458b3e15677632
Author: Ovilia <zwl.s...@gmail.com>
AuthorDate: Wed Jun 2 18:11:00 2021 +0800

    fix(endLabel): endLabel should be displayed if show is true in other states 
#14441
---
 src/chart/line/LineSeries.ts |  1 +
 src/chart/line/LineView.ts   | 16 +++++++++++----
 test/line-endLabel.html      | 46 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/src/chart/line/LineSeries.ts b/src/chart/line/LineSeries.ts
index 7d44f23..7dfe71d 100644
--- a/src/chart/line/LineSeries.ts
+++ b/src/chart/line/LineSeries.ts
@@ -55,6 +55,7 @@ interface ExtraStateOption {
 export interface LineStateOption {
     itemStyle?: ItemStyleOption
     label?: SeriesLabelOption
+    endLabel?: LineEndLabelOption
 }
 
 export interface LineDataItemOption extends SymbolOptionMixin,
diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts
index d14424b..a0aca1a 100644
--- a/src/chart/line/LineView.ts
+++ b/src/chart/line/LineView.ts
@@ -29,7 +29,7 @@ import {ECPolyline, ECPolygon} from './poly';
 import ChartView from '../../view/Chart';
 import {prepareDataCoordInfo, getStackedOnPoint} from './helper';
 import {createGridClipPath, createPolarClipPath} from 
'../helper/createClipPathFromCoordSys';
-import LineSeriesModel, { LineSeriesOption } from './LineSeries';
+import LineSeriesModel, { LineEndLabelOption, LineSeriesOption } from 
'./LineSeries';
 import type GlobalModel from '../../model/Global';
 import type ExtensionAPI from '../../core/ExtensionAPI';
 // TODO
@@ -412,6 +412,15 @@ function getIndexRange(points: ArrayLike<number>, xOrY: 
number, dim: 'x' | 'y')
     };
 }
 
+function anyStateShowEndLabel(
+    endLabelModel: Model<LineEndLabelOption>, seriesModel: LineSeriesModel
+) {
+    return endLabelModel.get('show')
+        || seriesModel.get(['emphasis', 'endLabel', 'show'])
+        || seriesModel.get(['blur', 'endLabel', 'show'])
+        || seriesModel.get(['select', 'endLabel', 'show']);
+}
+
 
 interface EndLabelAnimationRecord {
     lastFrameIndex: number
@@ -427,13 +436,12 @@ function createLineClipPath(
 ) {
     if (isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')) {
         const endLabelModel = seriesModel.getModel('endLabel');
-        const showEndLabel = endLabelModel.get('show');
         const valueAnimation = endLabelModel.get('valueAnimation');
         const data = seriesModel.getData();
 
         const labelAnimationRecord: EndLabelAnimationRecord = { 
lastFrameIndex: 0 };
 
-        const during = showEndLabel
+        const during = anyStateShowEndLabel(endLabelModel, seriesModel)
             ? (percent: number, clipRect: graphic.Rect) => {
                 lineView._endLabelOnDuring(
                     percent,
@@ -1055,7 +1063,7 @@ class LineView extends ChartView {
     ) {
         const endLabelModel = seriesModel.getModel('endLabel');
 
-        if (endLabelModel.get('show')) {
+        if (anyStateShowEndLabel(endLabelModel, seriesModel)) {
             const data = seriesModel.getData();
             const polyline = this._polyline;
             let endLabel = this._endLabel;
diff --git a/test/line-endLabel.html b/test/line-endLabel.html
index cefa176..860fec0 100644
--- a/test/line-endLabel.html
+++ b/test/line-endLabel.html
@@ -36,7 +36,7 @@ under the License.
                 height: 1000px;
                 margin-bottom: 30px;
             }
-            #main2 {
+            #main2, #main3 {
                 width: 100%;
                 height: 300px;
                 margin-bottom: 30px;
@@ -128,6 +128,8 @@ under the License.
         <div id="main0"></div>
         <div id="main1"></div>
         <div id="main2"></div>
+        <div id="main3"></div>
+
         <script>
 
             require([
@@ -389,5 +391,47 @@ under the License.
             })
 
         </script>
+
+        <script>
+
+
+            require([
+                'echarts'
+            ], function (echarts) {
+
+                var chart = echarts.init(document.getElementById('main3'));
+                var option = {
+                    title: [{
+                        text: 'Emphasis on the data at "b" and endLabel should 
be displayed',
+                        textAlign: 'center',
+                        left: '50%',
+                        top: 0
+                    }],
+                    xAxis: [{
+                        data: ['a', 'b']
+                    }],
+                    yAxis: [{
+                    }],
+                    series: [{
+                        type: 'line',
+                        data: [1, 2],
+                        endLabel: {
+                            // show: true,
+                            formatter: '{a}: {c}'
+                        },
+                        emphasis: {
+                            endLabel: {
+                                show: true,
+                                color: 'red'
+                            }
+                        }
+                    }],
+                    animationDuration: 0
+                };
+                chart.setOption(option);
+
+            })
+
+        </script>
     </body>
 </html>

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

Reply via email to