update at 2026-01-21 17:58:55

This commit is contained in:
douboer
2026-01-21 17:58:55 +08:00
parent 8c29926c88
commit f723f76df0
3 changed files with 195 additions and 152 deletions

View File

@@ -24,6 +24,36 @@ export const SECTOR_INSET_DISTANCE = 1;
*/
export const SECTOR_STROKE_WIDTH = 0.3;
/**
* 单个扇区多文本单元布局比例预设
* 当content使用"|"分隔多个文本时,根据单元数量自动选择布局比例
* 1个单元100%
* 2个单元平均分配 [0.5, 0.5]
* 3个单元中间大两边小 [0.25, 0.5, 0.25]
* 4个单元中间两个大 [0.2, 0.3, 0.3, 0.2]
* 5个及以上平均分配
*/
export const LAYOUT_RATIO_PRESETS: Record<number, number[]> = {
1: [1.0],
2: [0.5, 0.5],
3: [0.25, 0.5, 0.25],
4: [0.2, 0.3, 0.3, 0.2],
};
/**
* 获取多文本单元布局比例
* @param unitCount 文本单元数量
* @returns 角度分配比例数组
*/
export const getLayoutRatio = (unitCount: number): number[] => {
if (unitCount <= 4 && LAYOUT_RATIO_PRESETS[unitCount]) {
return LAYOUT_RATIO_PRESETS[unitCount];
}
// 5个及以上单元平均分配
const ratio = 1 / unitCount;
return Array(unitCount).fill(ratio);
};
/**
* 文字布局配置常量
* 用于计算扇区内文字的字体大小和位置