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:
+46
-116
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user