Files
pipelines/app/lib/features/graph/widgets/definition_graph_canvas.dart
T
alan 7872e57d40 Run card mini-map and stage strip; graph edge hover highlight
The show_run card carries the run's graph and per-stage progress (bounded by
the graph, not the run length) and draws a still mini-map with the run graph
plus a stage strip with status, visits and time. Hovering or tapping an edge
in the pipeline and run graphs highlights it, its label and endpoints, with a
tooltip naming from -> to, the outcome and, for runs, how often it was taken.

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

113 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import '../domain/graph_definition.dart';
import '../layout/layout_models.dart';
import '../painting/graph_edge_layer.dart';
import '../routing/route_models.dart';
import 'graph_canvas_style.dart';
import 'graph_edge_hover.dart';
import 'graph_stage_node.dart';
/// The measured definition canvas at any viewport size and selection.
///
/// Used by both the inline [GraphViewport] and the expanded presentation: the
/// passive edge layer paints behind the native nodes and outcome labels, and
/// every node reports selection through [onSelected].
class DefinitionGraphCanvas extends StatelessWidget {
const DefinitionGraphCanvas({
super.key,
required this.nodes,
required this.layout,
required this.routing,
required this.style,
required this.selectedStage,
required this.onSelected,
});
final List<GraphNode> nodes;
final GraphLayout layout;
final GraphRouting routing;
final GraphCanvasStyle style;
final String? selectedStage;
final ValueChanged<String> onSelected;
@override
Widget build(BuildContext context) {
final nodesByKey = <String, GraphNode>{
for (final node in nodes) node.key: node,
};
final size = Size(routing.width, routing.height);
return GraphEdgeHover(
layout: layout,
routing: routing,
describe: describeGraphEdge,
builder: (context, highlighted, select) =>
_canvas(context, nodesByKey, size, highlighted, select),
);
}
Widget _canvas(
BuildContext context,
Map<String, GraphNode> nodesByKey,
Size size,
int? highlighted,
ValueChanged<int> select,
) {
return Stack(
clipBehavior: Clip.none,
children: [
// The passive layer comes first so every edge paints behind the native
// nodes and labels without taking their input.
Positioned.fill(
child: GraphEdgeLayer(
routes: routing.routes,
canvasSize: size,
color: style.edgeColor,
strokeWidth: style.edgeWidth,
),
),
Positioned.fill(
child: graphEdgeHighlight(
context: context,
layout: layout,
routing: routing,
highlighted: highlighted,
edgeWidth: style.edgeWidth,
),
),
for (final box in layout.nodes)
Positioned(
left: box.x,
top: box.y,
width: box.width,
height: box.height,
child: GraphStageNode(
node: nodesByKey[box.key]!,
selected: box.key == selectedStage,
onSelected: onSelected,
),
),
for (final label in routing.labels)
Positioned(
left: label.x,
top: label.y,
child: graphEdgeLabel(
context: context,
highlighted: label.edgeId == highlighted,
description: describeGraphEdge(routing.routeFor(label.edgeId)!),
onSelect: () => select(label.edgeId),
child: Text(
routing.routeFor(label.edgeId)!.label,
style: graphEdgeLabelStyle(
context,
style.labelStyle,
highlighted: label.edgeId == highlighted,
),
),
),
),
],
);
}
}