feat(deps): 依赖连线自动错开 + 拖拽调整走线(三种视图);发布 v1.3.3

- 新增共享走线模块 lib/layout/dep_routes.dart:条形 / 圆周的走线、标签
  挂钩与外移判定、命中测试统一到同一份几何(绘制与命中不再各算一套);
- 自动错开:同一走线分组(同泳道 / 相邻泳道对 / 跨行对)内的多条依赖
  依次 ±6px 错开,解决“多条线完全重叠”;
- 手动走线偏移:Dependency.routeOffset(随工程保存)——
  · 条形 / 流程图:上下拖动平移横线,跨行走廊为左右拖动;
  · 圆周:沿半径方向(法线)拖动;
  · 直角拐点随平移保留,双击连线或右键「复位走线偏移」恢复自动位置;
  · 选中连线以强调色加粗高亮,状态栏给出操作提示;
- 画布命中判定改用「按下位置」(此前用手势验收点,细目标会抓空),
  端点把手与连线重叠时按“谁更近”判定优先级;
- 帮助中心补充「连线重叠怎么办」;版本号 1.3.3+19;
  更新说明 release/RELEASE_NOTES_v1.3.3.md。
This commit is contained in:
2026-10-09 21:27:40 +08:00
parent c352af2359
commit b902fa06c4
15 changed files with 920 additions and 233 deletions
+46 -116
View File
@@ -19,6 +19,7 @@ import 'dart:ui' as ui;
import 'package:flutter/material.dart' hide Action;
import '../layout/dep_routes.dart';
import '../layout/layout.dart';
import '../model/models.dart';
import '../model/units.dart';
@@ -37,6 +38,7 @@ class BarPainter extends CustomPainter {
/// - [criticalActions]:关键路径上的动作 id 集合,用于描边高亮。
/// - [criticalDeps]:关键路径上的依赖集合,键格式 `fromId->toId`。
/// - [selectedId]:当前选中动作 id,可为空。
/// - [selectedDep]:当前选中的依赖连线键(`from->to`),用于高亮。
///
/// 无副作用;实例不缓存布局,每次 [paint] 都重新计算。
BarPainter({
@@ -45,6 +47,7 @@ class BarPainter extends CustomPainter {
required this.criticalActions,
required this.criticalDeps,
required this.selectedIds,
this.selectedDep,
this.guideAngle,
this.dropLane,
this.dropValid = true,
@@ -61,6 +64,9 @@ class BarPainter extends CustomPainter {
/// 当前选中的动作 id 集合(支持多选)。
final Set<String> selectedIds;
/// 当前选中的依赖连线键(`from->to`);非空时该走线以强调色高亮。
final String? selectedDep;
/// 拖拽相位分区边界时的参考角(度);非空时绘制一条竖直虚线参考。
final double? guideAngle;
@@ -420,131 +426,55 @@ class BarPainter extends CustomPainter {
///
/// 参数 [layout] 提供条块矩形;[u] 当前未直接使用,保留以对齐调用接口。
void _deps(Canvas canvas, BarLayout layout, UnitSettings u) {
final List<Action> ordered = layout.ordered;
// 以「泳道序号」判断依赖的相邻关系(同泳道多个动作不再误判)。
final Map<String, int> index = <String, int>{
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
};
int k = 0;
// 走线统一由 [buildBarDepRoutes] 计算:同组自动错开 + 手动偏移,
// 与画布的命中测试 / 拖拽调整共用同一份几何。
final List<BarDepRoute> routes = buildBarDepRoutes(project, layout);
// 依赖标签先收集、后统一避让放置(见方法末尾 _placeChips)。
final List<_ChipSpec> chips = <_ChipSpec>[];
for (final Action to in ordered) {
for (final Dependency d in to.deps) {
final Action? from = project.actionById(d.fromId);
if (from == null) continue;
final int ia = index[from.id] ?? 0;
final int ib = index[to.id] ?? 0;
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
final bool crit = criticalDeps.contains('${d.fromId}->${d.toId}');
// 标签缩短 + 字号收小,减少占位与相互遮挡(关键路径已由线条光晕表示)。
final String label = switch (d.type) {
DepType.fs => 'FS',
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
DepType.ff => 'FF',
DepType.sf => 'SF',
};
final double chipW = _tp(label, 8.5, col, FontWeight.w600).width + 12;
final Rect ra = layout.rectFor(from);
final Rect rb = layout.rectFor(to);
const double barHalf = BarLayout.barH / 2;
final double sy = ra.center.dy;
final double ty = rb.center.dy;
final double dir = ty > sy ? 1 : -1;
// 箭头落点:目标条块靠源一侧外缘再留 3px。
final double tipY = ty - dir * (barHalf + 3);
final Path p = Path();
double chipX;
double chipY;
Offset arrowTip;
Offset arrowDir;
// 同一泳道内的依赖(源/目标同 y):箭头连接两色块的外侧边缘。
final bool sameLane = (ty - sy).abs() < 1;
if (sameLane) {
final bool fs = d.type == DepType.fs;
final double startX = fs ? ra.right + 2 : ra.left - 2;
double endX = rb.left - 2;
if (endX < startX) endX = rb.right + 2;
p.moveTo(startX, sy);
p.lineTo(endX, sy);
arrowTip = Offset(endX, sy);
arrowDir = Offset(endX >= startX ? 1 : -1, 0);
chipX = (startX + endX) / 2;
chipY = sy - (barHalf + 9);
// 两动作间距太短、图注放不下时,自动移到箭头右侧。
if ((endX - startX).abs() < chipW + 8) chipX = endX + chipW / 2 + 6;
} else if ((ib - ia).abs() <= 1) {
// 相邻泳道:在两泳道之间的空隙中线走水平线,箭头指向目标条块。
final double mid = (sy + ty) / 2;
final double sx = d.type == DepType.fs ? ra.right : ra.left;
final double ex = d.type == DepType.fs ? sx - 9 : sx + 9;
final double tx = rb.left + 14;
p.moveTo(ex, sy + dir * (barHalf + 2));
p.lineTo(ex, mid);
p.lineTo(tx, mid);
p.lineTo(tx, tipY);
arrowTip = Offset(tx, tipY);
arrowDir = Offset(0, dir);
chipX = (ex + tx) / 2;
chipY = mid;
if ((tx - ex).abs() < chipW + 10) chipX = tx + chipW / 2 + 6;
} else {
// 跨多行:扫描区间内所有条块边界,据此在外侧选一条竖直泳道。
final double sx = d.type == DepType.fs ? ra.right : ra.left;
final double ex = d.type == DepType.fs ? sx - 9 : sx + 9;
final double tx = rb.left + 14;
double maxRight = 0;
double minLeft = double.infinity;
final List<int> lanes = layout.lanes;
for (int r = math.min(ia, ib) + 1; r < math.max(ia, ib); r++) {
if (r < 0 || r >= lanes.length) continue;
for (final Action aa in layout.actionsInLane(lanes[r])) {
final Rect rr = layout.rectFor(aa);
maxRight = math.max(maxRight, rr.right);
minLeft = math.min(minLeft, rr.left);
}
}
double lane = math.max(math.max(sx, tx), maxRight) + 28 + (k % 3) * 16;
if (lane > layout.plotRight - 16) {
lane = math.min(math.min(sx, tx), minLeft) - 28 - (k % 3) * 16;
}
final double srcGapY = sy + dir * (barHalf + 14);
final double gapY = ty - dir * (barHalf + 6);
p.moveTo(ex, sy + dir * (barHalf + 2));
p.lineTo(ex, srcGapY);
p.lineTo(lane, srcGapY);
p.lineTo(lane, gapY);
p.lineTo(tx, gapY);
p.lineTo(tx, tipY);
arrowTip = Offset(tx, tipY);
arrowDir = Offset(0, dir);
chipX = (lane + tx) / 2;
chipY = gapY - (barHalf + 1);
}
// 关键路径依赖:先铺一层加粗低透明度光晕,再画主线。
if (crit) {
canvas.drawPath(
p,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 5
..strokeCap = StrokeCap.round
..color = col.withValues(alpha: 0.18),
);
}
for (final BarDepRoute r in routes) {
final Dependency d = r.dep;
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
final bool crit = criticalDeps.contains(r.key);
final bool sel = selectedDep == r.key;
final Color draw = sel ? tokens.accent : col;
final Path p = Path()
..moveTo(r.points.first.dx, r.points.first.dy);
for (int i = 1; i < r.points.length; i++) {
p.lineTo(r.points[i].dx, r.points[i].dy);
}
// 关键路径依赖:先铺一层加粗低透明度光晕,再画主线。
if (crit) {
canvas.drawPath(
p,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = crit ? 1.1 : 0.85
..strokeWidth = 5
..strokeCap = StrokeCap.round
..color = col.withValues(alpha: 0.95),
..color = col.withValues(alpha: 0.18),
);
_arrow(canvas, arrowTip, arrowDir, col);
// 先记录标签位置,所有依赖线画完后统一避让放置(避免标签互相重叠)。
chips.add(_ChipSpec(Offset(chipX, chipY), label, col));
k++;
}
canvas.drawPath(
p,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = sel ? 2.0 : (crit ? 1.1 : 0.85)
..strokeCap = StrokeCap.round
..color = sel ? draw : draw.withValues(alpha: 0.95),
);
_arrow(canvas, r.arrowTip, r.arrowDir, draw);
final String label = switch (d.type) {
DepType.fs => 'FS',
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
DepType.ff => 'FF',
DepType.sf => 'SF',
};
// 行程太短的连线:标签移到箭头外侧(宽度按真实字号精确测量)。
final double chipW = _tp(label, 8.5, draw, FontWeight.w600).width + 12;
final Offset chipCenter = r.chipRun < chipW + r.chipRunMargin
? Offset(r.chipAltAnchor.dx + chipW / 2, r.chipAltAnchor.dy)
: r.chipCenter;
// 先记录标签位置,所有依赖线画完后统一避让放置(避免标签互相重叠)。
chips.add(_ChipSpec(chipCenter, label, draw));
}
_placeChips(canvas, chips);
}
+24 -66
View File
@@ -15,6 +15,7 @@ import 'dart:ui' as ui;
import 'package:flutter/material.dart' hide Action;
import '../layout/dep_routes.dart';
import '../layout/layout.dart';
import '../model/models.dart';
import '../model/units.dart';
@@ -40,6 +41,7 @@ class CircularPainter extends CustomPainter {
required this.criticalActions,
required this.criticalDeps,
required this.selectedIds,
this.selectedDep,
this.guideAngle,
});
@@ -54,6 +56,9 @@ class CircularPainter extends CustomPainter {
/// 当前选中的动作 id 集合(支持多选)。
final Set<String> selectedIds;
/// 当前选中的依赖连线键(`from->to`);非空时该走线以强调色高亮。
final String? selectedDep;
/// 拖拽动作弧端点时的参考角(度);非空时绘制一条径向虚线参考。
final double? guideAngle;
@@ -131,12 +136,13 @@ class CircularPainter extends CustomPainter {
// 依赖连线先于动作弧绘制,使其位于弧之下、不被遮挡。
if (project.viewState.showDeps) {
// 走线统一由 [buildArcDepRoutes] 计算(同组自动错开 + 手动径向偏移),
// 与画布命中测试 / 拖拽调整共用同一份几何。
final List<ArcDepRoute> routes = buildArcDepRoutes(project, layout);
final List<_ArcChip> chips = <_ArcChip>[];
for (final Action to in project.actions) {
for (final Dependency d in to.deps) {
final _ArcChip? chip = _dep(canvas, layout, d);
if (chip != null) chips.add(chip);
}
for (final ArcDepRoute r in routes) {
final _ArcChip? chip = _drawDepRoute(canvas, layout, r);
if (chip != null) chips.add(chip);
}
_placeArcChips(canvas, layout, chips);
}
@@ -423,64 +429,18 @@ class CircularPainter extends CustomPainter {
return p;
}
/// 绘制圆形视图中的依赖连线。
/// 绘制一条圆周依赖走线(几何来自 [ArcDepRoute],与命中测试 / 拖拽共用)。
///
/// 路径由四段组成:从源弧末端沿半径到中间半径 [rC] → 沿圆弧走到目标弧
/// 起点角度 → 再沿半径落到目标弧表面([rTip])→ 末端加箭头。
/// - 相邻层取两层半径均值作为 [rC];层差大于 1 时改用最外圈 `rMax+24` 绕行。
/// - [large]/[cw] 决定圆弧走大弧还是小弧、顺时针还是逆时针。
/// - 关键依赖先画低透明度粗描边,再画主线,最后放置 `A→B 类型` 胶囊。
_ArcChip? _dep(Canvas canvas, CircularLayout layout, Dependency d) {
final Action? A = project.actionById(d.fromId);
final Action? B = project.actionById(d.toId);
if (A == null || B == null) return null;
final Offset c = layout.center;
final double rA = layout.radiusFor(A.layer);
final double rB = layout.radiusFor(B.layer);
final double aEnd = math.min(A.endAngle, 360);
final double aStart = B.startAngle;
// 层差大于 1 时从最外圈绕行,避免穿过中间层弧线。
final bool skip = (A.layer - B.layer).abs() > 1;
final double rC = skip ? layout.rMax + 24 : (rA + rB) / 2;
final bool cw = aStart >= aEnd;
final int large = (aStart - aEnd).abs() > 180 ? 1 : 0;
final Offset p0 = polar(c, rA, aEnd);
final Offset p1 = polar(c, rC, aEnd);
final Offset p2 = polar(c, rC, aStart);
final double rTip = rC < rB ? rB - layout.th / 2 - 4 : rB + layout.th / 2 + 4;
final Offset p3 = polar(c, rTip, aStart);
/// 关键依赖先画低透明度粗描边、再画主线;选中的连线以强调色加粗高亮。
/// 标签不在此处直接绘制:收集后统一避让放置(见 [_placeArcChips])。
_ArcChip? _drawDepRoute(Canvas canvas, CircularLayout layout, ArcDepRoute r) {
final Dependency d = r.dep;
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
final bool crit = criticalDeps.contains('${d.fromId}->${d.toId}');
// 起止角相同(FS 紧随其后)时路径会退化为一条从圆心附近拉出的径向直线,
// 看起来像“杂线”。此时改为贴近目标环的**短箭头**,并让标签旁移。
final bool degenerate = (aStart - aEnd).abs() < 0.5;
final Path p;
final Offset tipDir;
final double chipR;
final double chipDeg;
if (degenerate) {
final double r0 = rTip - (rTip > rB ? 28 : -28);
final Offset q0 = polar(c, r0, aStart);
p = Path()
..moveTo(q0.dx, q0.dy)
..lineTo(p3.dx, p3.dy);
tipDir = p3 - q0;
// 标签放在源环与目标环之间的径向空隙中,沿切向排布。
chipR = (rA + rB) / 2;
chipDeg = aStart;
} else {
p = Path()
..moveTo(p0.dx, p0.dy)
..lineTo(p1.dx, p1.dy)
..arcToPoint(p2, radius: Radius.circular(rC), largeArc: large == 1, clockwise: cw)
..lineTo(p3.dx, p3.dy);
tipDir = p3 - p2;
final double span = (aStart - aEnd).abs();
chipR = skip ? rC : (span < 30 ? rB + layout.th / 2 + 10 : rC);
chipDeg = (aEnd + aStart) / 2;
}
final bool crit = criticalDeps.contains(r.key);
final bool sel = selectedDep == r.key;
final Color draw = sel ? tokens.accent : col;
final Path p = r.buildPath();
if (crit) {
canvas.drawPath(
p,
@@ -495,18 +455,16 @@ class CircularPainter extends CustomPainter {
p,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9)
..strokeWidth = sel ? 2.2 : (crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9))
..strokeCap = StrokeCap.round
..color = col,
..color = draw,
);
_arrow(canvas, p3, tipDir, col);
_arrow(canvas, r.p3, r.tipDir, draw);
String label = d.type == DepType.fs ? 'FS' : 'SS+${d.offsetAngle.toStringAsFixed(0)}°';
if (d.type == DepType.ff) label = 'FF';
if (d.type == DepType.sf) label = 'SF';
// 标签不在此处直接绘制:收集后统一避让放置(见 [_placeArcChips]),
// 字号收小、取消五角星,避免多个依赖(尤其 FS 与 SS 并存)互相压盖。
return _ArcChip(chipR, chipDeg, '${A.id}→${B.id} $label', col);
return _ArcChip(r.chipR, r.chipDeg, '${d.fromId}→${d.toId} $label', draw);
}
/// 统一绘制圆周视图的依赖标签:沿半径方向逐级外移 / 内移避让,避免相互重叠。
+11 -4
View File
@@ -22,6 +22,7 @@ class FlowchartPainter extends CustomPainter {
required this.criticalActions,
required this.criticalDeps,
required this.selectedIds,
this.selectedDep,
});
/// 项目数据。
@@ -35,6 +36,9 @@ class FlowchartPainter extends CustomPainter {
/// 选中动作 id。
final Set<String> selectedIds;
/// 当前选中的依赖连线键(`from->to`);非空时该走线以强调色高亮。
final String? selectedDep;
@override
void paint(Canvas canvas, Size size) {
final FlowLayout layout = FlowLayout(
@@ -112,6 +116,9 @@ class FlowchartPainter extends CustomPainter {
final Color col = e.type == null
? tokens.sub
: (e.type == DepType.fs ? tokens.fs : tokens.ss);
// 选中的依赖连线以强调色加粗高亮(拖拽调整走线时可见)。
final bool sel = selectedDep == r.key;
final Color draw = sel ? tokens.accent : col;
final Path p = Path()..moveTo(r.points.first.dx, r.points.first.dy);
for (int i = 1; i < r.points.length; i++) {
p.lineTo(r.points[i].dx, r.points[i].dy);
@@ -129,16 +136,16 @@ class FlowchartPainter extends CustomPainter {
}
final Paint line = Paint()
..style = PaintingStyle.stroke
..strokeWidth = e.critical ? 1.8 : 1.2
..strokeWidth = sel ? 2.4 : (e.critical ? 1.8 : 1.2)
..strokeJoin = StrokeJoin.round
..strokeCap = StrokeCap.round
..color = col.withValues(alpha: e.type == null ? 0.7 : 0.95);
..color = sel ? draw : draw.withValues(alpha: e.type == null ? 0.7 : 0.95);
if (r.dashed) {
_dashPath(canvas, p, line);
} else {
canvas.drawPath(p, line);
}
_arrow(canvas, r.tip, r.dir, col);
_arrow(canvas, r.tip, r.dir, draw);
// FS / SS+偏移 标签
if (e.type != null) {
final String text = switch (e.type!) {
@@ -147,7 +154,7 @@ class FlowchartPainter extends CustomPainter {
DepType.ff => 'FF',
DepType.sf => 'SF',
};
_chip(canvas, r.labelAt, text, col);
_chip(canvas, r.labelAt, text, draw);
}
}
}