import 'package:flutter/material.dart'; import 'package:pipelines_app/features/graph/domain/graph_definition.dart'; import 'package:pipelines_app/features/graph/domain/graph_protocol.dart'; import 'package:pipelines_app/features/graph/layout/graph_node_layout.dart'; import 'package:pipelines_app/features/graph/layout/layout_models.dart'; import 'package:pipelines_app/features/graph/painting/graph_edge_layer.dart'; import 'package:pipelines_app/features/graph/routing/graph_edge_routing.dart'; import 'package:pipelines_app/features/graph/routing/route_models.dart'; /// Browser-capture fixture for `GraphEdgeLayer` only. /// /// It composes caller-measured cards, the landed node layout, the landed /// orthogonal router and the edge layer. It is not wired into `main.dart`; the /// app shell, a real pipeline and any server stay untouched. Query parameter /// `theme=dark` selects the dark native theme and `case=same-rank` swaps in a /// two-node cycle that exercises same-rank edges between distinct nodes. void main() => runApp(const GraphEdgeProbeApp()); const Map _definition = { 'stages': [ { 'key': 'ingest', 'edges': {'success': 'build', 'error': '#failure'}, }, { 'key': 'build', 'edges': {'success': 'verify', 'retry': 'build'}, }, { 'key': 'verify', 'edges': {'success': '#success', 'rework': 'ingest'}, }, ], }; /// A two-node cycle: both nodes share one rank and both edges are same-rank /// without being self loops. const Map _sameRankDefinition = { 'stages': [ { 'key': 'review', 'edges': {'success': 'approve'}, }, { 'key': 'approve', 'edges': {'success': 'review'}, }, ], }; class GraphEdgeProbeApp extends StatelessWidget { const GraphEdgeProbeApp({super.key}); @override Widget build(BuildContext context) { final dark = Uri.base.queryParameters['theme'] == 'dark'; return MaterialApp( title: 'Graph edge layer probe', theme: ThemeData( brightness: dark ? Brightness.dark : Brightness.light, colorScheme: ColorScheme.fromSeed( seedColor: Colors.indigo, brightness: dark ? Brightness.dark : Brightness.light, ), ), home: const _ProbePage(), ); } } class _ProbePage extends StatelessWidget { const _ProbePage(); @override Widget build(BuildContext context) { final theme = Theme.of(context); final scaler = MediaQuery.textScalerOf(context); final sameRankCase = Uri.base.queryParameters['case'] == 'same-rank'; final definition = sameRankCase ? _sameRankDefinition : _definition; final nodes = graphNodes(definition); final edges = graphEdges(definition); final layout = layoutGraphNodes( nodes: nodes, edges: edges, extents: { for (final node in nodes) node.key: _nodeExtent(theme.textTheme.bodyMedium, node.label, scaler), }, config: GraphLayoutConfig(columnGap: 120, rowGap: 24, padding: 16), ); final routing = routeGraphEdges( layout: layout, edges: edges, labelExtents: { for (final edge in edges) edge.id: _labelExtent(theme.textTheme.labelSmall, edge.label, scaler), }, config: RoutingConfig( nodeClearance: 8, laneSpacing: 28, corridorSpacing: 20, portSpacing: 12, labelGap: 4, boundsPadding: 8, ), ); final size = Size(routing.width, routing.height); return Scaffold( appBar: AppBar(title: const Text('Graph edge layer')), body: SingleChildScrollView( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( sameRankCase ? 'A two-node cycle in one rank: both arrows are same-rank ' 'and neither is a self loop.' : 'Measured cards and routed edges: same-rank cycle edges, ' 'forward edges to the terminals and a self loop, in the ' 'native outline color and stroke.', style: theme.textTheme.bodySmall, ), const SizedBox(height: 16), SingleChildScrollView( scrollDirection: Axis.horizontal, child: SizedBox.fromSize( size: size, child: Stack( clipBehavior: Clip.none, children: [ GraphEdgeLayer( routes: routing.routes, canvasSize: size, color: theme.colorScheme.outline, strokeWidth: theme.dividerTheme.thickness ?? 1, ), for (final node in layout.nodes) Positioned( left: node.x, top: node.y, width: node.width, height: node.height, child: Card( margin: EdgeInsets.zero, child: Center( child: Text( nodeDisplayLabel(node.key), style: theme.textTheme.bodyMedium, ), ), ), ), ], ), ), ), ], ), ), ); } } NodeExtent _nodeExtent(TextStyle? style, String text, TextScaler scaler) { final painter = TextPainter( text: TextSpan(text: text, style: style), textDirection: TextDirection.ltr, textScaler: scaler, )..layout(); return NodeExtent(width: painter.width + 32, height: painter.height + 20); } LabelExtent _labelExtent(TextStyle? style, String text, TextScaler scaler) { final painter = TextPainter( text: TextSpan(text: text, style: style), textDirection: TextDirection.ltr, textScaler: scaler, )..layout(); return LabelExtent(width: painter.width + 8, height: painter.height + 4); }