/// 圆形(极坐标)视图绘制器。 /// /// 职责:把 [Project] 中的动作绘制为同心圆环——角度表示相位 /// (0° 位于 12 点钟方向,顺时针递增),半径表示动作所属层级(layer)。 /// /// 架构位置: /// - 几何换算(圆心、各层半径、刻度半径)来自 [CircularLayout]; /// 极坐标换算复用 `layout.dart` 中的 [polar] 与 [arcPath]。 /// - 颜色取自 [Tokens],与条形视图及 SVG 导出保持同一视觉体系。 /// - 跨循环动作通过 [splitArcs] 拆成两段弧绘制,保证角度连续、视觉闭合。 library; import 'dart:math' as math; import 'dart:ui' as ui; import 'package:flutter/material.dart' hide Action; import '../layout/layout.dart'; import '../model/models.dart'; import '../model/units.dart'; import '../theme/tokens.dart'; /// 圆形视图的 [CustomPainter] 实现。 /// /// 所有角度以“12 点钟为 0°、顺时针为正”为约定,由 [polar] 完成换算。 class CircularPainter extends CustomPainter { /// 创建圆形视图绘制器。 /// /// 参数: /// - [project]:待绘制的工程数据(动作、依赖、视图开关)。 /// - [tokens]:当前主题令牌,决定所有颜色。 /// - [criticalActions]:关键路径上的动作 id 集合。 /// - [criticalDeps]:关键路径上的依赖集合,键格式 `fromId->toId`。 /// - [selectedId]:当前选中动作 id,可为空。 /// /// 无副作用;实例不缓存布局,每次 [paint] 都重新计算。 CircularPainter({ required this.project, required this.tokens, required this.criticalActions, required this.criticalDeps, required this.selectedIds, this.guideAngle, }); /// 待绘制的工程数据源。 final Project project; /// 当前主题令牌。 final Tokens tokens; /// 关键路径上的动作 id 集合。 final Set criticalActions; /// 关键路径上的依赖边集合,元素格式为 `fromId->toId`。 final Set criticalDeps; /// 当前选中的动作 id 集合(支持多选)。 final Set selectedIds; /// 拖拽动作弧端点时的参考角(度);非空时绘制一条径向虚线参考。 final double? guideAngle; /// 绘制整个圆形视图。 /// /// 参数 [canvas]/[size] 遵循 Flutter 绘制约定。 /// 图层顺序:表盘底 → 圆环背景 → 象限线 → 层号 → 依赖 → 动作弧 /// → 起点标记 / 方向箭头 / 刻度。 @override void paint(Canvas canvas, Size size) { final CircularLayout layout = CircularLayout(project, size); final UnitSettings u = project.units; final Offset c = layout.center; final double th = layout.th; final double tickR = layout.tickR; // 表盘底板:半径略大于最外圈刻度,形成一圈底色与边框。 canvas.drawCircle(c, tickR + 10, Paint()..color = tokens.dial); canvas.drawCircle( c, tickR + 10, Paint() ..style = PaintingStyle.stroke ..strokeWidth = 1.2 ..color = tokens.line2, ); // 圆环背景:每条轨道用一条粗描边构成环带,奇偶交替着色, // 并在环带内外沿各画一条细描边作为边界。 final List lanes = layout.lanes; final int layers = lanes.length; if (project.viewState.showRingBg) { for (int i = 0; i < layers; i++) { final double r = layout.radiusFor(lanes[i]); canvas.drawCircle( c, r, Paint() ..style = PaintingStyle.stroke ..strokeWidth = th ..color = i.isEven ? tokens.ringA : tokens.ringB, ); canvas.drawCircle( c, r - th / 2, Paint() ..style = PaintingStyle.stroke ..strokeWidth = 1 ..color = tokens.ringEdge, ); canvas.drawCircle( c, r + th / 2, Paint() ..style = PaintingStyle.stroke ..strokeWidth = 1 ..color = tokens.ringEdge, ); } } canvas.drawCircle(c, math.max(CircularLayout.r0 - th / 2, 8), Paint()..color = tokens.dial); // 相位分区环:在最外动作环与刻度环之间画一圈分区色带并标注名称。 if (project.viewState.showPhaseBands) _phaseRing(canvas, layout); // 轨道标签:为每条轨道挑选一个空位角度,避免压住该轨道的动作弧。 if (project.viewState.showLayerLabels) { for (int i = 0; i < layers; i++) { final double r = layout.radiusFor(lanes[i]); final double free = _freeAngle(lanes[i]); final Offset lp = polar(c, r, free); _text(canvas, 'L${i + 1}', lp, color: tokens.ringLabel, size: 10, align: TextAlign.center, weight: FontWeight.w700); } } // 依赖连线先于动作弧绘制,使其位于弧之下、不被遮挡。 if (project.viewState.showDeps) { 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); } } _placeArcChips(canvas, layout, chips); } // 逐个绘制动作弧。 for (final Action a in project.actions) { _action(canvas, layout, a, u); } // 拖拽端点时的径向虚线参考。 if (guideAngle != null) _guide(canvas, layout); // 起点标记、循环方向提示与外围刻度。 _startMarker(canvas, layout); _directionArrow(canvas, layout); if (project.viewState.showRuler) _ticks(canvas, layout); } /// 绘制相位分区环:在最外动作环与刻度环之间画一圈分区色带,标注分区名称, /// 并在每条边界处画一条径向虚线,便于与条形视图的分区对应。 void _phaseRing(Canvas canvas, CircularLayout layout) { final List zones = project.phaseZones.where((PhaseZone z) => z.endAngle > z.startAngle).toList(); if (zones.isEmpty) return; final Offset c = layout.center; // 加宽分区带(16px);tickR 已在外层动作环之外留出更大间距,避免挤在一起。 final double rBand = layout.tickR - 16; const double bandW = 16; // 底环,作为分区的“轨道”。 canvas.drawCircle( c, rBand, Paint() ..style = PaintingStyle.stroke ..strokeWidth = bandW ..color = tokens.track, ); // 分区配色(循环取用强调色系)。 const List pal = [ Color(0xFF4CC9F0), Color(0xFF7C5CFF), Color(0xFF34D399), Color(0xFFFFD166), Color(0xFFF472B6), ]; for (int i = 0; i < zones.length; i++) { final PhaseZone z = zones[i]; final Color col = pal[i % pal.length]; // 分区色带(跨圈会拆成两段)。 for (final List s in splitArcs(z.startAngle, z.endAngle)) { canvas.drawPath( arcPath(c, rBand, s[0], s[1]), Paint() ..style = PaintingStyle.stroke ..strokeWidth = bandW ..color = col.withValues(alpha: 0.85), ); } // 名称沿圆弧排列(切向),并按弧长截断,保证不超出色带。 final double mid = ((z.startAngle + z.endAngle) / 2) % 360; final double span = (z.endAngle - z.startAngle).clamp(0, 360); final double arcLen = 2 * math.pi * rBand * (span / 360); _arcLabel(canvas, c, rBand, mid, z.name, tokens.arcText, 11, math.max(arcLen - 10, 22)); // 边界径向虚线。 for (final double b in [z.startAngle, z.endAngle]) { final Offset p1 = polar(c, rBand - bandW / 2 - 5, b); final Offset p2 = polar(c, rBand + bandW / 2 + 5, b); _dashed(canvas, p1, p2, col.withValues(alpha: 0.9)); } } } /// 在两点之间画一条虚线(用于分区边界参考)。 void _dashed(Canvas canvas, Offset a, Offset b, Color col) { const double dash = 3; const double gap = 3; final double total = (b - a).distance; if (total <= 0) return; final Offset dir = (b - a) / total; double t = 0; final Paint paint = Paint() ..color = col ..strokeWidth = 1.4 ..strokeCap = StrokeCap.round; while (t < total) { final double end = math.min(t + dash, total); canvas.drawLine(a + dir * t, a + dir * end, paint); t = end + gap; } } /// 沿圆弧切向绘制文字,并按 [maxWidth] 截断,保证不超出色带。 /// /// 文字位于半径 [r]、角度 [midDeg] 处,旋转到该点的切线方向; /// 当文字位于左半圈(90°–270°)时翻转 180°,避免倒置。 void _arcLabel(Canvas canvas, Offset c, double r, double midDeg, String text, Color col, double size, double maxWidth) { final TextPainter tp = TextPainter( text: TextSpan( text: text, style: TextStyle(color: col, fontSize: size, fontWeight: FontWeight.w700, fontFamily: 'Microsoft YaHei UI'), ), textDirection: ui.TextDirection.ltr, maxLines: 1, ellipsis: '…', )..layout(maxWidth: maxWidth); final Offset pos = polar(c, r, midDeg); final double rad = midDeg * math.pi / 180; final bool flip = midDeg > 90 && midDeg < 270; canvas.save(); canvas.translate(pos.dx, pos.dy); canvas.rotate(flip ? rad + math.pi : rad); tp.paint(canvas, Offset(-tp.width / 2, -tp.height / 2)); canvas.restore(); } /// 为指定 [layer] 选一个尽量不被动作弧覆盖的角度,用于放置层号“L1/L2…”。 /// /// 从候选角列表(围绕正上方 270° 左右摆动)中挑选第一个与本层任何 /// 动作弧都不重叠的角度;若全部冲突则回退到 270°。 double _freeAngle(int layer) { const List cands = [270, 278, 262, 286, 254, 294, 246, 302, 238, 310]; final List inLayer = project.actions.where((Action a) => a.layer == layer).toList(); for (final double cand in cands) { bool ok = true; for (final Action a in inLayer) { if (_inArc(a, cand)) { ok = false; break; } } if (ok) return cand; } return 270; } /// 判断角度 [deg] 是否落在动作 [a] 的弧范围内。 /// /// 处理两类情况:普通动作(结束角 ≤ 360)用闭区间判定; /// 跨循环动作(结束角 > 360)用“大于起点 或 小于回绕终点”的并集判定。 /// 两侧各留 0.5° 容差以吸收浮点误差。 bool _inArc(Action a, double deg) { final double n = deg % 360; if (a.endAngle <= 360) return n >= a.startAngle - 0.5 && n <= a.endAngle + 0.5; return n >= a.startAngle - 0.5 || n <= (a.endAngle - 360) + 0.5; } /// 绘制单个动作弧。 /// /// 算法: /// - 通过 [splitArcs] 把可能跨循环的动作拆成一到两段,逐段绘制。 /// - 每段先画加宽阴影弧,再画本体弧;跨循环的“尾巴”段(第二段) /// 以 [Tokens.tailOp] 淡化,并额外叠一层高透明度描边以示区分。 /// - 关键动作沿弧画 [Tokens.crit] 描边;选中动作在外侧画强调色细弧。 /// - 在弧中点附近放置 `序号. id 名称` 与起止角度文本; /// 短弧(时长 < 38°)使用更小字号并收紧行距。 /// /// 参数 [u] 为当前单位设置(保留以对齐调用接口,当前未直接使用)。 void _action(Canvas canvas, CircularLayout layout, Action a, UnitSettings u) { final Offset c = layout.center; final double r = layout.radiusFor(a.layer); final double th = layout.th; final Color col = Color(a.color); final bool sel = selectedIds.contains(a.id); final bool crit = criticalActions.contains(a.id); // 跨循环动作会被拆成 [a0,360] 与 [0,a1-360] 两段。 final List> segs = splitArcs(a.startAngle, a.endAngle); for (int k = 0; k < segs.length; k++) { // 第二段且为跨循环时视为“尾巴”,需淡化处理。 final bool tail = a.wrap && k == 1; final Path p = arcPath(c, r, segs[k][0], segs[k][1]); // 圆周色块不加描边 / 阴影,保持干净。 canvas.drawPath( p, Paint() ..style = PaintingStyle.stroke ..strokeWidth = th ..strokeCap = a.wrap ? StrokeCap.butt : StrokeCap.round ..color = col.withValues(alpha: tail ? tokens.tailOp : 1), ); if (tail) { canvas.drawPath( p, Paint() ..style = PaintingStyle.stroke ..strokeWidth = th ..strokeCap = StrokeCap.butt ..color = col.withValues(alpha: 0.9), ); } } if (crit) { for (final List s in segs) { canvas.drawPath( arcPath(c, r, s[0], s[1]), Paint() ..style = PaintingStyle.stroke ..strokeWidth = 2 ..color = tokens.crit, ); } } if (sel) { for (final List s in segs) { canvas.drawPath( arcPath(c, r + th / 2 + 8, s[0], s[1]), Paint() ..style = PaintingStyle.stroke ..strokeWidth = 1.6 ..color = tokens.accent, ); } // 选中时在弧两端绘制把手:提示可拖拽端点改持续角(触屏更好抓)。 for (final Offset h in [ polar(c, r, a.startAngle), polar(c, r, math.min(a.endAngle, 360)), ]) { canvas.drawCircle(h, 6, Paint()..color = tokens.accent); canvas.drawCircle( h, 6, Paint() ..style = PaintingStyle.stroke ..strokeWidth = 2 ..color = Colors.white, ); } } // 文字沿圆弧排列并按弧长截断,保证始终位于动作色带之内。 final double mid = (a.startAngle + a.endAngle) / 2; final int step = project.actions.indexOf(a) + 1; final double span = a.wrap ? (360 - a.startAngle) : a.durationAngle; final double arcLen = 2 * math.pi * r * (span.clamp(0, 360) / 360); _arcLabel(canvas, c, r, mid, '$step. ${a.id} ${a.name}', tokens.arcText, 11, math.max(arcLen - 12, 20)); } /// 绘制圆形视图中的依赖连线。 /// /// 路径由四段组成:从源弧末端沿半径到中间半径 [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); 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; } if (crit) { canvas.drawPath( p, Paint() ..style = PaintingStyle.stroke ..strokeWidth = 5 ..strokeCap = StrokeCap.round ..color = col.withValues(alpha: 0.2), ); } canvas.drawPath( p, Paint() ..style = PaintingStyle.stroke ..strokeWidth = crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9) ..strokeCap = StrokeCap.round ..color = col, ); _arrow(canvas, p3, tipDir, col); 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); } /// 统一绘制圆周视图的依赖标签:沿半径方向逐级外移 / 内移避让,避免相互重叠。 /// /// 估算每个标签的占位矩形(文本长度 × 字号),若与已放置标签相交则按 /// +14 / −14 / +28 / −28 … 的步长沿半径方向挪动,直到找到空位。 void _placeArcChips(Canvas canvas, CircularLayout layout, List<_ArcChip> chips) { final Offset c = layout.center; final List placed = []; const double size = 8.5; for (final _ArcChip chip in chips) { final double w = chip.text.runes.length * size * 0.62 + 8; final double h = size * 1.7; double r = chip.r; Rect rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h); for (int i = 1; i <= 10; i++) { if (!placed.any((Rect o) => o.inflate(1.5).overlaps(rect))) break; final double step = 14.0 * ((i + 1) ~/ 2); r = chip.r + (i.isOdd ? step : -step); rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h); } placed.add(rect); final double arcLen = 2 * math.pi * r * 0.9; _arcLabel(canvas, c, r, chip.deg, chip.text, chip.color, size, math.max(math.min(arcLen, 200), 40)); } } /// 在 [tip] 处绘制指向 [dir] 方向的实心三角箭头。 /// /// 与条形视图不同,这里会先把 [dir] 归一化;长度过短时直接返回。 void _arrow(Canvas canvas, Offset tip, Offset dir, Color col) { final double len = dir.distance; if (len < 0.001) return; final Offset u = dir / len; const double s = 6; final Offset b = tip - u * s; final Offset n = Offset(-u.dy, u.dx) * s * 0.5; final Path p = Path() ..moveTo(tip.dx, tip.dy) ..lineTo(b.dx + n.dx, b.dy + n.dy) ..lineTo(b.dx - n.dx, b.dy - n.dy) ..close(); canvas.drawPath(p, Paint()..color = col); } /// 绘制拖拽端点时的径向虚线参考与角度标注。 void _guide(Canvas canvas, CircularLayout layout) { final Offset c = layout.center; final double deg = guideAngle!; final Offset p1 = polar(c, math.max(CircularLayout.r0 - 24, 8), deg); final Offset p2 = polar(c, layout.tickR + 6, deg); final Paint paint = Paint() ..color = tokens.accent ..strokeWidth = 1.4 ..strokeCap = StrokeCap.round; const double dash = 6; const double gap = 6; final double total = (p2 - p1).distance; if (total > 0) { final Offset dir = (p2 - p1) / total; double t = 0; while (t < total) { final double end = math.min(t + dash, total); canvas.drawLine(p1 + dir * t, p1 + dir * end, paint); t = end + gap; } } _text(canvas, '${deg.toStringAsFixed(1)}°', polar(c, layout.tickR + 22, deg), color: tokens.accent, size: 11, align: TextAlign.center, weight: FontWeight.w700); } /// 绘制 0° 起点标记:顶部朝下的三角与“0° · 12 点钟”文字。 void _startMarker(Canvas canvas, CircularLayout layout) { final Offset c = layout.center; // 放在刻度数字之外,避免与顶部的“0°”刻度标签重叠。 final double r = layout.tickR + 46; final Offset tip = Offset(c.dx, c.dy - r - 22); final Path p = Path() ..moveTo(tip.dx, tip.dy) ..lineTo(tip.dx - 9, tip.dy - 15) ..lineTo(tip.dx + 9, tip.dy - 15) ..close(); canvas.drawPath(p, Paint()..color = tokens.accent); _text(canvas, '0° · 12 点钟', Offset(c.dx, tip.dy - 30), color: tokens.accent, size: 11, align: TextAlign.center, weight: FontWeight.w600); } /// 绘制循环方向指示:外圈一段短弧 + 沿切线的箭头,标注顺时针。 void _directionArrow(Canvas canvas, CircularLayout layout) { final Offset c = layout.center; // 放在度数 / 时间两排标签之外,避免箭头与文字相撞。 final double r = layout.tickR + 72; canvas.drawPath( arcPath(c, r, 25, 60), Paint() ..style = PaintingStyle.stroke ..strokeWidth = 1.8 ..strokeCap = StrokeCap.round ..color = tokens.accent2, ); // 箭头指向弧的终点,方向与切线一致(顺时针)。 const double te = 60; final double trad = te * math.pi / 180; final Offset tip = polar(c, r, te); final Offset tan = Offset(math.cos(trad), math.sin(trad)); const double s = 7; final Offset b = tip - tan * s; final Offset n = Offset(-tan.dy, tan.dx) * s * 0.5; final Path head = Path() ..moveTo(tip.dx, tip.dy) ..lineTo(b.dx + n.dx, b.dy + n.dy) ..lineTo(b.dx - n.dx, b.dy - n.dy) ..close(); canvas.drawPath(head, Paint()..color = tokens.accent2); _text(canvas, '顺时针 CW', polar(c, r + 20, 42), color: tokens.accent2, size: 10, align: TextAlign.center, weight: FontWeight.w600); } /// 绘制外围角度刻度。 /// /// 每 5° 一个刻度,10° 为中刻度,30° 为主刻度并标注度数; /// 90° 的整数倍使用强调色加粗。度数外侧再标注等价的绝对时间。 void _ticks(Canvas canvas, CircularLayout layout) { final Offset c = layout.center; final double r = layout.tickR; final UnitSettings u = project.units; final double cycle = project.cycle.durationMs; for (int d = 0; d < 360; d += 5) { final bool major = d % 30 == 0; final bool mid = d % 10 == 0; final Offset p1 = polar(c, r, d.toDouble()); final Offset p2 = polar(c, r + (major ? 20 : (mid ? 13 : 7)), d.toDouble()); canvas.drawLine( p1, p2, Paint() ..strokeWidth = major ? 1.4 : 1 ..color = major ? tokens.line2 : tokens.line, ); if (major) { final Offset lp = polar(c, r + 34, d.toDouble()); _text(canvas, '$d°', lp, color: d % 90 == 0 ? tokens.accent : tokens.sub, size: 10, align: TextAlign.center, weight: d % 90 == 0 ? FontWeight.w700 : FontWeight.normal); // 度数外侧增加一个时间数值(字号与度数保持一致)。 final Offset tp = polar(c, r + 48, d.toDouble()); _text(canvas, tvalStr(d / 360 * cycle, u, dec: u.timeUnit == TimeUnit.ms ? 0 : 1), tp, color: tokens.sub, size: 10, align: TextAlign.center); } } } /// 构造并布局一个 [TextPainter]。 /// /// 统一使用微软雅黑字体;返回已完成 layout 的实例。 TextPainter _tp(String s, double size, Color color, FontWeight weight) { return TextPainter( text: TextSpan( text: s, style: TextStyle(color: color, fontSize: size, fontWeight: weight, fontFamily: 'Microsoft YaHei UI'), ), textDirection: ui.TextDirection.ltr, )..layout(); } /// 便捷文本绘制。 /// /// 在 [at] 处按 [align] 对齐绘制字符串 [s](默认左对齐、垂直居中)。 /// [color] 缺省时使用 [Tokens.text]。 void _text(Canvas canvas, String s, Offset at, {Color? color, double size = 12, FontWeight weight = FontWeight.normal, TextAlign align = TextAlign.left}) { final TextPainter tp = _tp(s, size, color ?? tokens.text, weight); double dx = at.dx; if (align == TextAlign.center) dx -= tp.width / 2; if (align == TextAlign.right) dx -= tp.width; tp.paint(canvas, Offset(dx, at.dy - tp.height / 2)); } /// 始终返回 `true`。 /// /// 绘制完全依赖每次重建的布局与外部状态,且本绘制器不做缓存, /// 因此保守地要求每次重绘。 @override bool shouldRepaint(covariant CircularPainter old) => true; } /// 圆周视图依赖标签的待放置描述:半径、角度、文本与颜色。 /// /// 先在依赖遍历中收集,再由 [CircularPainter] 统一做径向避让绘制。 class _ArcChip { const _ArcChip(this.r, this.deg, this.text, this.color); /// 期望的标签半径(像素)。 final double r; /// 期望的标签角度(度,0° = 12 点钟、顺时针)。 final double deg; /// 标签文本(如 `A1→A2 SS+30°`)。 final String text; /// 文本颜色(按依赖类型区分)。 final Color color; }