feat(flow): 泳道拓宽计划(空泳道策略 + 多槽位泳道,三视图同步);发布 v1.3.4

- 空泳道策略(F2 文档设置 →「泳道」):动作全部移走的泳道可保留(默认,序号不变)
  或自动移除;条形空行 / 圆周空环 / 流程空列与左侧栏占位行同步
- 泳道加宽(1–5 槽):双击条形视图左侧泳道编号 / 右键空白泳道 / 左侧栏「N 槽」徽标;
  条形分子行(浅色虚线分隔)、圆周同色加宽环带 + 槽位虚线、流程图分子列且泳道带
  随内容智能加宽;拖拽动作同时换道 + 换槽位;旧数据零迁移(row 语义改为槽位并自动钳制)
- 流程图智能排开:同源同层扇出连线在空隙内均匀铺开;同层节点水平重叠自动推开
- 显示修复:画布左栏标题按真实行高排版(灰色副标题不再被换行标题压住,
  持续换行到泳道高度不足);多槽位采用「槽位紧凑 + 泳道间拉开」的间隔
- 「时序创建和编辑」更名为「文档设置」(含对话框标题/帮助/文档);新增自动保存
  (默认 10 分钟,可选 1/5/10/30 或关闭;写入文件并同步 .bak)
- 授权临时冻结(kLicenseRequired=false):桌面版导出无需 .lic;关于页授权状态
  「开放授权版本」、EDC 版权、开发者与交流群(邮箱 liuyu65@126.com、微信 online-goose)
- 更新体验:直接升级到最新版本提示、下载过程保持屏幕常亮提示、
  下载/上传统一限速 320KB/s(客户端限速 + 发布脚本 --limit-rate 320k)
- docs/HELP.md 与帮助中心同步更新;新增 docs/ROADMAP.md 开发路线图
- flutter analyze 0 问题、40 项测试全过;演示截图更新(含泳道加宽与拥挤场景验证图)
This commit is contained in:
2026-10-10 09:21:45 +08:00
parent b902fa06c4
commit fe5e0be131
27 changed files with 1390 additions and 245 deletions
+2 -2
View File
@@ -314,8 +314,8 @@ List<ArcDepRoute> buildArcDepRoutes(Project project, CircularLayout layout) {
final Action? a = project.actionById(d.fromId);
final Action? b = project.actionById(d.toId);
if (a == null || b == null) continue;
final double rA = layout.radiusFor(a.layer);
final double rB = layout.radiusFor(b.layer);
final double rA = layout.radiusFor(a.layer, layout.slotOf(a));
final double rB = layout.radiusFor(b.layer, layout.slotOf(b));
final double aEnd = math.min(a.endAngle, 360);
final double aStart = b.startAngle;
// 层差大于 1 时从最外圈绕行,避免穿过中间层弧线。
+143 -10
View File
@@ -180,6 +180,40 @@ class FlowLayout {
/// 内容范围(所有节点矩形并集再外扩,供适应视图使用)。
Rect bounds = Rect.zero;
/// 泳道内两个槽位之间的横向间距(留出依赖连线的走线空间)。
static const double slotGap = 26;
/// 各泳道左边缘 x(放置完成后按内容自适应填充)。
final List<double> laneStarts = <double>[];
/// 各泳道宽度(基础 = 槽位数,放置后按内容自动加宽)。
final List<double> laneWidths = <double>[];
/// 第 [li] 条泳道的宽度(优先取内容自适应结果;未计算时按槽位数)。
double laneWidth(int li) {
if (li >= 0 && li < laneWidths.length) return laneWidths[li];
if (li < 0 || li >= lanes.length) return nodeW;
final int s = project.slotsOf(lanes[li]);
return s * nodeW + (s - 1) * slotGap;
}
/// 第 [li] 条泳道左边缘 x(优先取内容自适应结果,其次按槽位宽度累加)。
double laneStartX(int li) {
if (li >= 0 && li < laneStarts.length) return laneStarts[li];
double x = marginX;
for (int i = 0; i < li && i < lanes.length; i++) {
x += laneWidth(i) + laneGap;
}
return x;
}
/// 第 [li] 条泳道第 [slot] 列的节点中心 x(槽位钳制到有效范围)。
double slotCenterX(int li, int slot) {
final int s = (li >= 0 && li < lanes.length) ? project.slotsOf(lanes[li]) : 1;
final int k = slot < 0 ? 0 : (slot >= s ? s - 1 : slot);
return laneStartX(li) + k * (nodeW + slotGap) + nodeW / 2;
}
/// 按 id 查找节点。
FlowNode? nodeById(String id) {
for (final FlowNode n in nodes) {
@@ -198,7 +232,7 @@ class FlowLayout {
/// 构建节点、连线并完成布局。
void _build() {
lanes = (<int>{for (final Action a in project.actions) a.layer}.toList())..sort();
lanes = project.renderLanes;
final Map<String, FlowNode> byId = <String, FlowNode>{};
// 1) 动作节点(序号与条形视图一致:项目动作列表顺序 + 1)。
@@ -290,7 +324,18 @@ class FlowLayout {
cellTotal[key] = (cellTotal[key] ?? 0) + 1;
}
final Map<String, int> cellSeen = <String, int>{};
final double lanePitch = nodeW + laneGap;
// 泳道基础几何:宽度按槽位数,左边缘按前一泳道宽度累加。
laneStarts.clear();
laneWidths.clear();
{
double x = marginX;
for (int i = 0; i < lanes.length; i++) {
final int s = project.slotsOf(lanes[i]);
laneStarts.add(x);
laneWidths.add(s * nodeW + (s - 1) * slotGap);
x += laneWidths.last + laneGap;
}
}
for (final FlowNode n in nodes) {
final int li = laneIndex[n.lane] ?? 0;
final String key = '${n.lane}:${n.rank}';
@@ -299,15 +344,91 @@ class FlowLayout {
cellSeen[key] = idx + 1;
final double w = (n.isStart || n.isEnd) ? capW : nodeW;
final double h = (n.isStart || n.isEnd) ? capH : nodeH;
final double centerX = marginX + li * lanePitch + nodeW / 2 +
(idx - (total - 1) / 2) * (nodeW * 0.62);
// 开始 / 结束节点居中于泳道带;动作节点按(泳道, 槽位)分列,
// 同格多节点再沿横向错开。
final double centerX;
if (n.isStart || n.isEnd) {
centerX = laneStartX(li) + laneWidth(li) / 2;
} else {
final int slot = effectiveSlot(project, n.action!);
centerX = slotCenterX(li, slot) + (idx - (total - 1) / 2) * (nodeW * 0.62);
}
final double top = marginY + n.rank * (nodeH + rankGap) + (nodeH - h) / 2;
n.rect = Rect.fromLTWH(centerX - w / 2, top, w, h);
}
// 同层智能排开:同一 rank 行内若有水平重叠(同格多节点 / 跨列挤出),
// 从左到右依次推开,保证节点之间至少留 10px,避免“堆叠到一起看不清”。
final Map<int, List<FlowNode>> byRank = <int, List<FlowNode>>{};
for (final FlowNode n in nodes) {
byRank.putIfAbsent(n.rank, () => <FlowNode>[]).add(n);
}
for (final List<FlowNode> row in byRank.values) {
row.sort((FlowNode a, FlowNode b) => a.rect.left.compareTo(b.rect.left));
for (int i = 1; i < row.length; i++) {
final FlowNode prev = row[i - 1];
final FlowNode cur = row[i];
final double minLeft = prev.rect.right + 10;
if (cur.rect.left < minLeft) {
cur.rect = cur.rect.shift(Offset(minLeft - cur.rect.left, 0));
}
}
}
// 泳道带按内容**智能加宽**:若某泳道的节点被推到基础宽度之外,
// 先按内容算出需要的加宽量,再把该泳道及其后所有泳道整体右移,
// 保证底部泳道带完整覆盖自己的动作节点(与条形 / 圆周视图的观感一致)。
final List<double> extra = List<double>.filled(lanes.length, 0);
for (int i = 0; i < lanes.length; i++) {
double contentRight = double.negativeInfinity;
for (final FlowNode n in nodes) {
if ((laneIndex[n.lane] ?? 0) == i) {
contentRight = math.max(contentRight, n.rect.right);
}
}
if (contentRight.isFinite) {
final double need = contentRight + 26 - (laneStarts[i] + laneWidths[i]);
if (need > 0) extra[i] = need;
}
}
if (extra.any((double e) => e > 0)) {
double delta = 0;
for (int i = 0; i < lanes.length; i++) {
if (delta != 0) {
for (final FlowNode n in nodes) {
if ((laneIndex[n.lane] ?? 0) == i) {
n.rect = n.rect.shift(Offset(delta, 0));
}
}
laneStarts[i] += delta;
}
laneWidths[i] += extra[i];
// 泳道加宽后,开始 / 结束胶囊重新居中于泳道带。
if (extra[i] > 0) {
for (final FlowNode n in nodes) {
if ((n.isStart || n.isEnd) && (laneIndex[n.lane] ?? 0) == i) {
final double cx = laneStarts[i] + laneWidths[i] / 2;
n.rect = Rect.fromLTWH(
cx - n.rect.width / 2, n.rect.top, n.rect.width, n.rect.height);
}
}
}
delta += extra[i];
}
}
// 6) 连线走线:画布绘制 / SVG / drawio 导出共用(同源同层分支扇形错位)。
// 依赖上保存的手动走线偏移(routeOffset)在此叠加:
// 向下流为竖直偏移(拖动横线),同层绕行为水平偏移(拖动纵向走廊)。
// 同源同层的多条分支预先分组,横线在可用空隙内**均匀铺开**,
// 分支多时不再全部挤在同一条线上(流程图“智能排开”)。
final Map<String, List<FlowEdge>> fanGroups = <String, List<FlowEdge>>{};
for (final FlowEdge e in edges) {
final FlowNode? a = byId[e.fromId];
final FlowNode? b = byId[e.toId];
if (a == null || b == null || b.rank <= a.rank) continue;
fanGroups.putIfAbsent('${e.fromId}:${b.rank}', () => <FlowEdge>[]).add(e);
}
final Map<String, int> fanIndex = <String, int>{};
for (final FlowEdge e in edges) {
final FlowNode? a = byId[e.fromId];
@@ -325,14 +446,26 @@ class FlowLayout {
}
if (b.rank > a.rank) {
final String key = '${e.fromId}:${b.rank}';
final List<FlowEdge> group = fanGroups[key] ?? <FlowEdge>[e];
final int idx = fanIndex[key] ?? 0;
fanIndex[key] = idx + 1;
// 横线高度:扇形错开 + 手动偏移,限制在源/目标两行之间的空隙内。
double lane = math.min(
(a.rect.bottom + b.rect.top) / 2 + idx * 14 + routeOffset,
b.rect.top - 8,
);
if (lane < a.rect.bottom + 10) lane = a.rect.bottom + 10;
// 横线高度:单条分支沿用“空隙中线”;多条分支在
// [源底 + 10, 目标顶 - 8] 内均匀铺开(第 idx+1 / n+1 份),再叠加手动偏移。
final double gapLow = a.rect.bottom + 10;
double gapHigh = double.infinity;
for (final FlowEdge ge in group) {
final FlowNode? gb = byId[ge.toId];
if (gb != null && gb.rect.top - 8 < gapHigh) gapHigh = gb.rect.top - 8;
}
double lane;
if (group.length <= 1) {
lane = math.min((a.rect.bottom + b.rect.top) / 2 + routeOffset, b.rect.top - 8);
} else {
final double span = math.max(gapHigh - gapLow, 8);
lane = gapLow + span * (idx + 1) / (group.length + 1) + routeOffset;
}
if (lane < gapLow) lane = gapLow;
if (lane > gapHigh) lane = gapHigh;
final double x0 = a.rect.center.dx;
final double x1 = b.rect.center.dx;
routes.add(FlowEdgeRoute(
+166 -44
View File
@@ -95,6 +95,16 @@ bool angleRangesOverlap(double s1, double e1, double s2, double e2) {
return false;
}
/// 动作 [a] 在 [project] 中其泳道内的有效槽位(与泳道槽位数钳制一致)。
///
/// 1 槽泳道恒为 0;旧数据中的历史行序(超出范围 / -1)会被钳制到有效槽位。
int effectiveSlot(Project project, Action a) {
final int slots = project.slotsOf(a.layer);
if (slots <= 1) return 0;
final int r = a.row;
return r < 0 ? 0 : (r >= slots ? slots - 1 : r);
}
/// 条形(甘特)视图布局。
///
/// 横轴为相位角(0°–360°),纵轴为动作行。行顺序由 [ordered] 决定,
@@ -105,14 +115,23 @@ class BarLayout {
/// 参数 [project]:项目数据;[size]:可用画布尺寸。
/// 副作用:初始化 [pitch]。
BarLayout(this.project, this.size) {
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**泳道数**均分并夹取到 [44, 58],
// 让相邻泳道之间的空隙能容纳依赖连线及其标签(上限定得高一些,
// 泳道少时获得更多垂直间隙,减少标签相互压盖)。
final int n = lanes.length;
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**总子行数**(各泳道槽位数之和)
// 均分并夹取到 [44, 58];单槽泳道时与旧版行为完全一致。
// 多槽位工程采用「组内紧凑 + 泳道间拉开」:子行更紧、泳道之间额外留白,
// 一眼能看出哪些子行属于同一条泳道。
final int n = subRowCount;
final int laneN = lanes.length;
final double extraTotal = _grouped && laneN > 1 ? (laneN - 1) * laneExtraGap : 0;
final double usable = size.height - topPad - bottomReserve;
pitch = n == 0 ? 58 : (usable / n).clamp(44, 58);
pitch = n == 0 ? 58 : ((usable - extraTotal) / n).clamp(_grouped ? 36 : 44, 58);
}
/// 是否启用「组内紧凑 + 泳道间拉开」的间隔分组(仅多槽位工程)。
bool get _grouped => project.hasMultiSlotLanes;
/// 泳道之间的额外纵向留白(仅多槽位分组时生效,像素)。
static const double laneExtraGap = 16;
/// 布局所依据的项目数据。
final Project project;
@@ -149,12 +168,10 @@ class BarLayout {
/// 决定行先后的动作列表;见顶层函数 [orderActions]。
List<Action> get ordered => orderActions(project);
/// 泳道编号(= 物理执行器轨道):所有动作 `layer` 的去重升序列表。
List<int> get lanes {
final Set<int> s = <int>{for (final Action a in project.actions) a.layer};
final List<int> l = s.toList()..sort();
return l;
}
/// 泳道编号(= 物理执行器轨道):来自 [Project.renderLanes]。
///
/// 开启「保留空泳道」时包含动作已全部移走的空泳道(序号不变)。
List<int> get lanes => project.renderLanes;
/// 泳道号在 [lanes] 中的序号。
int laneIndexOf(int lane) => lanes.indexOf(lane);
@@ -163,17 +180,65 @@ class BarLayout {
List<Action> actionsInLane(int lane) =>
ordered.where((Action a) => a.layer == lane).toList();
/// 泳道号转纵坐标(该泳道顶部 y)。
double yForLane(int lane) => topPad + laneIndexOf(lane) * pitch;
/// 泳道 [lane] 的槽位数(1–5)。
int slotsOf(int lane) => project.slotsOf(lane);
/// 行索引转纵坐标(按泳道序号)。
double yFor(int index) => topPad + index * pitch;
/// 动作 [a] 的实际槽位(钳制到所属泳道的有效范围;1 槽泳道恒为 0)。
int slotOf(Action a) => effectiveSlot(project, a);
/// 全部泳道的子行总数(Σ 槽位)。
int get subRowCount {
int n = 0;
for (final int lane in lanes) {
n += slotsOf(lane);
}
return n;
}
/// 泳道 [lane] 之前(不含)的纵向高度(子行 + 分组留白)。
double _laneOffsetBefore(int lane) {
double h = 0;
for (final int l in lanes) {
if (l == lane) break;
h += slotsOf(l) * pitch + (_grouped ? laneExtraGap : 0);
}
return h;
}
/// 泳道号转纵坐标(该泳道顶部 y)。
double yForLane(int lane) => topPad + _laneOffsetBefore(lane);
/// 泳道内槽位转纵坐标(该槽位所在子行的顶部 y)。
double yForSlot(int lane, int slot) => yForLane(lane) + slot * pitch;
/// 内容底部 y(最后一个子行之后)。
double get plotBottom {
double h = subRowCount * pitch;
if (_grouped && lanes.length > 1) h += (lanes.length - 1) * laneExtraGap;
return topPad + h;
}
/// 由纵坐标反查最近的泳道号(用于拖拽换道)。
int laneAt(double y) {
if (lanes.isEmpty) return 0;
final int i = ((y - topPad) / pitch).round().clamp(0, lanes.length - 1);
return lanes[i];
int laneAt(double y) => laneSlotAt(y).$1;
/// 由纵坐标反查(泳道号, 槽位)——拖拽换道 / 换槽位时使用。
(int, int) laneSlotAt(double y) {
if (lanes.isEmpty) return (0, 0);
double top = topPad;
for (int li = 0; li < lanes.length; li++) {
final int lane = lanes[li];
final int s = slotsOf(lane);
final double h = s * pitch;
// 泳道之间的额外留白按半份归属本道,保证指针落在空隙中也能命中相邻泳道。
final double boundary =
top + h + (_grouped && li < lanes.length - 1 ? laneExtraGap * 0.5 : 0);
if (y < boundary || li == lanes.length - 1) {
final int slot = ((y - top) / pitch).round().clamp(0, s - 1);
return (lane, slot);
}
top += h + (_grouped ? laneExtraGap : 0);
}
return (lanes.last, slotsOf(lanes.last) - 1);
}
/// 相位角(度)转横坐标;角度先钳制到 `[0, 360]`。
@@ -183,7 +248,7 @@ class BarLayout {
///
/// 宽度至少为 3px,避免极短动作不可见;跨圈部分会被截断到 360°。
Rect rectFor(Action a) {
final double y = yForLane(a.layer);
final double y = yForSlot(a.layer, slotOf(a));
final double x0 = xFor(a.startAngle);
final double x1 = xFor(math.min(a.endAngle, 360));
return Rect.fromLTWH(x0, y, math.max(x1 - x0, 3), barH);
@@ -217,18 +282,29 @@ class CircularLayout {
CircularLayout(this.project, this.size) {
// 圆心略微下移 18px 以平衡顶部刻度标签的视觉重心。
center = Offset(size.width / 2, size.height / 2 + 18);
// 轨道数 = 泳道数(layer 去重),同一轨道可放多个互不重叠的动作。
final int layers = lanes.length;
// 子环总数 = Σ 各轨道槽位数(泳道加宽后同一轨道可有多条并行子环);
// 单槽时与旧版(按轨道数)完全一致。
final int rings = subRingCount;
final int laneN = lanes.length;
// 多槽位工程采用「组内紧凑 + 轨道间拉开」:同一轨道的子环更紧、
// 轨道之间额外留白,一眼能看出哪些子环属于同一轨道。
final double extraTotal = _grouped && laneN > 1 ? (laneN - 1) * ringExtraGap : 0;
// 最大半径受较短边约束,减去 74px 留给刻度与边距。
final double maxR = math.min(size.width, size.height) / 2 - 74;
// 在 r0 与 maxR 之间均分各轨道,环间距夹取到 [32, 52]:
// 让相邻环之间留出足够空隙放置依赖箭头与图注。
pitch = layers <= 1 ? 46 : ((maxR - r0) / (layers - 1)).clamp(32, 56);
// 动作环带宽度:只求容纳文字(约 15–18px),环更窄、环间空隙更宽,
// 便于在环间放置依赖标签(减少与动作名、其它标签的压盖)。
ringWidth = (pitch * 0.42).clamp(14, 17);
// 在 r0 与 maxR 之间均分各子环,环间距夹取(多槽位时允许更紧)。
pitch = rings <= 1
? 46
: ((maxR - r0 - extraTotal) / (rings - 1)).clamp(_grouped ? 24 : 32, 56);
// 动作环带宽度:只求容纳文字;多槽位分组时子环更窄,轨道间靠留白区分。
ringWidth = (pitch * 0.42).clamp(_grouped ? 10 : 14, 17);
}
/// 是否启用「组内紧凑 + 轨道间拉开」的间隔分组(仅多槽位工程)。
bool get _grouped => project.hasMultiSlotLanes;
/// 轨道之间的额外径向留白(仅多槽位分组时生效,像素)。
static const double ringExtraGap = 18;
/// 布局所依据的项目数据。
final Project project;
@@ -247,31 +323,77 @@ class CircularLayout {
/// 环的视觉宽度(像素)。
late final double ringWidth;
/// 轨道编号(= 泳道):所有动作 `layer` 的去重升序列表。
List<int> get lanes {
final Set<int> s = <int>{for (final Action a in project.actions) a.layer};
final List<int> l = s.toList()..sort();
return l;
}
/// 轨道编号(= 泳道):来自 [Project.renderLanes](含保留的空轨道)。
List<int> get lanes => project.renderLanes;
/// 轨道号在 [lanes] 中的序号。
int laneIndexOf(int lane) => lanes.indexOf(lane);
/// 由半径反查最近的轨道号(用于拖拽换轨)。
int laneAtRadius(double r) {
if (lanes.isEmpty) return 0;
final int i = ((r - r0) / pitch).round().clamp(0, lanes.length - 1);
return lanes[i];
/// 轨道 [lane] 的槽位数(1–5)。
int slotsOf(int lane) => project.slotsOf(lane);
/// 动作 [a] 的实际槽位(钳制;1 槽轨道恒为 0)。
int slotOf(Action a) => effectiveSlot(project, a);
/// 全部轨道的子环总数(Σ 槽位)。
int get subRingCount {
int n = 0;
for (final int lane in lanes) {
n += slotsOf(lane);
}
return n;
}
/// 第 [lane] 条轨道对应的环半径(未知轨道回退到最内圈)。
double radiusFor(int lane) {
/// 轨道 [lane] 之前(不含)的子环数。
int subRingIndexOfLane(int lane) {
int n = 0;
for (final int l in lanes) {
if (l == lane) break;
n += slotsOf(l);
}
return n;
}
/// 由半径反查最近的轨道号(用于拖拽换轨)。
int laneAtRadius(double r) => laneSlotAtRadius(r).$1;
/// 由半径反查(轨道号, 槽位)——拖拽换轨 / 换子环时使用。
(int, int) laneSlotAtRadius(double r) {
if (lanes.isEmpty) return (0, 0);
double base = r0;
for (int li = 0; li < lanes.length; li++) {
final int lane = lanes[li];
final int s = slotsOf(lane);
final double h = s * pitch;
// 轨道之间的额外留白按半份归属本道,落在空隙中也能命中相邻轨道。
final double boundary =
base + h + (_grouped && li < lanes.length - 1 ? ringExtraGap * 0.5 : 0);
if (r < boundary || li == lanes.length - 1) {
final int slot = ((r - base) / pitch).round().clamp(0, s - 1);
return (lane, slot);
}
base += h + (_grouped ? ringExtraGap : 0);
}
return (lanes.last, slotsOf(lanes.last) - 1);
}
/// 轨道 [lane] 第 [slot] 条子环的半径(未知轨道回退到最内圈)。
double radiusFor(int lane, [int slot = 0]) {
final int i = laneIndexOf(lane);
return r0 + (i < 0 ? 0 : i) * pitch;
if (i < 0) return r0;
final int s = slotsOf(lane);
final int k = slot < 0 ? 0 : (slot >= s ? s - 1 : slot);
return r0 +
(subRingIndexOfLane(lane) + k) * pitch +
(_grouped ? i * ringExtraGap : 0);
}
/// 最外层半径。
double get rMax => lanes.isEmpty ? r0 : radiusFor(lanes.last);
double get rMax {
if (lanes.isEmpty) return r0;
final double extra = _grouped && lanes.length > 1 ? (lanes.length - 1) * ringExtraGap : 0;
return r0 + (subRingCount - 1) * pitch + extra;
}
/// 刻度标签所在的半径(最外层再向外偏移)。
/// 刻度环半径:在外层动作环之外留出足够间距,
@@ -292,7 +414,7 @@ class CircularLayout {
Action? best;
double bestDelta = double.infinity;
for (final Action a2 in project.actions) {
final double r = radiusFor(a2.layer);
final double r = radiusFor(a2.layer, slotOf(a2));
if ((d - r).abs() > ringWidth / 2 + slop) continue;
if (_inArc(a2, a)) {
final double delta = (d - r).abs();