Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/arc inside center label #1398

Merged
merged 3 commits into from
Aug 29, 2024
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 position `inside-center` of arc label",
"type": "none"
}
],
"packageName": "@visactor/vrender-components"
}
17 changes: 6 additions & 11 deletions packages/vrender-components/src/label/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@ import {
} from '@visactor/vutils';
import { LabelBase } from './base';
import type { ArcLabelAttrs, IPoint, Quadrant, BaseLabelAttrs, LabelItem, IArcLabelLineSpec } from './type';
import type { ILineGraphicAttribute, IRichTextAttribute } from '@visactor/vrender-core';
import type { IRichTextAttribute } from '@visactor/vrender-core';
// eslint-disable-next-line no-duplicate-imports
import {
type IRichText,
type IText,
type IArcGraphicAttribute,
type IGraphic,
type ILine,
graphicCreator,
CustomPath2D
} from '@visactor/vrender-core';
import { type IRichText, type IText, type IArcGraphicAttribute, type IGraphic } from '@visactor/vrender-core';
import { isQuadrantRight, isQuadrantLeft, lineCirclePoints, connectLineRadian, checkBoundsOverlap } from './util';
import type { ComponentOptions } from '../interface';
import { registerLabelComponent } from './data-label-register';
Expand Down Expand Up @@ -286,6 +278,7 @@ export class ArcLabel extends LabelBase<ArcLabelAttrs> {
case 'inside':
case 'inside-inner':
case 'inside-outer':
case 'inside-center':
arcs.push(...this._layoutInsideLabels(rightArcs, attribute, currentMarks));
arcs.push(...this._layoutInsideLabels(leftArcs, attribute, currentMarks));
break;
Expand Down Expand Up @@ -339,6 +332,8 @@ export class ArcLabel extends LabelBase<ArcLabelAttrs> {
let labelRadius;
if (position === 'inside-inner') {
labelRadius = innerRadius - offsetRadius + alignOffset;
} else if (position === 'inside-center') {
labelRadius = innerRadius + (outerRadius - innerRadius) / 2;
} else {
labelRadius = outerRadius + offsetRadius - alignOffset;
}
Expand Down Expand Up @@ -966,7 +961,7 @@ export class ArcLabel extends LabelBase<ArcLabelAttrs> {
}

protected _canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds) {
return this.attribute.position === 'inside';
return this.attribute.position === 'inside' || this.attribute.position === 'inside-center';
}

private computeLayoutOuterRadius(r: number, width: number, height: number) {
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 @@ -356,8 +356,9 @@ export interface ArcLabelAttrs extends BaseLabelAttrs {
/**
* 标签位置
* @default 'outside'
* @since 0.20.1 support 'inside-center'
*/
position?: Functional<'inside' | 'outside' | 'inside-inner' | 'inside-outer'>;
position?: 'inside' | 'outside' | 'inside-inner' | 'inside-outer' | 'inside-center';
xiaoluoHe marked this conversation as resolved.
Show resolved Hide resolved

// 画布宽度
width?: number;
Expand Down
Loading