环形图标注重叠:上下边界让出两行字高度

This commit is contained in:
XIGE
2026-11-28 02:13:39 +08:00
parent 431fede0ed
commit ecf33cded5
2 changed files with 10 additions and 3 deletions

View File

@@ -1,5 +1,9 @@
# 变更记录
## 2026-11-28 · 环形图标注重叠:上下边界让出两行字高度
- 同步源码更新 1 个文件(新增/修改 1,删除 0)。
## 2026-11-28 · v0.4.0:统计页按参考图重做分布卡片(日/周/月/年 + 引线标注环图)
- **删除统计页右上角的区间筛选栏**(今日/本周/本月/全部)。趋势图随之固定为「最近 7 天」,不再受全局区间牵制。

View File

@@ -197,8 +197,9 @@ class LabelDonutView @JvmOverloads constructor(
/** 同侧标签按落点排序后做最小间距夹逼,再整体收回可视区 */
private fun layoutTags(tags: List<Tag>) {
val minGap = context.dpf(29f)
val top = context.dpf(4f)
val bottom = height - context.dpf(8f)
// 上下留出两行字的高度:时间在 y 上方、名称在 y 下方,压到边界会被裁掉
val top = context.dpf(15f)
val bottom = height - context.dpf(17f)
for (side in intArrayOf(-1, 1)) {
val group = tags.filter { it.side == side }.sortedBy { it.anchorY }
if (group.isEmpty()) continue
@@ -208,7 +209,9 @@ class LabelDonutView @JvmOverloads constructor(
val overflow = group.last().y - bottom
if (overflow > 0f) group.forEach { it.y -= overflow }
// 极端情况下(标注多、控件矮)再压回上界,宁可间距略小也不出画布
group.forEach { it.y = it.y.coerceIn(top, bottom) }
val lo = minOf(top, bottom)
val hi = maxOf(top, bottom)
group.forEach { it.y = it.y.coerceIn(lo, hi) }
}
}