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:
@@ -0,0 +1,225 @@
|
||||
/// drawio 导出写入器:把流程图序列化为 diagrams.net(draw.io)可编辑的 `.drawio` 文件。
|
||||
///
|
||||
/// 架构位置:
|
||||
/// - 仅流程图视图支持(条形 / 圆周视图只有 SVG / PNG 两种导出);
|
||||
/// - 几何完全复用 [FlowLayout](与屏幕画布、SVG 导出同一套坐标与走线),
|
||||
/// 保证三种载体(画布 / drawio / SVG)内容一致;
|
||||
/// - 输出标准 `<mxfile>` 文档:节点保留动作颜色与「时长 · 工位」语义,
|
||||
/// 连线保留 FS / SS 类型与偏移角标签,泳道为背景带、相位为竖排文字带,
|
||||
/// 导入 draw.io 后可直接继续排布与编辑。
|
||||
///
|
||||
/// 输出约定:
|
||||
/// - 坐标与原画布 1:1(不缩放),原点同样在左上角;
|
||||
/// - 页面尺寸按内容范围自动设置,四边各留 [_pad] 留白,整体平移到页内;
|
||||
/// - 不写入时间戳等易变字段,保证同一工程多次导出结果稳定(便于测试与归档)。
|
||||
library;
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
/// drawio 文档写入器。
|
||||
///
|
||||
/// 通过内部 [StringBuffer] 逐段拼接 XML,最终由 [build] 返回完整文档。
|
||||
class DrawioWriter {
|
||||
/// 创建写入器。
|
||||
///
|
||||
/// 参数:
|
||||
/// - [project]:数据源(动作、依赖、相位分区、单位);
|
||||
/// - [tokens]:配色令牌(内部转为导出专用纯白主题,与 SVG / PNG 一致)。
|
||||
///
|
||||
/// 构造时不生成任何内容;调用 [build] 才写出文档。
|
||||
DrawioWriter({required this.project, required Tokens tokens})
|
||||
: tokens = exportTokens(tokens);
|
||||
|
||||
/// 数据源工程。
|
||||
final Project project;
|
||||
/// 导出专用配色令牌。
|
||||
final Tokens tokens;
|
||||
|
||||
/// 页内留白(四周各留的空白,逻辑像素)。
|
||||
static const double _pad = 40;
|
||||
|
||||
/// 输出缓冲区,累积 XML 文本片段。
|
||||
final StringBuffer _b = StringBuffer();
|
||||
|
||||
/// 生成完整 drawio 文档字符串。
|
||||
///
|
||||
/// 返回:以 `<mxfile>` 开头、`</mxfile>` 结尾的字符串。
|
||||
/// 副作用:会持续向内部缓冲区追加内容;约定每次导出新建实例。
|
||||
String build() {
|
||||
final FlowLayout layout = FlowLayout(project);
|
||||
if (layout.nodes.isEmpty) {
|
||||
return '<mxfile host="app.diagrams.net"><diagram id="flow" name="流程图">'
|
||||
'<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root>'
|
||||
'</mxGraphModel></diagram></mxfile>';
|
||||
}
|
||||
// 平移到页内:原点统一挪到 (pad, pad),页面尺寸随内容自适应。
|
||||
final double ox = _pad - layout.bounds.left;
|
||||
final double oy = _pad - layout.bounds.top;
|
||||
final int pageW = (layout.bounds.width + _pad * 2).ceil();
|
||||
final int pageH = (layout.bounds.height + _pad * 2).ceil();
|
||||
|
||||
_b.write('<mxfile host="app.diagrams.net" agent="Sequence Diagram Studio" '
|
||||
'version="24.7.8" type="device">');
|
||||
_b.write('<diagram id="flow" name="${_esc(project.name.isEmpty ? '流程图' : project.name)}">');
|
||||
_b.write('<mxGraphModel dx="1600" dy="900" grid="1" gridSize="10" guides="1" '
|
||||
'tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" '
|
||||
'pageWidth="$pageW" pageHeight="$pageH" math="0" shadow="0">');
|
||||
_b.write('<root>');
|
||||
_b.write('<mxCell id="0"/>');
|
||||
_b.write('<mxCell id="1" parent="0"/>');
|
||||
|
||||
_lanes(layout, ox, oy);
|
||||
_phases(layout, ox, oy);
|
||||
_edges(layout);
|
||||
_nodes(layout, ox, oy);
|
||||
|
||||
_b.write('</root></mxGraphModel></diagram></mxfile>');
|
||||
return _b.toString();
|
||||
}
|
||||
|
||||
/// 写入泳道背景带与轨道标题(原样平移)。
|
||||
void _lanes(FlowLayout layout, double ox, double oy) {
|
||||
final double lanePitch = FlowLayout.nodeW + FlowLayout.laneGap;
|
||||
final double top = layout.bounds.top + 20 + oy;
|
||||
final double bottom = layout.bounds.bottom - 20 + oy;
|
||||
for (int i = 0; i < layout.lanes.length; i++) {
|
||||
final double cx = FlowLayout.marginX + i * lanePitch + FlowLayout.nodeW / 2 + ox;
|
||||
_rectCell(
|
||||
'lane-${layout.lanes[i]}',
|
||||
'轨道 L${i + 1}',
|
||||
cx - FlowLayout.nodeW / 2 - 26,
|
||||
top,
|
||||
FlowLayout.nodeW + 52,
|
||||
bottom - top,
|
||||
'rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;fontSize=11;fontStyle=1;'
|
||||
'fillColor=${_hex(i.isEven ? tokens.ringA : tokens.ringB)};fillOpacity=55;'
|
||||
'strokeColor=none;fontColor=${_hex(tokens.sub)};',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入相位竖带:竖排文字(`horizontal=0`)+ 低透明度填充,台阶错位保持一致。
|
||||
void _phases(FlowLayout layout, double ox, double oy) {
|
||||
final double rowPitch = FlowLayout.nodeH + FlowLayout.rankGap;
|
||||
for (int i = 0; i < layout.spans.length; i++) {
|
||||
final FlowPhaseSpan s = layout.spans[i];
|
||||
final double top = FlowLayout.marginY + s.rankTop * rowPitch - 6 + oy;
|
||||
final double bottom =
|
||||
FlowLayout.marginY + s.rankBottom * rowPitch + FlowLayout.nodeH + 6 + oy;
|
||||
final double left = FlowLayout.railX + s.slot * FlowLayout.railStep + ox;
|
||||
_rectCell(
|
||||
'phase-$i',
|
||||
s.zone.name,
|
||||
left,
|
||||
top,
|
||||
FlowLayout.railW,
|
||||
bottom - top,
|
||||
'rounded=1;whiteSpace=wrap;html=1;horizontal=0;fontSize=10;fontStyle=1;'
|
||||
'fillColor=${_hex(tokens.accent)};fillOpacity=10;'
|
||||
'strokeColor=${_hex(tokens.accent)};strokeOpacity=45;fontColor=${_hex(tokens.sub)};',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入动作节点与开始 / 结束胶囊。
|
||||
void _nodes(FlowLayout layout, double ox, double oy) {
|
||||
for (final FlowNode n in layout.nodes) {
|
||||
final Rect r = n.rect;
|
||||
if (n.isStart || n.isEnd) {
|
||||
_rectCell(
|
||||
_cellId(n.id),
|
||||
n.title,
|
||||
r.left + ox,
|
||||
r.top + oy,
|
||||
r.width,
|
||||
r.height,
|
||||
'ellipse;whiteSpace=wrap;html=1;fontSize=13;fontStyle=1;'
|
||||
'fillColor=${_hex(tokens.panel2)};strokeColor=${_hex(tokens.accent)};'
|
||||
'fontColor=${_hex(tokens.accent)};',
|
||||
);
|
||||
continue;
|
||||
}
|
||||
final Action a = n.action!;
|
||||
// 节点两行文字:标题(序号. 名称)+ 副标题(时长 · 工位)。
|
||||
_rectCell(
|
||||
_cellId(n.id),
|
||||
'${n.title}\n${n.subtitle}',
|
||||
r.left + ox,
|
||||
r.top + oy,
|
||||
r.width,
|
||||
r.height,
|
||||
'rounded=1;absoluteArcSize=1;arcSize=10;whiteSpace=wrap;html=1;fontSize=12;fontStyle=1;'
|
||||
'fillColor=${_hex(Color(a.color))};fillOpacity=92;'
|
||||
'strokeColor=${_hex(tokens.selOutline)};strokeOpacity=25;'
|
||||
'fontColor=${_hex(tokens.arcText)};',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入依赖连线:以 source / target 引用节点,drawio 自动正交布线并可再编辑。
|
||||
///
|
||||
/// 样式与画布一致:FS 绿实线、SS 琥珀虚线(标签标注偏移角)、关键路径加粗。
|
||||
void _edges(FlowLayout layout) {
|
||||
int i = 0;
|
||||
for (final FlowEdge e in layout.edges) {
|
||||
i++;
|
||||
final bool fs = e.type == DepType.fs;
|
||||
final String col =
|
||||
_hex(e.type == null ? tokens.sub : (fs ? tokens.fs : tokens.ss));
|
||||
final String label = switch (e.type) {
|
||||
null => '',
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
_b.write('<mxCell id="edge-$i-${_cellId(e.fromId)}-${_cellId(e.toId)}" '
|
||||
'value="${_esc(label)}" '
|
||||
'style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;jettySize=auto;'
|
||||
'orthogonalLoop=1;endArrow=block;endFill=1;'
|
||||
'strokeWidth=${e.critical ? 2.4 : 1.3};strokeColor=$col;'
|
||||
'${e.type == DepType.ss ? 'dashed=1;dashPattern=6 4;' : ''}'
|
||||
'fontSize=9;fontColor=$col;labelBackgroundColor=${_hex(tokens.bg)};" '
|
||||
'edge="1" parent="1" source="${_cellId(e.fromId)}" target="${_cellId(e.toId)}">'
|
||||
'<mxGeometry relative="1" as="geometry"/></mxCell>');
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入一个顶点(矩形 / 胶囊 / 竖带)单元格。
|
||||
void _rectCell(String id, String value, double x, double y, double w, double h,
|
||||
String style) {
|
||||
_b.write('<mxCell id="$id" value="${_esc(value)}" '
|
||||
'style="$style" vertex="1" parent="1">'
|
||||
'<mxGeometry x="${x.toStringAsFixed(1)}" y="${y.toStringAsFixed(1)}" '
|
||||
'width="${w.toStringAsFixed(1)}" height="${h.toStringAsFixed(1)}" as="geometry"/>'
|
||||
'</mxCell>');
|
||||
}
|
||||
|
||||
/// 节点 id → drawio 单元格 id:开始 / 结束用可读短名,其余原样保留。
|
||||
static String _cellId(String nodeId) {
|
||||
if (nodeId == FlowNode.startId) return 'flow-start';
|
||||
if (nodeId == FlowNode.endId) return 'flow-end';
|
||||
return nodeId.replaceAll(RegExp(r'[^A-Za-z0-9_-]'), '_');
|
||||
}
|
||||
|
||||
/// 转义 XML 文本 / 属性中的特殊字符;换行转为 ` `(drawio 多行标签约定)。
|
||||
static String _esc(String s) => s
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll('\n', ' ');
|
||||
|
||||
/// 把 Flutter [Color] 转为 `#rrggbb` 字符串(忽略 alpha)。
|
||||
static String _hex(Color c) {
|
||||
final int r = (c.r * 255).round();
|
||||
final int g = (c.g * 255).round();
|
||||
final int b = (c.b * 255).round();
|
||||
return '#${r.toRadixString(16).padLeft(2, '0')}${g.toRadixString(16).padLeft(2, '0')}${b.toRadixString(16).padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
@@ -54,10 +55,14 @@ ExportFit computeExportFit(Project project, ViewMode mode, Rect area) {
|
||||
final int n = l.lanes.length;
|
||||
final double bottom = n == 0 ? BarLayout.topPad + BarLayout.rowVisual : l.yFor(n) + BarLayout.rowVisual + 8;
|
||||
bounds = Rect.fromLTRB(12, BarPainter.phaseBandTop - 14, l.plotRight + 120, bottom);
|
||||
} else {
|
||||
} else if (mode == ViewMode.circular) {
|
||||
final CircularLayout l = CircularLayout(project, kExportSize);
|
||||
final double rExt = l.tickR + 100;
|
||||
bounds = Rect.fromLTRB(l.center.dx - rExt, l.center.dy - rExt, l.center.dx + rExt, l.center.dy + rExt);
|
||||
} else {
|
||||
// 流程图:直接使用布局层给出的内容范围(含泳道、阶段栏与连线)。
|
||||
final FlowLayout l = FlowLayout(project);
|
||||
bounds = l.nodes.isEmpty ? const Rect.fromLTWH(0, 0, 800, 600) : l.bounds;
|
||||
}
|
||||
if (bounds.width <= 1 || bounds.height <= 1) {
|
||||
return const ExportFit(1, 0, 0);
|
||||
@@ -69,14 +74,21 @@ ExportFit computeExportFit(Project project, ViewMode mode, Rect area) {
|
||||
}
|
||||
|
||||
/// 导出标题(与画布浮层一致)。
|
||||
String exportTitle(ViewMode mode) =>
|
||||
mode == ViewMode.bar ? '条形时序视图' : '圆周时序视图';
|
||||
String exportTitle(ViewMode mode) => switch (mode) {
|
||||
ViewMode.bar => '条形时序视图',
|
||||
ViewMode.circular => '圆周时序视图',
|
||||
ViewMode.flow => '流程图视图',
|
||||
};
|
||||
|
||||
/// 导出副标题(与画布浮层一致)。
|
||||
String exportSubtitle(Project project, ViewMode mode) {
|
||||
if (mode == ViewMode.bar) {
|
||||
return '箭头表示动作之间关联(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)';
|
||||
}
|
||||
if (mode == ViewMode.flow) {
|
||||
// 流程图不重复线型说明,导出仅保留标题(与画布浮层一致)。
|
||||
return '';
|
||||
}
|
||||
return '同心圆环 = 动作层 · 1 圈 = 1 循环 = ${tfmt(project.cycle.durationMs, project.units)} = 360° = 100%';
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:flutter/material.dart' hide Action;
|
||||
import '../model/models.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../render/circular_painter.dart';
|
||||
import '../render/flow_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
@@ -64,6 +65,14 @@ Future<Uint8List> renderExportPng({
|
||||
criticalDeps: criticalDeps,
|
||||
selectedIds: const <String>{},
|
||||
).paint(canvas, kExportSize);
|
||||
} else if (mode == ViewMode.flow) {
|
||||
FlowchartPainter(
|
||||
project: project,
|
||||
tokens: et,
|
||||
criticalActions: criticalActions,
|
||||
criticalDeps: criticalDeps,
|
||||
selectedIds: const <String>{},
|
||||
).paint(canvas, kExportSize);
|
||||
} else {
|
||||
CircularPainter(
|
||||
project: project,
|
||||
|
||||
+106
-3
@@ -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>` 元素。
|
||||
|
||||
Reference in New Issue
Block a user