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 nodes; final GraphLayout layout; final GraphRouting routing; final GraphCanvasStyle style; final String? selectedStage; final ValueChanged onSelected; @override Widget build(BuildContext context) { final nodesByKey = { 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, ), ), ], ); } }