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
@@ -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,
),
);
}
}