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
38 changes: 38 additions & 0 deletions packages/vrender-components/src/axis/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,51 @@ export class CircleAxis extends AxisBase<CircleAxisAttributes> {
}
}
}

protected afterLabelsOverlap(
labelShapes: IText[],
labelData: AxisItem[],
labelContainer: IGroup,
layer: number,
layerCount: number
): void {
/**
* 基于布局矩形与文本对齐方式设置标签最大行宽:
* - left:可用宽度为到矩形右边界的水平距离(rectRight - x)
* - right:可用宽度为到矩形左边界的水平距离(x - rectLeft)
* - center:取左右两侧最小距离的两倍(2 * min(x - rectLeft, rectRight - x))
*/
const { layoutRect, autoLabelMaxWidth } = this.attribute as CircleAxisAttributes;
if (!autoLabelMaxWidth || !layoutRect || !labelShapes || labelShapes.length === 0) {
return;
}

const rectLeft = 0;
const rectRight = 0 + layoutRect.width;

for (let i = 0; i < labelShapes.length; i++) {
const label = labelShapes[i];
const x = label.attribute.x;
const align = (label.attribute.textAlign as TextAlignType) ?? 'center';

let maxWidth = 0;
if (align === 'left') {
maxWidth = rectRight - x;
} else if (align === 'right') {
maxWidth = x - rectLeft;
} else {
const leftDist = x - rectLeft;
const rightDist = rectRight - x;
maxWidth = 2 * Math.max(0, Math.min(leftDist, rightDist));
}

if (maxWidth > 0) {
label.setAttributes({ maxLineWidth: maxWidth });
} else {
label.setAttributes({ maxLineWidth: 0 });
}
}

return;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/vrender-components/src/axis/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ export interface CircleAxisAttributes extends AxisBaseAttributes {
* @since 0.19.24
*/
sides?: number;

/**
* 坐标轴可用布局区域的大小
*/
layoutRect?: { x: number; y: number; width: number; height: number };
/**
* 是否自动调整标签宽度以适应布局区域
*/
autoLabelMaxWidth?: boolean;
}

// 坐标轴标题配置
Expand Down
Loading