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 @@
+ + +