feat(V1.0.1): 泳道/轨道支持多动作(同执行器多条不重叠);圆周弧可拖拽端点;依赖标签沿弧避让
- 泳道模型:layer 兼作泳道/轨道编号,同一泳道可放多个互不重叠动作(角区间重叠校验) - 条形:上下拖拽换道;圆周:Shift+径向拖拽换轨;冲突时拒绝并提示 - 泳道标题合并显示(/ 分隔,≤2 行);左侧列表按泳道分组 - 圆周动作弧支持拖拽两端改起止角(弱吸附 + 径向虚线参考),整体拖拽旋转 - 圆周依赖标签沿圆弧切向排布,落入环间空隙,避免压住动作弧 - 版本 1.0.1+2;帮助/README 补充泳道说明;重新构建 dist
This commit is contained in:
+112
-87
@@ -234,12 +234,13 @@ class BarPainter extends CustomPainter {
|
||||
///
|
||||
/// 参数 [layout] 提供行列几何,[u]/[cycle] 用于时长文本换算。
|
||||
void _rows(Canvas canvas, BarLayout layout, UnitSettings u, double cycle) {
|
||||
final List<Action> ordered = layout.ordered;
|
||||
for (int i = 0; i < ordered.length; i++) {
|
||||
final Action a = ordered[i];
|
||||
final double y = layout.yFor(i);
|
||||
// 隔行背景色带,弱化行边界。
|
||||
if (i.isEven) {
|
||||
final List<int> lanes = layout.lanes;
|
||||
for (int li = 0; li < lanes.length; li++) {
|
||||
final int lane = lanes[li];
|
||||
final double y = layout.yFor(li);
|
||||
final List<Action> acts = layout.actionsInLane(lane);
|
||||
// 隔泳道背景色带,弱化边界。
|
||||
if (li.isEven) {
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, BarLayout.rowVisual),
|
||||
@@ -248,24 +249,9 @@ class BarPainter extends CustomPainter {
|
||||
Paint()..color = tokens.panel2.withValues(alpha: 0.5),
|
||||
);
|
||||
}
|
||||
// 左侧序号徽标:动作自身颜色作底,叠加白色序号。
|
||||
final Station? st = project.stationById(a.stationId);
|
||||
final Color c = Color(a.color);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(Rect.fromLTWH(32, y + 8, 18, 18), const Radius.circular(5)),
|
||||
Paint()..color = c,
|
||||
);
|
||||
_text(canvas, '${i + 1}', Offset(41, y + 17),
|
||||
color: tokens.chip, size: 10, align: TextAlign.center, weight: FontWeight.w700);
|
||||
// 动作标识与工位/驱动信息(两行文本)。
|
||||
// 标题列文字按列宽截断,避免越界压到图表。
|
||||
final double labelMax = BarLayout.leftGutter - 68;
|
||||
_textMax(canvas, '${i + 1}. ${a.id} ${a.name}', Offset(60, y + 6), labelMax,
|
||||
color: tokens.text, size: 12, weight: FontWeight.w600);
|
||||
_textMax(canvas, '${st?.name ?? a.stationId} · ${a.driver}', Offset(60, y + 21), labelMax,
|
||||
color: tokens.dim, size: 10);
|
||||
|
||||
// 行底分隔线,颜色较淡。
|
||||
// 泳道标题(合并显示,最多两行,用 / 分隔)。
|
||||
_laneHeader(canvas, layout, li, acts, y);
|
||||
// 泳道底分隔线。
|
||||
canvas.drawLine(
|
||||
Offset(layout.plotLeft, y + BarLayout.rowVisual - 4),
|
||||
Offset(layout.plotRight, y + BarLayout.rowVisual - 4),
|
||||
@@ -273,69 +259,104 @@ class BarPainter extends CustomPainter {
|
||||
..color = tokens.line.withValues(alpha: 0.5)
|
||||
..strokeWidth = 1,
|
||||
);
|
||||
// 该泳道内的所有动作条(互不重叠)。
|
||||
for (final Action a in acts) {
|
||||
_bar(canvas, layout, a, u, cycle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 动作条块:先投影,再填充,最后描边。
|
||||
final Rect r = layout.rectFor(a);
|
||||
final bool sel = selectedIds.contains(a.id);
|
||||
final bool crit = criticalActions.contains(a.id);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r.shift(const Offset(1.5, 2)), const Radius.circular(8)),
|
||||
Paint()..color = tokens.shadow.withValues(alpha: tokens.shadowOp),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
Paint()..color = c.withValues(alpha: 0.92),
|
||||
);
|
||||
// 选中描边:选中时更亮,未选中时仅保留很淡的轮廓。
|
||||
/// 绘制一条泳道的标题:序号徽标 + 合并动作名(≤2 行,用 / 分隔)+ 副标题。
|
||||
void _laneHeader(Canvas canvas, BarLayout layout, int li, List<Action> acts, double y) {
|
||||
final double labelMax = BarLayout.leftGutter - 68;
|
||||
final Color c0 = acts.isEmpty ? tokens.accent : Color(acts.first.color);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(Rect.fromLTWH(32, y + 8, 18, 18), const Radius.circular(5)),
|
||||
Paint()..color = c0,
|
||||
);
|
||||
_text(canvas, '${li + 1}', Offset(41, y + 17),
|
||||
color: tokens.chip, size: 10, align: TextAlign.center, weight: FontWeight.w700);
|
||||
if (acts.isEmpty) return;
|
||||
|
||||
// 多个动作合并为「A1 上料 / A2 定位」,最多两行。
|
||||
final String joined = acts.map((Action a) => '${a.id} ${a.name}').join(' / ');
|
||||
final TextPainter tp = TextPainter(
|
||||
text: TextSpan(
|
||||
text: joined,
|
||||
style: TextStyle(
|
||||
color: tokens.text,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontFamily: 'Microsoft YaHei UI',
|
||||
),
|
||||
),
|
||||
textDirection: ui.TextDirection.ltr,
|
||||
maxLines: 2,
|
||||
ellipsis: '…',
|
||||
)..layout(maxWidth: labelMax);
|
||||
tp.paint(canvas, Offset(60, y + 2));
|
||||
|
||||
final Station? st = project.stationById(acts.first.stationId);
|
||||
final String sub = '${st?.name ?? acts.first.stationId} · ${acts.first.driver}'
|
||||
'${acts.length > 1 ? ' · 共 ${acts.length} 个' : ''}';
|
||||
_textMax(canvas, sub, Offset(60, y + 32), labelMax, color: tokens.dim, size: 10);
|
||||
}
|
||||
|
||||
/// 绘制单个动作条块(投影 / 填充 / 描边 / 跨圈尾段 / 文字标注)。
|
||||
void _bar(Canvas canvas, BarLayout layout, Action a, UnitSettings u, double cycle) {
|
||||
final Color c = Color(a.color);
|
||||
final Rect r = layout.rectFor(a);
|
||||
final bool sel = selectedIds.contains(a.id);
|
||||
final bool crit = criticalActions.contains(a.id);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r.shift(const Offset(1.5, 2)), const Radius.circular(8)),
|
||||
Paint()..color = tokens.shadow.withValues(alpha: tokens.shadowOp),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
Paint()..color = c.withValues(alpha: 0.92),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.selOutline.withValues(alpha: sel ? 0.9 : 0.25),
|
||||
);
|
||||
if (crit) {
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.selOutline.withValues(alpha: sel ? 0.9 : 0.25),
|
||||
..strokeWidth = 2
|
||||
..color = tokens.crit,
|
||||
);
|
||||
// 关键路径条块额外叠加一圈加粗高亮描边。
|
||||
if (crit) {
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2
|
||||
..color = tokens.crit,
|
||||
);
|
||||
}
|
||||
|
||||
// 跨循环延续:把 360° 之后的部分回绕到左侧 0° 起绘制,
|
||||
// 使用 [Tokens.tailOp] 透明度淡化以区别于主体。
|
||||
if (a.wrap && u.autoSplitWrap) {
|
||||
final double wx = layout.xFor(a.endAngle - 360) - layout.plotLeft;
|
||||
final Rect tail = Rect.fromLTWH(layout.plotLeft, r.top, math.max(wx, 2), r.height);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(tail, const Radius.circular(8)),
|
||||
Paint()..color = c.withValues(alpha: tokens.tailOp),
|
||||
);
|
||||
_text(canvas, '跨循环延续 ${(a.endAngle - 360).toStringAsFixed(0)}°',
|
||||
Offset(layout.plotLeft + wx + 18, r.center.dy), color: tokens.warn, size: 10);
|
||||
}
|
||||
|
||||
// 文字放置策略:条块足够宽时内置名称与时长;否则视右侧剩余空间
|
||||
// 决定放到条块左侧还是右侧,避免文字越出绘图区。
|
||||
final double durMs = a.durationAngle / 360 * cycle;
|
||||
if (r.width > 150) {
|
||||
_text(canvas, a.name, Offset(r.left + 10, r.center.dy - 5),
|
||||
color: tokens.arcText, size: 11, weight: FontWeight.w700);
|
||||
_text(canvas, tfmt(durMs, u), Offset(r.left + 10, r.center.dy + 7),
|
||||
color: tokens.arcText.withValues(alpha: 0.8), size: 10);
|
||||
} else if (r.right + 170 > layout.plotRight) {
|
||||
_text(canvas, '${a.name} ${tfmt(durMs, u)}', Offset(r.left - 10, r.center.dy),
|
||||
color: c, size: 11, weight: FontWeight.w600, align: TextAlign.right);
|
||||
} else {
|
||||
_text(canvas, '${a.name} ${tfmt(durMs, u)}', Offset(r.right + 10, r.center.dy),
|
||||
color: c, size: 11, weight: FontWeight.w600);
|
||||
}
|
||||
_text(canvas, 'Δ${a.durationAngle.toStringAsFixed(0)}°', Offset(layout.plotRight - 4, r.center.dy),
|
||||
color: tokens.dim, size: 10, align: TextAlign.right);
|
||||
}
|
||||
if (a.wrap && u.autoSplitWrap) {
|
||||
final double wx = layout.xFor(a.endAngle - 360) - layout.plotLeft;
|
||||
final Rect tail = Rect.fromLTWH(layout.plotLeft, r.top, math.max(wx, 2), r.height);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(tail, const Radius.circular(8)),
|
||||
Paint()..color = c.withValues(alpha: tokens.tailOp),
|
||||
);
|
||||
_text(canvas, '跨循环延续 ${(a.endAngle - 360).toStringAsFixed(0)}°',
|
||||
Offset(layout.plotLeft + wx + 18, r.center.dy), color: tokens.warn, size: 10);
|
||||
}
|
||||
final double durMs = a.durationAngle / 360 * cycle;
|
||||
if (r.width > 150) {
|
||||
_text(canvas, a.name, Offset(r.left + 10, r.center.dy - 5),
|
||||
color: tokens.arcText, size: 11, weight: FontWeight.w700);
|
||||
_text(canvas, tfmt(durMs, u), Offset(r.left + 10, r.center.dy + 7),
|
||||
color: tokens.arcText.withValues(alpha: 0.8), size: 10);
|
||||
} else if (r.right + 170 > layout.plotRight) {
|
||||
_text(canvas, '${a.name} ${tfmt(durMs, u)}', Offset(r.left - 10, r.center.dy),
|
||||
color: c, size: 11, weight: FontWeight.w600, align: TextAlign.right);
|
||||
} else {
|
||||
_text(canvas, '${a.name} ${tfmt(durMs, u)}', Offset(r.right + 10, r.center.dy),
|
||||
color: c, size: 11, weight: FontWeight.w600);
|
||||
}
|
||||
_text(canvas, 'Δ${a.durationAngle.toStringAsFixed(0)}°', Offset(layout.plotRight - 4, r.center.dy),
|
||||
color: tokens.dim, size: 10, align: TextAlign.right);
|
||||
}
|
||||
|
||||
/// 绘制动作依赖连线(正交折线)。
|
||||
@@ -352,10 +373,10 @@ 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 (int i = 0; i < ordered.length; i++) {
|
||||
index[ordered[i].id] = i;
|
||||
}
|
||||
// 以「泳道序号」判断依赖的相邻关系(同泳道多个动作不再误判)。
|
||||
final Map<String, int> index = <String, int>{
|
||||
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
|
||||
};
|
||||
int k = 0;
|
||||
for (final Action to in ordered) {
|
||||
for (final Dependency d in to.deps) {
|
||||
@@ -390,10 +411,14 @@ class BarPainter extends CustomPainter {
|
||||
// 跨多行:扫描区间内所有条块边界,据此在外侧选一条竖直泳道。
|
||||
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++) {
|
||||
final Rect rr = layout.rectFor(ordered[r]);
|
||||
maxRight = math.max(maxRight, rr.right);
|
||||
minLeft = math.min(minLeft, rr.left);
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user