diff --git a/src/model/mixin/dataFormat.ts b/src/model/mixin/dataFormat.ts index 2c39816235..4fe0c1a840 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,12 @@ export class DataFormatMixin { if (zrUtil.isFunction(formatter)) { params.status = status; params.dimensionIndex = labelDimIndex; + 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)) { 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..8709497f1b 100644 --- a/test/pie-label.html +++ b/test/pie-label.html @@ -53,6 +53,7 @@
+ + +