From 1333f195fc782045d0bf764ea2dc335200d43e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E7=A7=8B=E5=8D=8A=E5=A4=8F?= <2646403766@qq.com> Date: Thu, 8 Jan 2026 11:09:34 +0800 Subject: [PATCH 1/3] feature(pie): inject labelSide into pie label formatter parameters --- src/model/mixin/dataFormat.ts | 21 ++++++++------ src/util/types.ts | 2 ++ test/pie-label.html | 54 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/model/mixin/dataFormat.ts b/src/model/mixin/dataFormat.ts index 2c39816235..a746029a0b 100644 --- a/src/model/mixin/dataFormat.ts +++ b/src/model/mixin/dataFormat.ts @@ -21,21 +21,21 @@ import * as zrUtil from 'zrender/src/core/util'; import {retrieveRawValue} from '../../data/helper/dataProvider'; import {formatTpl} from '../../util/format'; import { - DataHost, - DisplayState, CallbackDataParams, ColorString, - ZRColor, - OptionDataValue, - SeriesDataType, ComponentMainType, ComponentSubType, + DataHost, DimensionLoose, - InterpolatableValue + DisplayState, + InterpolatableValue, + OptionDataValue, + SeriesDataType, + ZRColor } from '../../util/types'; import GlobalModel from '../Global'; -import { TooltipMarkupBlockFragment } from '../../component/tooltip/tooltipMarkup'; -import { error, makePrintable } from '../../util/log'; +import {TooltipMarkupBlockFragment} from '../../component/tooltip/tooltipMarkup'; +import {error, makePrintable} from '../../util/log'; const DIMENSION_LABEL_REG = /\{@(.+?)\}/g; @@ -140,6 +140,11 @@ export class DataFormatMixin { if (zrUtil.isFunction(formatter)) { params.status = status; params.dimensionIndex = labelDimIndex; + + const sectorShape = data.getItemLayout(dataIndex); + const midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2; + const nx = Math.cos(midAngle); + params.labelSide = nx > 0 ? 'right' : 'left'; return formatter(params); } else if (zrUtil.isString(formatter)) { diff --git a/src/util/types.ts b/src/util/types.ts index 1d6521d51e..d40a985ca4 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -884,6 +884,8 @@ export interface CallbackDataParams { // Param name list for mapping `a`, `b`, `c`, `d`, `e` $vars: string[]; + // Pie chart label orientation + labelSide?: string; } export type InterpolatableValue = ParsedValue | ParsedValue[]; diff --git a/test/pie-label.html b/test/pie-label.html index fae6518079..927127d1a4 100644 --- a/test/pie-label.html +++ b/test/pie-label.html @@ -53,6 +53,7 @@
+
+ + From 0d2892de0241cecd9c60ace44fbb7a5c0cfd3b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E7=A7=8B=E5=8D=8A=E5=A4=8F?= <2646403766@qq.com> Date: Thu, 8 Jan 2026 11:43:09 +0800 Subject: [PATCH 2/3] feature(pie): demo title --- test/pie-label.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/pie-label.html b/test/pie-label.html index 927127d1a4..8709497f1b 100644 --- a/test/pie-label.html +++ b/test/pie-label.html @@ -1116,8 +1116,8 @@ var chart = testHelper.create(echarts, 'main13', { title: [ - 'The labels should be rendered correctly and no errors in the console', - 'Test case from issue #17712', + 'add labelSide to formatter params', + 'label Icons always face inward.', ], height: 300, option: option From 937cb40919703ce9518144aa96918226dee5a310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E7=A7=8B=E5=8D=8A=E5=A4=8F?= <2646403766@qq.com> Date: Thu, 8 Jan 2026 13:11:16 +0800 Subject: [PATCH 3/3] feature(pie): Specific to pie --- src/model/mixin/dataFormat.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/model/mixin/dataFormat.ts b/src/model/mixin/dataFormat.ts index a746029a0b..4fe0c1a840 100644 --- a/src/model/mixin/dataFormat.ts +++ b/src/model/mixin/dataFormat.ts @@ -140,11 +140,12 @@ export class DataFormatMixin { if (zrUtil.isFunction(formatter)) { params.status = status; params.dimensionIndex = labelDimIndex; - - const sectorShape = data.getItemLayout(dataIndex); - const midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2; - const nx = Math.cos(midAngle); - params.labelSide = nx > 0 ? 'right' : 'left'; + if (params.seriesType === 'pie') { + const sectorShape = data.getItemLayout(dataIndex); + const midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2; + const nx = Math.cos(midAngle); + params.labelSide = nx > 0 ? 'right' : 'left'; + } return formatter(params); } else if (zrUtil.isString(formatter)) {