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>
This commit is contained in:
2026-12-03 12:56:51 +00:00
parent c4de1de27b
commit 7872e57d40
17 changed files with 1709 additions and 51 deletions
@@ -1,10 +1,11 @@
import 'package:flutter/widgets.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.
@@ -36,6 +37,22 @@ class DefinitionGraphCanvas extends StatelessWidget {
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: [
@@ -49,6 +66,15 @@ class DefinitionGraphCanvas extends StatelessWidget {
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,
@@ -65,9 +91,19 @@ class DefinitionGraphCanvas extends StatelessWidget {
Positioned(
left: label.x,
top: label.y,
child: Text(
routing.routeFor(label.edgeId)!.label,
style: style.labelStyle,
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,
),
),
),
),
],
@@ -0,0 +1,282 @@
import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/material.dart';
import '../domain/graph_protocol.dart';
import '../layout/layout_models.dart';
import '../painting/edge_highlight_layer.dart';
import '../painting/edge_hit_test.dart';
import '../routing/route_models.dart';
/// Builds a graph canvas with [highlighted] (an edge id, or null) emphasized.
/// [select] highlights an edge without a pointer, e.g. from semantics.
typedef GraphEdgeHoverBuilder =
Widget Function(
BuildContext context,
int? highlighted,
ValueChanged<int> select,
);
/// How far from a route, in screen pixels, a pointer still counts as on it.
const double graphEdgeHitTolerance = 8;
/// Highlights the edge under the pointer of a graph canvas, and shows what it
/// is in a tooltip: hovering with a mouse, or tapping with touch (tap again
/// elsewhere to clear).
///
/// Wraps the canvas in graph space, inside any pan/zoom transform, so hits are
/// tested against the routed polylines and label boxes with a tolerance that
/// stays [graphEdgeHitTolerance] screen pixels at every zoom. Nodes keep their
/// own taps; a point over a node is never an edge.
class GraphEdgeHover extends StatefulWidget {
const GraphEdgeHover({
super.key,
required this.layout,
required this.routing,
required this.describe,
required this.builder,
});
final GraphLayout layout;
final GraphRouting routing;
/// The tooltip text for one edge.
final String Function(EdgeRoute route) describe;
final GraphEdgeHoverBuilder builder;
@override
State<GraphEdgeHover> createState() => _GraphEdgeHoverState();
}
class _GraphEdgeHoverState extends State<GraphEdgeHover> {
final OverlayPortalController _tooltip = OverlayPortalController();
int? _hovered;
int? _pinned;
Offset? _pointer;
int? get _highlighted => _hovered ?? _pinned;
/// Graph-space pixels per screen pixel under the current transform.
double _tolerance() {
final box = context.findRenderObject();
if (box is! RenderBox || !box.attached) return graphEdgeHitTolerance;
final scale =
(box.localToGlobal(const Offset(1, 0)) - box.localToGlobal(Offset.zero))
.distance;
return scale <= 0 ? graphEdgeHitTolerance : graphEdgeHitTolerance / scale;
}
int? _hit(Offset local) => hitTestEdge(
routes: widget.routing.routes,
labels: widget.routing.labels,
nodes: widget.layout.nodes,
point: local,
tolerance: _tolerance(),
);
void _update({int? hovered, int? pinned, Offset? pointer, bool pin = false}) {
final nextPinned = pin ? pinned : _pinned;
if (hovered == _hovered && nextPinned == _pinned && pointer == _pointer) {
return;
}
setState(() {
_hovered = hovered;
_pinned = nextPinned;
_pointer = pointer;
});
_syncTooltip();
}
void _syncTooltip() {
if (_highlighted != null && _pointer != null) {
_tooltip.show();
} else {
_tooltip.hide();
}
}
@override
void didUpdateWidget(covariant GraphEdgeHover oldWidget) {
super.didUpdateWidget(oldWidget);
// A re-laid graph may have dropped the highlighted edge.
bool known(int? id) => id != null && widget.routing.routeFor(id) != null;
if (!known(_hovered)) _hovered = null;
if (!known(_pinned)) _pinned = null;
if (_highlighted == null) _pointer = null;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _syncTooltip();
});
}
@override
Widget build(BuildContext context) {
final canvas = MouseRegion(
onHover: (event) {
final id = _hit(event.localPosition);
_update(hovered: id, pointer: id == null ? null : event.position);
},
onExit: (_) =>
_update(hovered: null, pointer: _pinned == null ? null : _pointer),
child: GestureDetector(
behavior: HitTestBehavior.translucent,
// A tap pins the edge under it (touch has no hover); tapping it again
// or anywhere off an edge clears it.
onTapUp: (details) {
final id = _hit(details.localPosition);
final hovered = details.kind == PointerDeviceKind.mouse
? _hovered
: null;
final pinned = id == _pinned ? null : id;
_update(
hovered: hovered,
pinned: pinned,
pin: true,
pointer: (hovered ?? pinned) == null
? null
: details.globalPosition,
);
},
child: widget.builder(context, _highlighted, (id) {
_update(hovered: _hovered, pinned: id, pin: true, pointer: _pointer);
}),
),
);
if (Overlay.maybeOf(context) == null) return canvas;
return OverlayPortal(
controller: _tooltip,
overlayChildBuilder: _buildTooltip,
child: canvas,
);
}
Widget _buildTooltip(BuildContext context) {
final id = _highlighted;
final pointer = _pointer;
final route = id == null ? null : widget.routing.routeFor(id);
final overlay = Overlay.of(context).context.findRenderObject();
if (route == null || pointer == null || overlay is! RenderBox) {
return const SizedBox.shrink();
}
final local = overlay.globalToLocal(pointer);
final size = overlay.size;
final theme = Theme.of(context);
final colors = theme.colorScheme;
const gap = 14.0;
final flipX = local.dx > size.width * 0.6;
final flipY = local.dy > size.height * 0.75;
return Positioned(
left: flipX ? null : local.dx + gap,
right: flipX ? size.width - local.dx + gap : null,
top: flipY ? null : local.dy + gap,
bottom: flipY ? size.height - local.dy + gap : null,
child: IgnorePointer(
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: size.width * 0.6),
child: Material(
key: const Key('graph-edge-tooltip'),
color: colors.inverseSurface,
elevation: 2,
borderRadius: BorderRadius.circular(6),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
child: Text(
widget.describe(route),
style: theme.textTheme.bodySmall?.copyWith(
color: colors.onInverseSurface,
),
),
),
),
),
),
);
}
}
/// The highlight layer a canvas places above its edges and below its nodes,
/// or nothing when no edge is highlighted.
Widget graphEdgeHighlight({
required BuildContext context,
required GraphLayout layout,
required GraphRouting routing,
required int? highlighted,
required double edgeWidth,
}) {
final route = highlighted == null ? null : routing.routeFor(highlighted);
if (route == null) return const SizedBox.shrink();
final endpoints = [
?layout.nodeFor(route.source),
if (route.target != route.source) ?layout.nodeFor(route.target),
];
return IgnorePointer(
child: CustomPaint(
key: ValueKey('graph-edge-highlight:${route.id}'),
size: Size(routing.width, routing.height),
painter: EdgeHighlightPainter(
route: route,
endpoints: endpoints,
color: Theme.of(context).colorScheme.primary,
strokeWidth: edgeWidth * 2.5,
),
),
);
}
/// What an edge is, for its tooltip and screen readers: `from → to`, the
/// outcome, and for a run how many times it was taken ([taken] null for a
/// definition).
String describeGraphEdge(EdgeRoute route, {int? taken}) {
final lines = [
'${nodeDisplayLabel(route.source)} → ${nodeDisplayLabel(route.target)}',
'Outcome: ${route.label}',
if (taken != null)
switch (taken) {
0 => 'Not taken',
1 => 'Taken once',
_ => 'Taken $taken times',
},
];
return lines.join('\n');
}
/// The label style of a highlighted edge: [base] on the emphasis container.
TextStyle graphEdgeLabelStyle(
BuildContext context,
TextStyle base, {
required bool highlighted,
}) => highlighted
? base.copyWith(color: Theme.of(context).colorScheme.onPrimaryContainer)
: base;
/// An outcome label drawn emphasized while its edge is highlighted. The
/// emphasis is a backdrop only, so the measured label box does not change.
/// [description] names the edge for screen readers; activating it highlights
/// the edge through [onSelect].
Widget graphEdgeLabel({
required BuildContext context,
required Widget child,
required bool highlighted,
required String description,
required VoidCallback onSelect,
}) {
final colors = Theme.of(context).colorScheme;
return Semantics(
container: true,
label: description,
selected: highlighted,
onTap: onSelect,
child: ExcludeSemantics(
child: !highlighted
? child
: DecoratedBox(
decoration: BoxDecoration(
color: colors.primaryContainer,
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(color: colors.primaryContainer, spreadRadius: 2),
],
),
child: child,
),
),
);
}
@@ -7,6 +7,7 @@ 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';
import 'measured_child.dart';
@@ -199,56 +200,115 @@ class RunGraphCanvas extends StatelessWidget {
final size = Size(routing.width, routing.height);
final activeStage = state.activeStage;
final executedColor = Theme.of(context).colorScheme.primary;
return Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
child: RunGraphEdgeLayer(
executedRoutes: executed,
untakenRoutes: untaken,
canvasSize: size,
executedColor: executedColor,
untakenColor: style.edgeColor,
strokeWidth: style.edgeWidth,
),
),
for (final box in layout.nodes)
Positioned(
left: box.x,
top: box.y,
width: box.width,
height: box.height,
child: RunGraphNode(
node: nodesByKey[box.key]!,
recordedStatus: recordedStatuses[box.key],
selected: box.key == selectedStage,
active: box.key == activeStage,
opensVisit:
!nodesByKey[box.key]!.terminal &&
state.isStageVisited(box.key),
onSelected: onStageSelected,
String describe(EdgeRoute route) => describeGraphEdge(
route,
taken: state.routeOrder(route.source, route.outcome, route.target).length,
);
return GraphEdgeHover(
layout: layout,
routing: routing,
describe: describe,
builder: (context, highlighted, select) => Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
child: RunGraphEdgeLayer(
executedRoutes: executed,
untakenRoutes: untaken,
canvasSize: size,
executedColor: executedColor,
untakenColor: style.edgeColor,
strokeWidth: style.edgeWidth,
),
),
// A run labels only the routes that actually happened.
for (final label in routing.labels)
if (executedIds.contains(label.edgeId))
Positioned(
left: label.x,
top: label.y,
child: _takenLabel(
routing.routeFor(label.edgeId)!,
executedColor,
),
Positioned.fill(
child: graphEdgeHighlight(
context: context,
layout: layout,
routing: routing,
highlighted: highlighted,
edgeWidth: style.edgeWidth,
),
],
),
..._placed(
context,
nodesByKey,
executedIds,
executedColor,
activeStage,
highlighted,
select,
describe,
),
],
),
);
}
Widget _takenLabel(EdgeRoute route, Color color) => RunRouteLabel(
List<Widget> _placed(
BuildContext context,
Map<String, GraphNode> nodesByKey,
Set<int> executedIds,
Color executedColor,
String? activeStage,
int? highlighted,
ValueChanged<int> select,
String Function(EdgeRoute) describe,
) {
return [
for (final box in layout.nodes)
Positioned(
left: box.x,
top: box.y,
width: box.width,
height: box.height,
child: RunGraphNode(
node: nodesByKey[box.key]!,
recordedStatus: recordedStatuses[box.key],
selected: box.key == selectedStage,
active: box.key == activeStage,
opensVisit:
!nodesByKey[box.key]!.terminal && state.isStageVisited(box.key),
onSelected: onStageSelected,
),
),
// A run labels only the routes that actually happened, and the route
// being highlighted so its outcome reads where it is drawn.
for (final label in routing.labels)
if (executedIds.contains(label.edgeId) || label.edgeId == highlighted)
Positioned(
left: label.x,
top: label.y,
child: graphEdgeLabel(
context: context,
highlighted: label.edgeId == highlighted,
description: describe(routing.routeFor(label.edgeId)!),
onSelect: () => select(label.edgeId),
child: _takenLabel(
context,
routing.routeFor(label.edgeId)!,
executedColor,
highlighted: label.edgeId == highlighted,
),
),
),
];
}
Widget _takenLabel(
BuildContext context,
EdgeRoute route,
Color color, {
required bool highlighted,
}) => RunRouteLabel(
edgeId: route.id,
label: route.label,
order: state.routeOrder(route.source, route.outcome, route.target),
style: style.labelStyle,
style: graphEdgeLabelStyle(
context,
style.labelStyle,
highlighted: highlighted,
),
color: color,
);
}
@@ -48,8 +48,13 @@ class RunGraphView extends StatefulWidget {
this.now,
this.showHeader = true,
this.expandable = true,
this.still = false,
});
/// True for a mini-map: the whole graph scaled to fit the box, with no
/// pan/zoom viewport, controls, input or semantics of its own.
final bool still;
/// False when this graph is already the full-screen view: no maximise.
final bool expandable;
@@ -207,7 +212,9 @@ class _RunGraphViewState extends State<RunGraphView> {
child: Stack(
fit: StackFit.expand,
children: [
if (geometry != null)
if (geometry != null && widget.still)
_stillCanvas(nodes, geometry, state, style, statuses)
else if (geometry != null)
GraphViewport(
controller: _viewport,
contentSize: Size(geometry.$2.width, geometry.$2.height),
@@ -273,6 +280,40 @@ class _RunGraphViewState extends State<RunGraphView> {
),
);
/// The whole measured canvas scaled down (never up) to fit the box: a
/// picture with no input or semantics, for a mini-map.
Widget _stillCanvas(
List<GraphNode> nodes,
(GraphLayout, GraphRouting) geometry,
RunGraphState state,
GraphCanvasStyle style,
Map<String, String?> statuses,
) {
final routing = geometry.$2;
return ExcludeSemantics(
child: IgnorePointer(
child: FittedBox(
key: const Key('run-graph-still'),
fit: BoxFit.scaleDown,
child: SizedBox(
width: routing.width,
height: routing.height,
child: _runCanvas(
nodes: nodes,
layout: geometry.$1,
routing: routing,
state: state,
style: style,
statuses: statuses,
selectedStage: widget.selectedStage,
onStageSelected: widget.onStageSelected,
),
),
),
),
);
}
/// The same measured run canvas at any viewport size and selection, used by
/// the inline viewport and the expanded presentation.
Widget _runCanvas({