P26:标签按"标签列"1:1 落到记录、窗口、元素、文本四处(规范 §35)
- XChartColumnMath 补标签半边(LabelCount / LabelSlotOf / DefinitionOfLabelSlot / SizedLabels),
记录的标签长度只由这一处定;TryAddRecord 在 labels 长度≠标签列数时整条拒收
- 导入按标签字段个数校验并点名行号;记录行少到连时间戳都没有时点名拒绝(不再抛异常)
- 数据窗口:一个显示序两个读者(标签列在前),格子身份 CellRef{IsLabel,Slot},
标签格走 TrySetLabel 的字符串分支,「+标签」走 SetDimensions 这唯一定长路径
- 新标签元素 ChartToolLabels + XChartLabelConfig:13 旋钮全自动置脏、位置/折法同散点、
文本走池且多余槽位必须擦、锚点与对齐出自同一张表(anchorMin/Max 不写)
- 面板把"要几个标签列、表里有几个"与数值维、记录数一起印(§25.1 第三半 RequiredLabelColumns)
- 探针先红的两个真缺陷:SizedLabels(null,n) 补 null 不是空串;锚点表漏 MiddleRight 与 Center 重合
- 雷达 AddSeries 带系列名,两个 SetDimensions 重载都声明 series 标签列(否则新门口整条拒收)
- 判据:探针 492/0、label_gate 15 claim/15 臂全红、dirty_gate 149/149、slot_reset PASS、
编译门三臂+3 对照绿(source present 点名四个新文件)、p4_control 78 支各红在点名断言
(同一棵树指纹 478727e6748c67cddda40995874b20968e9eae3706f2a21c24726d3412059747)
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericUI.XChart.Text
|
||||
{
|
||||
/// <summary>标签矩形相对它那一点的位置:9 档(四角 + 四边中点 + 中心)。</summary>
|
||||
public enum XChartLabelAnchor
|
||||
{
|
||||
LowerLeft,
|
||||
LowerCenter,
|
||||
LowerRight,
|
||||
MiddleLeft,
|
||||
Center,
|
||||
MiddleRight,
|
||||
UpperLeft,
|
||||
UpperCenter,
|
||||
UpperRight,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 锚点的<b>纯算</b>部分(离线可验)。
|
||||
///
|
||||
/// <para><b>为什么锚点与对齐必须出自同一张表</b>:锚定在左下角的矩形如果把字居中对齐,
|
||||
/// 字就横跨在那一点两侧,"标签贴在点上"这句话当场作废。以前这两件事各写各的
|
||||
/// (锚点一处、对齐来自池的默认值),所以改锚点而字仍居中是画面上最难归因的一种错。</para>
|
||||
/// </summary>
|
||||
public static class XChartLabelAnchorMath
|
||||
{
|
||||
/// <summary>九档锚点各自的那个位置([0,1] 内的矩形锚位)。九档互不相同是判据,不是巧合。</summary>
|
||||
public static Vector2 AnchorOf(XChartLabelAnchor anchor)
|
||||
{
|
||||
switch (anchor)
|
||||
{
|
||||
case XChartLabelAnchor.LowerLeft: return new Vector2(0f, 0f);
|
||||
case XChartLabelAnchor.LowerCenter: return new Vector2(0.5f, 0f);
|
||||
case XChartLabelAnchor.LowerRight: return new Vector2(1f, 0f);
|
||||
case XChartLabelAnchor.MiddleLeft: return new Vector2(0f, 0.5f);
|
||||
case XChartLabelAnchor.MiddleRight: return new Vector2(1f, 0.5f);
|
||||
case XChartLabelAnchor.UpperLeft: return new Vector2(0f, 1f);
|
||||
case XChartLabelAnchor.UpperCenter: return new Vector2(0.5f, 1f);
|
||||
case XChartLabelAnchor.UpperRight: return new Vector2(1f, 1f);
|
||||
default: return new Vector2(0.5f, 0.5f); // Center
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 这一档锚点对应的文字对齐:<b>由同一个锚点算出来</b>(横分量取锚点的 x、纵分量取锚点的 y)。
|
||||
/// 这样"贴在左下角"和"字从左下角起排"是同一件事,不再有第二处定义。
|
||||
/// </summary>
|
||||
public static TextAlignmentOptions AlignmentFor(XChartLabelAnchor anchor)
|
||||
{
|
||||
Vector2 a = AnchorOf(anchor);
|
||||
if (Mathf.Abs(a.x - 0.5f) < 1e-4f && Mathf.Abs(a.y - 0.5f) < 1e-4f) return TextAlignmentOptions.Center;
|
||||
if (Mathf.Abs(a.y - 0.5f) < 1e-4f) return a.x < 0.5f ? TextAlignmentOptions.MidlineLeft : TextAlignmentOptions.MidlineRight;
|
||||
if (Mathf.Abs(a.x - 0.5f) < 1e-4f) return a.y < 0.5f ? TextAlignmentOptions.Bottom : TextAlignmentOptions.Top;
|
||||
if (a.y < 0.5f) return a.x < 0.5f ? TextAlignmentOptions.BottomLeft : TextAlignmentOptions.BottomRight;
|
||||
return a.x < 0.5f ? TextAlignmentOptions.TopLeft : TextAlignmentOptions.TopRight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 偏移:<b>非有限数当成零</b>。NaN 进 anchoredPosition 会把这一件字整个挪出画面,
|
||||
/// 而且它不报错——这正是"计数全对、画面空无一物"那一族。
|
||||
/// </summary>
|
||||
public static Vector2 SafeOffset(Vector2 offset)
|
||||
{
|
||||
if (float.IsNaN(offset.x) || float.IsInfinity(offset.x)) offset.x = 0f;
|
||||
if (float.IsNaN(offset.y) || float.IsInfinity(offset.y)) offset.y = 0f;
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user