feat(app): add passive routed graph edge layer
Paint the landed orthogonal EdgeRoutes on a caller-sized canvas: one polyline per route, a filled arrow at the target port in the route's real arrival direction, clipping, and value-based repaint. The layer is pointer transparent so node widgets below it keep their gestures. Includes focused geometry, painter and hit-test regressions, an isolated web probe with rendered evidence, and a note recording the slice and its limits.
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
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<String, dynamic> _definition = <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'ingest',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#failure'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'edges': <String, String?>{'success': 'verify', 'retry': 'build'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'verify',
|
||||
'edges': <String, String?>{'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<String, dynamic> _sameRankDefinition = <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'review',
|
||||
'edges': <String, String?>{'success': 'approve'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'approve',
|
||||
'edges': <String, String?>{'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: <String, NodeExtent>{
|
||||
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: <int, LabelExtent>{
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user