Files
pipelines/app/lib/features/graph/painting/run_graph_edge_layer.dart
T
alan 413c923e77 Graph: stage popover with the prompt, tools, configs and run facts
Tapping or pressing Enter on a stage in the pipeline or run graph (inline
and full screen) opens a card anchored to the node: type, config chips,
tools, collapsed permissions, the prompt clamped with Show all (commands,
gate or operator instructions by type), limits and routes, and for runs
the status, visits, time, verdict, handoff and failure. Open definition
keeps the old tap target; Open visit the old run tap. It follows pan and
zoom, closes on outside tap, Escape or the same node, and opens as a
bottom sheet on a narrow viewport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:19:18 +00:00

146 lines
4.8 KiB
Dart

import 'package:flutter/foundation.dart' show listEquals;
import 'package:flutter/material.dart';
import '../routing/route_models.dart';
import 'graph_edge_layer.dart';
/// The run graph's route painting: the landed `GraphEdgePainter` geometry
/// (paths and arrowheads) with the two route classes run evidence needs on one
/// passive layer. No route is re-routed and no style is assumed here.
/// A passive canvas that draws taken routes as solid, arrowed strokes and
/// untaken routes as dashed, arrowless strokes behind them.
///
/// The caller supplies the already-routed [executedRoutes] and
/// [untakenRoutes], the graph-space [canvasSize] and its native theme colours.
/// The layer never takes pointer input, so nodes and labels keep their gestures.
class RunGraphEdgeLayer extends StatelessWidget {
const RunGraphEdgeLayer({
super.key,
required this.executedRoutes,
required this.untakenRoutes,
required this.canvasSize,
required this.executedColor,
required this.untakenColor,
required this.strokeWidth,
});
final List<EdgeRoute> executedRoutes;
final List<EdgeRoute> untakenRoutes;
final Size canvasSize;
final Color executedColor;
final Color untakenColor;
final double strokeWidth;
@override
Widget build(BuildContext context) => CustomPaint(
size: canvasSize,
painter: RunGraphEdgePainter(
executedRoutes: executedRoutes,
untakenRoutes: untakenRoutes,
executedColor: executedColor,
untakenColor: untakenColor,
strokeWidth: strokeWidth,
),
);
}
/// Paints a [RunGraphEdgeLayer].
///
/// Executed routes reuse the landed [GraphEdgePainter] path and arrow geometry;
/// untaken routes are the same polyline broken into native-sized dashes and
/// never receive an arrowhead. Public so the compositor and its tests share one
/// decision about which class of route gets an arrow.
class RunGraphEdgePainter extends CustomPainter {
RunGraphEdgePainter({
required this.executedRoutes,
required this.untakenRoutes,
required this.executedColor,
required this.untakenColor,
required this.strokeWidth,
}) : assert(strokeWidth > 0),
_executed = GraphEdgePainter(
routes: executedRoutes,
color: executedColor,
strokeWidth: strokeWidth,
),
_executedLine = Paint()
..color = executedColor
..strokeWidth = strokeWidth
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round,
_untakenLine = Paint()
..color = untakenColor
..strokeWidth = strokeWidth
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round,
_arrow = Paint()
..color = executedColor
..style = PaintingStyle.fill;
final List<EdgeRoute> executedRoutes;
final List<EdgeRoute> untakenRoutes;
final Color executedColor;
final Color untakenColor;
final double strokeWidth;
final GraphEdgePainter _executed;
final Paint _executedLine;
final Paint _untakenLine;
final Paint _arrow;
/// Dash and gap lengths in graph space; a dash never becomes a route style.
static const double dashLength = 12;
static const double dashGap = 8;
@override
void paint(Canvas canvas, Size size) {
if (executedRoutes.isEmpty && untakenRoutes.isEmpty) return;
canvas.save();
canvas.clipRect(Offset.zero & size);
for (final route in untakenRoutes) {
if (route.points.length < 2) continue;
canvas.drawPath(dashedPath(route), _untakenLine);
}
for (final route in executedRoutes) {
if (route.points.length < 2) continue;
canvas.drawPath(_executed.linePath(route), _executedLine);
}
for (final route in executedRoutes) {
if (route.points.length < 2) continue;
canvas.drawPath(_executed.arrowPath(route), _arrow);
}
canvas.restore();
}
/// The route's polyline split into [dashLength] segments separated by
/// [dashGap], following every orthogonal bend without smoothing.
Path dashedPath(EdgeRoute route) {
final source = _executed.linePath(route);
final dashed = Path();
for (final metric in source.computeMetrics()) {
var start = 0.0;
while (start < metric.length) {
final end = start + dashLength < metric.length
? start + dashLength
: metric.length;
dashed.addPath(metric.extractPath(start, end), Offset.zero);
start = end + dashGap;
}
}
return dashed;
}
/// Passive like the landed edge layer: every point misses.
@override
bool hitTest(Offset position) => false;
@override
bool shouldRepaint(RunGraphEdgePainter oldDelegate) =>
oldDelegate.executedColor != executedColor ||
oldDelegate.untakenColor != untakenColor ||
oldDelegate.strokeWidth != strokeWidth ||
!listEquals(oldDelegate.executedRoutes, executedRoutes) ||
!listEquals(oldDelegate.untakenRoutes, untakenRoutes);
}