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:
@@ -60,5 +60,70 @@ namespace XericUI.XChart
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── 标签列(String 那一族):与数值列同一套规则,只是占的是标签数组的格 ──
|
||||
//
|
||||
// 记录身上有两个数组:值数组的长度=<see cref="ValueCount"/>,标签数组的长度=
|
||||
// <see cref="LabelCount"/>。<b>标签数组的长度就是它自己的判据</b>:一条记录能写出
|
||||
// 比标签列更多的字符串,那些字符串没有一个列能叫出名字,屏幕上便凭空多出一个标签
|
||||
// (以前这里靠调用方自觉,所以导入能塞进去、窗口显示得出来、元素却读不到)。
|
||||
|
||||
/// <summary>标签列的个数=每条记录标签数组的长度(非标签列不占格)</summary>
|
||||
public static int LabelCount(IReadOnlyList<XChartDimensionDefinition> dimensions)
|
||||
{
|
||||
if (dimensions == null) return 0;
|
||||
int count = 0;
|
||||
for (int i = 0; i < dimensions.Count; i++)
|
||||
if (dimensions[i] != null && dimensions[i].Kind == XChartDimensionKind.Label) count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表里第 <paramref name="tableIndex"/> 行对应的<b>标签下标</b>;
|
||||
/// 那一列不占标签格(种类不是 Label)或行号越界时返回 <c>-1</c>。
|
||||
/// </summary>
|
||||
public static int LabelSlotOf(IReadOnlyList<XChartDimensionDefinition> dimensions, int tableIndex)
|
||||
{
|
||||
if (dimensions == null || tableIndex < 0 || tableIndex >= dimensions.Count) return -1;
|
||||
var target = dimensions[tableIndex];
|
||||
if (target == null || target.Kind != XChartDimensionKind.Label) return -1;
|
||||
|
||||
int slot = 0;
|
||||
for (int i = 0; i < tableIndex; i++)
|
||||
if (dimensions[i] != null && dimensions[i].Kind == XChartDimensionKind.Label) slot++;
|
||||
return slot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把一条记录的标签数组按<b>标签列个数</b>定长——这是"记录标签长度"唯一的定义处:
|
||||
/// 按位置逐格搬(不是按列号搬:列号已经被调用方换算过),短的补空串、长的截掉。
|
||||
/// <b>加/删列之后重排就靠它</b>,所以各写入路径不许各自 Copy 一遍。
|
||||
/// </summary>
|
||||
public static string[] SizedLabels(IReadOnlyList<string> labels, int labelCount)
|
||||
{
|
||||
if (labelCount < 0) labelCount = 0;
|
||||
var copy = new string[labelCount];
|
||||
// 空位一律写空串,不写 null:null 与 "" 在窗口里都显示为空,却在"这一格是空的"这条判据上
|
||||
// 各答一套(导入写出的是 "",而这里补 null,往返一次就变了样)。
|
||||
for (int i = 0; i < labelCount; i++)
|
||||
copy[i] = labels != null && i < labels.Count ? labels[i] : string.Empty;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>反方向:标签下标属于表里哪一列(拿到那一列的定义)——与 <see cref="DefinitionOfValueSlot"/> 对称</summary>
|
||||
public static XChartDimensionDefinition DefinitionOfLabelSlot(
|
||||
IReadOnlyList<XChartDimensionDefinition> dimensions, int labelSlot)
|
||||
{
|
||||
if (dimensions == null || labelSlot < 0) return null;
|
||||
int slot = 0;
|
||||
for (int i = 0; i < dimensions.Count; i++)
|
||||
{
|
||||
var candidate = dimensions[i];
|
||||
if (candidate == null || candidate.Kind != XChartDimensionKind.Label) continue;
|
||||
if (slot == labelSlot) return candidate;
|
||||
slot++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user