Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-components",
"comment": "feat: support 'inside-middle' position for line-data label",
"type": "none"
}
],
"packageName": "@visactor/vrender-components"
}
16 changes: 14 additions & 2 deletions packages/vrender-components/src/label/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,15 +697,27 @@ export class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {
return (this.getRootNode() as IGroup).find(node => node.name === baseMarkGroupName, true) as IGroup;
}

protected getGraphicBounds(graphic?: IGraphic, point?: Partial<PointLocationCfg>, position?: string): IBoundsLike;
protected getGraphicBounds(graphic?: IGraphic, point: Partial<PointLocationCfg> = {}): IBoundsLike {
protected getGraphicBounds(
graphic?: IGraphic,
point: Partial<PointLocationCfg> = {},
position?: string
): IBoundsLike {
if (graphic) {
if (graphic.attribute.visible !== false) {
return graphic.AABBBounds;
}
const { x, y } = graphic.attribute;
return { x1: x, x2: x, y1: y, y2: y } as IBoundsLike;
}
if (point && position && position === 'inside-middle') {
const { x, y, x1 = x, y1 = y } = point;
return {
x1: (x + x1) / 2,
x2: (x + x1) / 2,
y1: (y + y1) / 2,
y2: (y + y1) / 2
};
}
const { x, y } = point;
return { x1: x, x2: x, y1: y, y2: y } as IBoundsLike;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/vrender-components/src/label/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ export interface LineDataLabelAttrs extends BaseLabelAttrs {
/**
* 标签位置
* @default 'top'
* @since 0.21.1 支持 'inside-middle' 在面积图元中显示在中间位置
*/
position?: Functional<BoundsAnchorType>;
position?: Functional<BoundsAnchorType | 'inside-middle'>;
}

export interface PolygonLabelAttrs extends BaseLabelAttrs {
Expand Down
Loading