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:
@@ -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);
|
||||
}
|
||||
|
||||
/// 统一绘制圆周视图的依赖标签:沿半径方向逐级外移 / 内移避让,避免相互重叠。
|
||||
|
||||
Reference in New Issue
Block a user