feat(app): graph pan, zoom and expanded view

This commit is contained in:
2026-10-22 02:05:20 +01:00
parent d5f24b8259
commit cc7eba59b6
19 changed files with 2622 additions and 200 deletions
@@ -0,0 +1,76 @@
import 'package:flutter/widgets.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_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 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,
),
),
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: Text(
routing.routeFor(label.edgeId)!.label,
style: style.labelStyle,
),
),
],
);
}
}
@@ -5,23 +5,29 @@ import '../../../core/api_gateway.dart';
import '../domain/graph_definition.dart';
import '../layout/graph_node_layout.dart';
import '../layout/layout_models.dart';
import '../painting/graph_edge_layer.dart';
import '../routing/graph_edge_routing.dart';
import '../routing/route_models.dart';
import '../viewport/graph_expanded_view.dart';
import '../viewport/graph_viewport.dart';
import '../viewport/graph_viewport_controller.dart';
import 'definition_graph_canvas.dart';
import 'graph_canvas_style.dart';
import 'graph_stage_node.dart';
import 'graph_measurements.dart';
/// The definition's own empty-state wording (web `PIPELINE_GRAPH_EMPTY`).
const String definitionGraphEmpty = 'This pipeline has no stages.';
/// The expanded definition presentation's title.
const String definitionGraphExpandedTitle = 'Pipeline graph';
/// One pipeline definition as a readable native graph: measured stage nodes,
/// routed passive edges behind them and native outcome labels on their boxes.
///
/// [selectedStage] is a node key (including `#success`/`#failure`) and
/// [onSelected] reports the exact key activated. Nothing reads run evidence:
/// nodes show no status and terminals stay plain, so no visit is implied. The
/// view fills bounded caller constraints with a stock [InteractiveViewer].
/// view fills bounded caller constraints with a pan/zoom [GraphViewport] and can
/// present the same canvas full screen without losing the selection.
class DefinitionGraphView extends StatefulWidget {
const DefinitionGraphView({
super.key,
@@ -41,9 +47,16 @@ class DefinitionGraphView extends StatefulWidget {
class _DefinitionGraphViewState extends State<DefinitionGraphView> {
final Map<String, Size> _nodeSizes = {};
final Map<String, Size> _labelSizes = {};
final GraphViewportController _viewport = GraphViewportController();
TextScaler? _scaler;
bool _rebuildScheduled = false;
@override
void dispose() {
_viewport.dispose();
super.dispose();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
@@ -159,56 +172,22 @@ class _DefinitionGraphViewState extends State<DefinitionGraphView> {
GraphRouting routing,
GraphCanvasStyle style,
) {
final nodesByKey = <String, GraphNode>{
for (final node in nodes) node.key: node,
};
final size = Size(routing.width, routing.height);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: InteractiveViewer(
constrained: false,
minScale: 0.3,
maxScale: 3,
child: SizedBox.fromSize(
size: size,
child: 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,
),
),
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 == widget.selectedStage,
onSelected: widget.onSelected,
),
),
for (final label in routing.labels)
Positioned(
left: label.x,
top: label.y,
child: Text(
routing.routeFor(label.edgeId)!.label,
style: style.labelStyle,
),
),
],
),
child: GraphViewport(
controller: _viewport,
contentSize: size,
onExpand: () => _openExpanded(nodes, layout, routing, size),
child: DefinitionGraphCanvas(
nodes: nodes,
layout: layout,
routing: routing,
style: style,
selectedStage: widget.selectedStage,
onSelected: widget.onSelected,
),
),
),
@@ -228,4 +207,28 @@ class _DefinitionGraphViewState extends State<DefinitionGraphView> {
],
);
}
/// Opens the same measured canvas full screen, keeping the selection.
void _openExpanded(
List<GraphNode> nodes,
GraphLayout layout,
GraphRouting routing,
Size size,
) {
openGraphExpanded(
context,
contentSize: size,
title: definitionGraphExpandedTitle,
selectedStage: widget.selectedStage,
onSelected: widget.onSelected,
canvasBuilder: (context, selected, onSelected) => DefinitionGraphCanvas(
nodes: nodes,
layout: layout,
routing: routing,
style: GraphCanvasStyle.of(context),
selectedStage: selected,
onSelected: onSelected,
),
);
}
}
@@ -159,7 +159,8 @@ class RunGraphEdgePainter extends CustomPainter {
/// outcome labels only for routes the run actually took.
///
/// [layout] and [routing] are the caller's measured geometry. The canvas never
/// changes them and never assumes a node size.
/// changes them and never assumes a node size; the caller supplies the pan/zoom
/// viewport around this content.
class RunGraphCanvas extends StatelessWidget {
const RunGraphCanvas({
super.key,
@@ -202,55 +203,47 @@ class RunGraphCanvas extends StatelessWidget {
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return InteractiveViewer(
constrained: false,
minScale: 0.3,
maxScale: 3,
child: SizedBox.fromSize(
size: size,
child: Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
child: RunGraphEdgeLayer(
executedRoutes: executed,
untakenRoutes: untaken,
canvasSize: size,
executedColor: executedColor,
untakenColor: style.edgeColor,
strokeWidth: style.edgeWidth,
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,
opensVisit:
!nodesByKey[box.key]!.terminal &&
state.isStageVisited(box.key),
onSelected: onStageSelected,
),
),
// 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: Text(
routing.routeFor(label.edgeId)!.label,
style: style.labelStyle,
),
),
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,
opensVisit:
!nodesByKey[box.key]!.terminal &&
state.isStageVisited(box.key),
onSelected: onStageSelected,
),
),
// 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: Text(
routing.routeFor(label.edgeId)!.label,
style: style.labelStyle,
),
),
],
),
),
],
);
}
}
@@ -0,0 +1,117 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/run_graph_state.dart';
import 'graph_canvas_style.dart';
/// The run legend's route-class words (web graph legend).
const String runGraphExecuted = 'Executed';
const String runGraphNotExecuted = 'Not executed';
/// The run canvas' fixed header: the route legend, plus the elapsed line while
/// the run is still executing.
///
/// It is shared by the inline view and the full-screen presentation so the
/// expanded canvas explains its solid and dashed routes the way the web keeps
/// its legend inside the graph panel.
class RunGraphHeader extends StatelessWidget {
const RunGraphHeader({
super.key,
required this.state,
required this.style,
this.now,
});
final RunGraphState state;
final GraphCanvasStyle style;
/// Injectable clock for deterministic elapsed labels; defaults to now.
final DateTime Function()? now;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final mutedColor = style.edgeColor;
final active = state.activeStage;
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 0),
child: Wrap(
spacing: 16,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Semantics(
container: true,
label: 'Route kinds',
child: Wrap(
spacing: 12,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
_LegendEntry(
icon: cupertino
? CupertinoIcons.arrow_right
: Icons.arrow_forward,
label: runGraphExecuted,
color: executedColor,
),
_LegendEntry(
icon: cupertino ? CupertinoIcons.minus : Icons.remove,
label: runGraphNotExecuted,
color: mutedColor,
),
],
),
),
if (active != null)
_elapsed(context, active, state.currentStageStartedAt),
],
),
);
}
Widget _elapsed(BuildContext context, String active, String? startedAt) {
final started = startedAt == null ? null : DateTime.tryParse(startedAt);
final duration = started == null
? null
: _formatElapsed((now ?? DateTime.now)().difference(started));
final text = duration == null
? 'Current stage $active'
: 'Current stage $active · elapsed $duration';
return Text(text, style: GraphCanvasStyle.of(context).labelStyle);
}
}
class _LegendEntry extends StatelessWidget {
const _LegendEntry({
required this.icon,
required this.label,
required this.color,
});
final IconData icon;
final String label;
final Color color;
@override
Widget build(BuildContext context) => Wrap(
spacing: 4,
runSpacing: 2,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
ExcludeSemantics(child: Icon(icon, color: color)),
Text(label),
],
);
}
String _formatElapsed(Duration duration) {
final seconds = duration.inSeconds < 0 ? 0 : duration.inSeconds;
if (seconds < 60) return '${seconds}s';
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
}
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_definition.dart';
import '../domain/run_graph_state.dart';
import '../domain/stage_visits.dart';
@@ -10,15 +8,20 @@ import '../layout/graph_node_layout.dart';
import '../layout/layout_models.dart';
import '../routing/graph_edge_routing.dart';
import '../routing/route_models.dart';
import '../viewport/graph_expanded_view.dart';
import '../viewport/graph_viewport.dart';
import '../viewport/graph_viewport_controller.dart';
import 'graph_canvas_style.dart';
import 'run_graph_canvas.dart';
import 'run_graph_header.dart';
export 'run_graph_header.dart' show runGraphExecuted, runGraphNotExecuted;
/// The run tab's exact missing-graph wording (web `RUN_GRAPH_MISSING`).
const String runGraphMissing = 'This server did not include the run graph.';
/// The run legend's route-class words (web graph legend).
const String runGraphExecuted = 'Executed';
const String runGraphNotExecuted = 'Not executed';
/// The expanded run presentation's title.
const String runGraphExpandedTitle = 'Run graph';
/// One run's definition drawn as evidence: visited stages carry their recorded
/// status, only taken routes are solid and arrowed, and every other route stays
@@ -32,9 +35,10 @@ const String runGraphNotExecuted = 'Not executed';
/// shown with the outcome that resolved there but have no recorded visit to
/// open, so they stay non-interactive.
///
/// The view fills its bounded constraints with a stock [InteractiveViewer] for
/// pan and zoom; the elapsed line appears only while the run is executing and
/// is static (no invented progress or timer).
/// The view fills its bounded constraints with a pan/zoom [GraphViewport]; the
/// elapsed line appears only while the run is executing and is static (no
/// invented progress or timer). The same canvas can be opened full screen with
/// its selection preserved and the route legend still explaining its marks.
class RunGraphView extends StatefulWidget {
const RunGraphView({
super.key,
@@ -67,9 +71,16 @@ class _RunGraphViewState extends State<RunGraphView> {
final Map<String, Size> _nodeSizes = {};
final Map<String, Size> _labelSizes = {};
final Map<String, String?> _measuredStatuses = {};
final GraphViewportController _viewport = GraphViewportController();
TextScaler? _scaler;
bool _rebuildScheduled = false;
@override
void dispose() {
_viewport.dispose();
super.dispose();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
@@ -188,21 +199,32 @@ class _RunGraphViewState extends State<RunGraphView> {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_header(state, style),
RunGraphHeader(state: state, style: style, now: widget.now),
Expanded(
child: Stack(
fit: StackFit.expand,
children: [
if (geometry != null)
RunGraphCanvas(
nodes: nodes,
layout: geometry.$1,
routing: geometry.$2,
state: state,
style: style,
recordedStatuses: statuses,
selectedStage: widget.selectedStage,
onStageSelected: widget.onStageSelected,
GraphViewport(
controller: _viewport,
contentSize: Size(geometry.$2.width, geometry.$2.height),
onExpand: () => _openExpanded(
nodes,
geometry.$1,
geometry.$2,
state,
statuses,
),
child: _runCanvas(
nodes: nodes,
layout: geometry.$1,
routing: geometry.$2,
state: state,
style: style,
statuses: statuses,
selectedStage: widget.selectedStage,
onStageSelected: widget.onStageSelected,
),
)
else
const SizedBox.shrink(),
@@ -245,87 +267,58 @@ class _RunGraphViewState extends State<RunGraphView> {
),
);
Widget _header(RunGraphState state, GraphCanvasStyle style) {
final cupertino = usesCupertinoHost(context);
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final mutedColor = style.edgeColor;
final active = state.activeStage;
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 0),
child: Wrap(
spacing: 16,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Semantics(
container: true,
label: 'Route kinds',
child: Wrap(
spacing: 12,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
_LegendEntry(
icon: cupertino
? CupertinoIcons.arrow_right
: Icons.arrow_forward,
label: runGraphExecuted,
color: executedColor,
),
_LegendEntry(
icon: cupertino ? CupertinoIcons.minus : Icons.remove,
label: runGraphNotExecuted,
color: mutedColor,
),
],
),
),
if (active != null) _elapsed(active, state.currentStageStartedAt),
],
/// The same measured run canvas at any viewport size and selection, used by
/// the inline viewport and the expanded presentation.
Widget _runCanvas({
required List<GraphNode> nodes,
required GraphLayout layout,
required GraphRouting routing,
required RunGraphState state,
required GraphCanvasStyle style,
required Map<String, String?> statuses,
required String? selectedStage,
required ValueChanged<String> onStageSelected,
}) => RunGraphCanvas(
nodes: nodes,
layout: layout,
routing: routing,
state: state,
style: style,
recordedStatuses: statuses,
selectedStage: selectedStage,
onStageSelected: onStageSelected,
);
void _openExpanded(
List<GraphNode> nodes,
GraphLayout layout,
GraphRouting routing,
RunGraphState state,
Map<String, String?> statuses,
) {
openGraphExpanded(
context,
contentSize: Size(routing.width, routing.height),
title: runGraphExpandedTitle,
selectedStage: widget.selectedStage,
onSelected: widget.onStageSelected,
// The full-screen canvas draws solid and dashed routes; the legend that
// explains them must travel with it, as it does on the web.
header: RunGraphHeader(
state: state,
style: GraphCanvasStyle.of(context),
now: widget.now,
),
canvasBuilder: (context, selected, onSelected) => _runCanvas(
nodes: nodes,
layout: layout,
routing: routing,
state: state,
style: GraphCanvasStyle.of(context),
statuses: statuses,
selectedStage: selected,
onStageSelected: onSelected,
),
);
}
Widget _elapsed(String active, String? startedAt) {
final started = startedAt == null ? null : DateTime.tryParse(startedAt);
final duration = started == null
? null
: _formatElapsed((widget.now ?? DateTime.now)().difference(started));
final text = duration == null
? 'Current stage $active'
: 'Current stage $active · elapsed $duration';
return Text(text, style: GraphCanvasStyle.of(context).labelStyle);
}
}
class _LegendEntry extends StatelessWidget {
const _LegendEntry({
required this.icon,
required this.label,
required this.color,
});
final IconData icon;
final String label;
final Color color;
@override
Widget build(BuildContext context) => Wrap(
spacing: 4,
runSpacing: 2,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
ExcludeSemantics(child: Icon(icon, color: color)),
Text(label),
],
);
}
String _formatElapsed(Duration duration) {
final seconds = duration.inSeconds < 0 ? 0 : duration.inSeconds;
if (seconds < 60) return '${seconds}s';
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
}