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:
@@ -4,8 +4,10 @@ import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sequence_diagram/export/drawio_writer.dart';
|
||||
import 'package:sequence_diagram/export/export_renderer.dart';
|
||||
import 'package:sequence_diagram/export/svg_writer.dart';
|
||||
import 'package:sequence_diagram/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
@@ -50,4 +52,75 @@ void main() {
|
||||
expect(first & 0xFFFFFF, 0xFFFFFF);
|
||||
File('build/export_preview.png').writeAsBytesSync(bytes);
|
||||
});
|
||||
|
||||
test('svg export: flowchart view (lanes / phases / edges / actions / start-end)', () {
|
||||
final Project p = demoTiming();
|
||||
final String svg = SvgWriter(project: p, tokens: Tokens.light, mode: ViewMode.flow).build();
|
||||
expect(svg, contains('流程图视图'));
|
||||
expect(svg, contains('<g id="lanes">'));
|
||||
expect(svg, contains('轨道 L1'));
|
||||
expect(svg, contains('<g id="phases">'));
|
||||
expect(svg, contains('上料相位'));
|
||||
expect(svg, contains('rotate(-90)'));
|
||||
expect(svg, contains('<g id="edges">'));
|
||||
expect(svg, contains('marker-end="url(#arrow-fs)"'));
|
||||
expect(svg, contains('marker-end="url(#arrow-ss)"'));
|
||||
expect(svg, contains('stroke-dasharray="6 4"'));
|
||||
expect(svg, contains('>SS+10°</text>'));
|
||||
expect(svg, contains('<g id="actions">'));
|
||||
expect(svg, contains('data-action="A1"'));
|
||||
// 每个节点都在(标题 / 副标题取自布局,避免硬编码格式)。
|
||||
final FlowLayout layout = FlowLayout(p);
|
||||
for (final FlowNode n in layout.nodes) {
|
||||
expect(svg, contains(n.title), reason: '缺少节点标题 ${n.title}');
|
||||
if (n.action != null) {
|
||||
expect(svg, contains(n.subtitle), reason: '缺少节点副标题 ${n.subtitle}');
|
||||
}
|
||||
}
|
||||
expect(svg, contains('开始'));
|
||||
expect(svg, contains('结束'));
|
||||
});
|
||||
|
||||
test('png export: flowchart view renders on 1920x1080 canvas (2x bitmap)', () async {
|
||||
final Project p = demoTiming().copyWith(viewState: const ViewState(mode: ViewMode.flow));
|
||||
final Uint8List bytes = await renderExportPng(
|
||||
project: p,
|
||||
tokens: Tokens.light,
|
||||
criticalActions: const <String>{'A1', 'A2', 'A3'},
|
||||
criticalDeps: const <String>{'A1->A2', 'A2->A3'},
|
||||
);
|
||||
final ui.ImmutableBuffer buf = await ui.ImmutableBuffer.fromUint8List(bytes);
|
||||
final ui.ImageDescriptor desc = await ui.ImageDescriptor.encoded(buf);
|
||||
expect(desc.width, 3840);
|
||||
expect(desc.height, 2160);
|
||||
final ui.Codec codec = await desc.instantiateCodec();
|
||||
final ui.FrameInfo frame = await codec.getNextFrame();
|
||||
final ByteData? rgba = await frame.image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
||||
expect(rgba!.getUint32(0) & 0xFFFFFF, 0xFFFFFF);
|
||||
File('build/export_flow_preview.png').writeAsBytesSync(bytes);
|
||||
});
|
||||
|
||||
test('drawio export: mxfile with lanes / phases / nodes / edges', () {
|
||||
final Project p = demoTiming();
|
||||
final String xml = DrawioWriter(project: p, tokens: Tokens.light).build();
|
||||
expect(xml, startsWith('<mxfile'));
|
||||
expect(xml, endsWith('</mxfile>'));
|
||||
expect(xml, contains('<mxGraphModel'));
|
||||
expect(xml, contains('<mxCell id="0"/>'));
|
||||
expect(xml, contains('<mxCell id="1" parent="0"/>'));
|
||||
expect(xml, contains('value="轨道 L1"'));
|
||||
expect(xml, contains('value="上料相位"'));
|
||||
expect(xml, contains('horizontal=0'));
|
||||
// 动作节点:两行文本( 换行)+ 依赖以 source / target 引用。
|
||||
expect(xml, contains(' '));
|
||||
expect(xml, contains('source="A1" target="A2"'));
|
||||
expect(xml, contains('value="SS+10°"'));
|
||||
expect(xml, contains('edge="1"'));
|
||||
expect(xml, contains('value="开始"'));
|
||||
expect(xml, contains('value="结束"'));
|
||||
// 保留 id 映射为可读短名,避免出现下划线开头的内部 id。
|
||||
expect(xml, contains('id="flow-start"'));
|
||||
expect(xml, contains('id="flow-end"'));
|
||||
expect(xml, isNot(contains('__flow_start__')));
|
||||
});
|
||||
}
|
||||
|
||||
+15
-34
@@ -5,40 +5,9 @@ import 'package:flutter/services.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 构造一个动作较多、含依赖与相位分区的演示工程。
|
||||
Project demoTiming() {
|
||||
return Project(
|
||||
name: '装配线节拍',
|
||||
cycle: const Cycle(durationMs: 2400),
|
||||
stations: const <Station>[
|
||||
Station(id: 'ST1', name: '上料工位', order: 0, color: 0xFF4CC9F0),
|
||||
Station(id: 'ST2', name: '加工工位', order: 1, color: 0xFFFFD166),
|
||||
Station(id: 'ST3', name: '检测工位', order: 2, color: 0xFF34D399),
|
||||
],
|
||||
actions: <Action>[
|
||||
const Action(id: 'A1', name: '上料', stationId: 'ST1', driver: '气缸 Y1', startAngle: 0, durationAngle: 45, layer: 0, color: 0xFF4CC9F0),
|
||||
const Action(id: 'A2', name: '定位夹紧', stationId: 'ST1', driver: '气缸 Y2', startAngle: 50, durationAngle: 55, layer: 0, color: 0xFF7BD88F,
|
||||
deps: <Dependency>[Dependency(fromId: 'A1', toId: 'A2', type: DepType.fs)]),
|
||||
const Action(id: 'A3', name: '伺服下压', stationId: 'ST2', driver: '伺服 M1', startAngle: 90, durationAngle: 70, layer: 1, color: 0xFFFFD166,
|
||||
deps: <Dependency>[Dependency(fromId: 'A2', toId: 'A3', type: DepType.fs)]),
|
||||
const Action(id: 'A4', name: '超声焊接', stationId: 'ST2', driver: '超声 U1', startAngle: 100, durationAngle: 50, layer: 2, color: 0xFFF472B6,
|
||||
deps: <Dependency>[Dependency(fromId: 'A3', toId: 'A4', type: DepType.ss, offsetAngle: 10)]),
|
||||
const Action(id: 'A5', name: '视觉检测', stationId: 'ST3', driver: '相机 C1', startAngle: 160, durationAngle: 70, layer: 1, color: 0xFF7C5CFF,
|
||||
deps: <Dependency>[Dependency(fromId: 'A4', toId: 'A5', type: DepType.fs)]),
|
||||
const Action(id: 'A6', name: '分选下料', stationId: 'ST3', driver: '气缸 Y3', startAngle: 200, durationAngle: 70, layer: 2, color: 0xFFFF9F7C,
|
||||
deps: <Dependency>[Dependency(fromId: 'A5', toId: 'A6', type: DepType.fs)]),
|
||||
const Action(id: 'A7', name: '清洁吹气', stationId: 'ST1', driver: '电磁阀 V1', startAngle: 240, durationAngle: 80, layer: 3, color: 0xFF34D399,
|
||||
deps: <Dependency>[Dependency(fromId: 'A6', toId: 'A7', type: DepType.fs)]),
|
||||
],
|
||||
units: const UnitSettings(timeUnit: TimeUnit.s),
|
||||
viewState: const ViewState(mode: ViewMode.bar),
|
||||
phaseZones: const <PhaseZone>[
|
||||
PhaseZone(name: '上料相位', startAngle: 0, endAngle: 70),
|
||||
PhaseZone(name: '加工相位', startAngle: 70, endAngle: 200),
|
||||
PhaseZone(name: '检测相位', startAngle: 200, endAngle: 300),
|
||||
PhaseZone(name: '下料相位', startAngle: 300, endAngle: 360),
|
||||
],
|
||||
);
|
||||
}
|
||||
/// 演示工程:与内置默认工程完全一致(`Project.demo()`),
|
||||
/// 保证「本地构建启动即所见」与演示截图的数据永远同步。
|
||||
Project demoTiming() => Project.demo();
|
||||
|
||||
/// 从系统字体加载中文字体,使测试截图中的中文正常渲染。
|
||||
Future<void> loadZhFonts() async {
|
||||
@@ -57,3 +26,15 @@ Future<void> loadZhFonts() async {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// 从 Flutter SDK 加载 Material 图标字体,使测试截图中的图标正常渲染
|
||||
/// (否则所有 Icon 会显示为空心方框)。
|
||||
Future<void> loadMaterialIcons() async {
|
||||
final String root = Platform.environment['FLUTTER_ROOT'] ?? '';
|
||||
if (root.isEmpty) return;
|
||||
final File f = File('$root/bin/cache/artifacts/material_fonts/MaterialIcons-Regular.otf');
|
||||
if (!f.existsSync()) return;
|
||||
final ByteData bytes = ByteData.sublistView(await f.readAsBytes());
|
||||
final FontLoader loader = FontLoader('MaterialIcons')..addFont(Future<ByteData>.value(bytes));
|
||||
await loader.load();
|
||||
}
|
||||
|
||||
@@ -52,8 +52,9 @@ void main() {
|
||||
expect(decoded.actions.length, p.actions.length);
|
||||
expect(decoded.stations.length, p.stations.length);
|
||||
expect(decoded.phaseZones.length, p.phaseZones.length);
|
||||
expect(decoded.actions.last.deps.first.type, DepType.fs);
|
||||
expect(decoded.cycle.durationMs, 3600);
|
||||
final Action withDeps = decoded.actions.firstWhere((Action a) => a.deps.isNotEmpty);
|
||||
expect(withDeps.deps.first.type, DepType.fs);
|
||||
expect(decoded.cycle.durationMs, 2400);
|
||||
expect(decoded.actions.last.color, p.actions.last.color);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,8 @@ void main() {
|
||||
group('station management', () {
|
||||
test('setStations reassigns actions of a removed station', () {
|
||||
final AppController c = AppController(project: Project.demo());
|
||||
expect(c.project.stations.length, 2);
|
||||
// 演示工程至少包含两个工位;移除第二个工位后其动作应被重新分配。
|
||||
expect(c.project.stations.length, greaterThan(1));
|
||||
final String removed = c.project.stations[1].id;
|
||||
expect(c.project.actions.any((Action a) => a.stationId == removed), isTrue);
|
||||
|
||||
@@ -26,13 +27,14 @@ void main() {
|
||||
|
||||
test('setStations can add and rename stations', () {
|
||||
final AppController c = AppController(project: Project.demo());
|
||||
final int before = c.project.stations.length;
|
||||
final List<Station> next = <Station>[
|
||||
...c.project.stations,
|
||||
const Station(id: 'ST3', name: '工位 3', order: 2, color: 0xFF4ADE80),
|
||||
const Station(id: 'ST9', name: '工位 9', order: 9, color: 0xFF4ADE80),
|
||||
];
|
||||
c.setStations(next);
|
||||
expect(c.project.stations.length, 3);
|
||||
expect(c.project.stationById('ST3')?.name, '工位 3');
|
||||
expect(c.project.stations.length, before + 1);
|
||||
expect(c.project.stationById('ST9')?.name, '工位 9');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'helpers.dart';
|
||||
void main() {
|
||||
testWidgets('generate tablet demo screenshots', (WidgetTester tester) async {
|
||||
await tester.runAsync(() => loadZhFonts());
|
||||
await tester.runAsync(() => loadMaterialIcons());
|
||||
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
@@ -25,6 +26,7 @@ void main() {
|
||||
key: const ValueKey<String>('shot'),
|
||||
child: MaterialApp(
|
||||
theme: buildTheme(t),
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: AppShell(controller: c),
|
||||
),
|
||||
);
|
||||
@@ -38,13 +40,15 @@ void main() {
|
||||
await shot('../demo/tablet-bar-light.png');
|
||||
|
||||
// 展开左右侧栏(浮层)并钉住,展示停靠布局。
|
||||
await tester.tap(find.byIcon(Icons.chevron_right).first);
|
||||
// 注意:不能用 find.byIcon(Icons.chevron_right)——画布右下角的预览卡里
|
||||
// 也有同类图标且更早出现在组件树中,会误触「切换视图」;改为按坐标点贴边轨道。
|
||||
await tester.tapAt(const Offset(10, 300));
|
||||
await tester.pump();
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
await tester.pump();
|
||||
}
|
||||
await tester.tap(find.byIcon(Icons.chevron_left).first);
|
||||
await tester.tapAt(const Offset(1270, 300));
|
||||
await tester.pump();
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
@@ -56,12 +60,33 @@ void main() {
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await shot('../demo/tablet-circular-light.png');
|
||||
|
||||
// 深色主题:条形与圆周。
|
||||
// 流程图视图(浅色):由时序图自动生成(泳道 = 轨道,只读)。
|
||||
c.setViewMode(ViewMode.flow);
|
||||
await shot('../demo/tablet-flow-light.png');
|
||||
|
||||
// 流程图导出菜单:SVG / PNG 之外额外提供 drawio 入口(仅流程图)。
|
||||
await tester.tap(find.text('导出'));
|
||||
await tester.pumpAndSettle();
|
||||
await shot('../demo/tablet-flow-export-menu-light.png');
|
||||
await tester.tapAt(const Offset(5, 5));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 选中动作:右侧属性面板进入只读态(滑块 / 依赖编辑置灰)。
|
||||
c.select('A2');
|
||||
await shot('../demo/tablet-flow-selected-light.png');
|
||||
c.select(null);
|
||||
|
||||
// 深色主题:条形、圆周与流程图。
|
||||
// 注意:MaterialApp 的主题切换带 200ms 过渡动画,必须等动画结束再截图,
|
||||
// 否则截到的是过渡起点(仍然是浅色)。
|
||||
c.toggleTheme();
|
||||
await tester.pumpWidget(shell(Tokens.dark));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
c.setViewMode(ViewMode.bar);
|
||||
await shot('../demo/tablet-bar-dark.png');
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await shot('../demo/tablet-circular-dark.png');
|
||||
c.setViewMode(ViewMode.flow);
|
||||
await shot('../demo/tablet-flow-dark.png');
|
||||
});
|
||||
}
|
||||
|
||||
+43
-1
@@ -25,9 +25,10 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(controller.project.viewState.mode, ViewMode.circular);
|
||||
|
||||
final int before = controller.project.actions.length;
|
||||
controller.addAction(startAngle: 30);
|
||||
await tester.pump();
|
||||
expect(controller.project.actions.length, 3);
|
||||
expect(controller.project.actions.length, before + 1);
|
||||
|
||||
controller.setViewMode(ViewMode.bar);
|
||||
await tester.pump();
|
||||
@@ -56,4 +57,45 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(controller.brightness, Brightness.dark);
|
||||
});
|
||||
|
||||
testWidgets('export menu: drawio only in flow view; AI disabled in flow', (WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1920, 1080);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final AppController controller = AppController();
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: buildTheme(Tokens.light),
|
||||
home: AppShell(controller: controller),
|
||||
));
|
||||
await tester.pump();
|
||||
|
||||
// 条形视图:导出菜单只有 SVG / PNG,不含 drawio;AI 生成可用。
|
||||
expect(tester.widget<FilledButton>(find.widgetWithText(FilledButton, 'AI 生成')).onPressed, isNotNull);
|
||||
await tester.tap(find.text('导出'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('导出 SVG'), findsOneWidget);
|
||||
expect(find.text('导出 PNG'), findsOneWidget);
|
||||
expect(find.text('导出 drawio'), findsNothing);
|
||||
await tester.tapAt(const Offset(5, 5));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 流程图视图:导出菜单额外出现 drawio;AI 生成 / 撤销 / 重做置灰。
|
||||
controller.setViewMode(ViewMode.flow);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<FilledButton>(find.widgetWithText(FilledButton, 'AI 生成')).onPressed, isNull);
|
||||
expect(
|
||||
tester.widget<IconButton>(find.widgetWithIcon(IconButton, Icons.undo)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<IconButton>(find.widgetWithIcon(IconButton, Icons.redo)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.text('导出'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('导出 drawio'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user