feat(flow): 新增流程图视图(时序图自动生成);导出合并为菜单并支持 drawio;发布 v1.3.0

- 流程图视图:泳道 = 轨道、FS/SS 依赖连线、关键路径高亮、相位阶段栏
  (每个动作行归属覆盖占比最大的分区,重叠分区台阶错位)
- 无前置依赖的动作从「开始」并列引出(并行分支),无后继动作汇入「结束」
- 流程图只读:AI 生成 / 撤销重做 / 动作增删 / 属性与依赖编辑等入口自动置灰,
  左栏视图模式只保留条形 / 圆周(流程图入口在顶部工具栏)
- 导出升级:导出按钮合并为下拉菜单,SVG / PNG 三种视图通用;
  流程图额外支持 drawio(diagrams.net 可继续编辑泳道 / 相位 / 依赖)
- 连线走线统一收敛到 FlowLayout.routes,画布 / SVG / drawio 共用同一几何
- 默认示例升级为完整「装配线节拍」(8 动作 / 3 工位 / 4 相位分区)
- 版本号 1.3.0+16,更新说明 release/RELEASE_NOTES_v1.3.0.md
This commit is contained in:
2026-10-09 13:59:05 +08:00
parent fe2008b604
commit f4ef9b32a5
22 changed files with 1837 additions and 281 deletions
+106 -3
View File
@@ -21,6 +21,7 @@ import 'dart:math' as math;
import 'dart:ui';
import '../layout/layout.dart';
import '../layout/flow_layout.dart';
import '../model/models.dart';
import '../model/units.dart';
import '../theme/tokens.dart';
@@ -85,8 +86,10 @@ class SvgWriter {
_b.write('<g id="content" transform="${fit.svgTransform}">');
if (mode == ViewMode.bar) {
_barView(const Size(w, h));
} else {
} else if (mode == ViewMode.circular) {
_circularView(const Size(w, h));
} else {
_flowView();
}
_b.write('</g>');
// 图例:固定左下角。
@@ -273,6 +276,104 @@ class SvgWriter {
}
}
/// 生成流程图视图的 SVG 内容。
///
/// 几何完全复用 [FlowLayout](与屏幕画布、drawio 导出共用同一套走线),
/// 依次输出:
/// - `g#lanes`:泳道背景带与轨道标题;
/// - `g#phases`:左侧相位竖带(分区名旋转 90°,重叠分区台阶错位);
/// - `g#edges`:依赖折线(FS 实线 / SS 虚线,带箭头与 FS/SS 标签);
/// - `g#actions`:动作节点与开始 / 结束胶囊(带 data-* 语义属性)。
void _flowView() {
final FlowLayout layout = FlowLayout(project);
if (layout.nodes.isEmpty) return;
// 泳道背景带(与画布一致:环带色 55% 透明度 + 轨道标题)。
_b.write('<g id="lanes">');
final double lanePitch = FlowLayout.nodeW + FlowLayout.laneGap;
final double top = layout.bounds.top + 20;
final double bottom = layout.bounds.bottom - 20;
for (int i = 0; i < layout.lanes.length; i++) {
final double cx = FlowLayout.marginX + i * lanePitch + FlowLayout.nodeW / 2;
_rect(cx - FlowLayout.nodeW / 2 - 26, top, FlowLayout.nodeW + 52, bottom - top,
fill: _hex(i.isEven ? tokens.ringA : tokens.ringB), rx: 14, opacity: 0.55);
_text(cx, top + 16, '轨道 L${i + 1}',
color: _hex(tokens.sub), size: 11, anchor: 'middle', weight: '700');
}
_b.write('</g>');
// 相位竖带:窄带 + 旋转 90° 分区名,纵向对齐流程行、重叠分区台阶错位。
_b.write('<g id="phases">');
final double rowPitch = FlowLayout.nodeH + FlowLayout.rankGap;
for (final FlowPhaseSpan s in layout.spans) {
final double pTop = FlowLayout.marginY + s.rankTop * rowPitch - 6;
final double pBottom =
FlowLayout.marginY + s.rankBottom * rowPitch + FlowLayout.nodeH + 6;
final double left = FlowLayout.railX + s.slot * FlowLayout.railStep;
_rect(left, pTop, FlowLayout.railW, pBottom - pTop,
fill: _hex(tokens.accent), rx: 9, opacity: 0.10);
_rect(left, pTop, FlowLayout.railW, pBottom - pTop,
fill: 'none', rx: 9, stroke: _hex(tokens.accent), sw: 1, opacity: 0.45);
final double tx = left + FlowLayout.railW / 2;
final double ty = (pTop + pBottom) / 2;
_b.write('<text transform="translate(${tx.toStringAsFixed(1)} ${ty.toStringAsFixed(1)}) rotate(-90)" '
'font-family="$_font" font-size="10.5" fill="${_hex(tokens.sub)}" text-anchor="middle" '
'dominant-baseline="middle" font-weight="700">${_esc(s.zone.name)}</text>');
}
_b.write('</g>');
// 依赖折线:FS 实线 / SS 虚线,带箭头与 FS/SS 标签。
_b.write('<g id="edges">');
for (final FlowEdgeRoute r in layout.routes) {
final FlowEdge e = r.edge;
final bool fs = e.type == DepType.fs;
final String col = _hex(e.type == null ? tokens.sub : (fs ? tokens.fs : tokens.ss));
final String d = <String>[
for (int i = 0; i < r.points.length; i++)
'${i == 0 ? 'M' : 'L'} ${r.points[i].dx.toStringAsFixed(1)} ${r.points[i].dy.toStringAsFixed(1)}',
].join(' ');
final String marker = e.type == null ? '' : ' marker-end="url(#arrow-${fs ? 'fs' : 'ss'})"';
final String dash = r.dashed ? ' stroke-dasharray="6 4"' : '';
_b.write('<path d="$d" fill="none" stroke="$col" stroke-width="${e.critical ? 2 : 1.3}"'
'$dash$marker/>');
if (e.type != null) {
final String text = switch (e.type!) {
DepType.fs => 'FS',
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
DepType.ff => 'FF',
DepType.sf => 'SF',
};
_text(r.labelAt.dx, r.labelAt.dy, text,
color: col, size: 9, anchor: 'middle', weight: '600');
}
}
_b.write('</g>');
// 动作节点与开始 / 结束胶囊。
_b.write('<g id="actions">');
for (final FlowNode n in layout.nodes) {
final Rect r = n.rect;
if (n.isStart || n.isEnd) {
_rect(r.left, r.top, r.width, r.height,
fill: _hex(tokens.panel2), rx: r.height / 2, stroke: _hex(tokens.accent), sw: 1.2);
_text(r.center.dx, r.center.dy, n.title,
color: _hex(tokens.accent), size: 13, anchor: 'middle', weight: '700');
continue;
}
final Action a = n.action!;
final Color c = Color(a.color);
_b.write('<g id="${_esc(n.id)}" data-action="${_esc(n.id)}" data-start="${a.startAngle}" '
'data-duration="${a.durationAngle}" data-layer="${a.layer}" data-station="${_esc(a.stationId)}">');
_rect(r.left, r.top, r.width, r.height, fill: _hex(c), rx: 10, opacity: 0.92);
_text(r.center.dx, r.top + 21, n.title,
color: _hex(tokens.arcText), size: 12, anchor: 'middle', weight: '700');
_text(r.center.dx, r.top + 41, n.subtitle,
color: _hex(tokens.arcText), size: 10, anchor: 'middle');
_b.write('</g>');
}
_b.write('</g>');
}
/// 生成一段圆弧的 SVG `d` 路径字符串。
///
/// 参数 [c] 圆心、[r] 半径、[a0]/[a1] 起止角度(度)。
@@ -290,9 +391,11 @@ class SvgWriter {
///
/// 参数为位置与尺寸;可选 [fill] 填充色、[rx] 圆角半径、[opacity] 透明度。
void _rect(double x, double y, double w, double h,
{String? fill, double rx = 0, double opacity = 1}) {
{String? fill, double rx = 0, double opacity = 1, String? stroke, double sw = 1}) {
_b.write('<rect x="${x.toStringAsFixed(1)}" y="${y.toStringAsFixed(1)}" width="${w.toStringAsFixed(1)}" '
'height="${h.toStringAsFixed(1)}" rx="$rx" fill="${fill ?? 'none'}" opacity="$opacity"/>');
'height="${h.toStringAsFixed(1)}" rx="$rx" fill="${fill ?? 'none'}" opacity="$opacity"'
'${stroke == null ? '' : ' stroke="$stroke" stroke-width="$sw"'}'
'/>');
}
/// 写入一个 `<circle>` 元素。