c1f140bc78
Pure-Dart SCC ranking and column placement over the landed graph identities. Every extent and gap is caller supplied; missing measurements are rejected rather than defaulted. Focused tests cover linear, diamond, cycle, self-loop, disconnected, terminal, expanded-text and invalid-input cases.
103 lines
3.0 KiB
Dart
103 lines
3.0 KiB
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/layout_models.dart';
|
|
|
|
import '../domain/graph_fixtures.dart' as domain;
|
|
|
|
/// Small definitions and measured extents shared by the layout tests.
|
|
|
|
GraphLayoutConfig layoutConfig({
|
|
double columnGap = 24,
|
|
double rowGap = 12,
|
|
double padding = 4,
|
|
}) {
|
|
return GraphLayoutConfig(
|
|
columnGap: columnGap,
|
|
rowGap: rowGap,
|
|
padding: padding,
|
|
);
|
|
}
|
|
|
|
/// One measured size for every node, optionally scaled to simulate text growth.
|
|
Map<String, NodeExtent> uniformExtents(
|
|
Iterable<GraphNode> nodes, {
|
|
double width = 120,
|
|
double height = 60,
|
|
double scale = 1,
|
|
}) {
|
|
return <String, NodeExtent>{
|
|
for (final node in nodes)
|
|
node.key: NodeExtent(width: width * scale, height: height * scale),
|
|
};
|
|
}
|
|
|
|
Map<String, NodeExtent> scaledExtents(
|
|
Map<String, NodeExtent> base,
|
|
double scale,
|
|
) {
|
|
return <String, NodeExtent>{
|
|
for (final entry in base.entries)
|
|
entry.key: NodeExtent(
|
|
width: entry.value.width * scale,
|
|
height: entry.value.height * scale,
|
|
),
|
|
};
|
|
}
|
|
|
|
/// Deliberately uneven measured boxes for the diamond definition.
|
|
Map<String, NodeExtent> heterogeneousExtents() {
|
|
return <String, NodeExtent>{
|
|
'a': NodeExtent(width: 210, height: 84),
|
|
'b': NodeExtent(width: 92, height: 44),
|
|
'c': NodeExtent(width: 148, height: 126),
|
|
'd': NodeExtent(width: 104, height: 58),
|
|
failureEnd: NodeExtent(width: 72, height: 34),
|
|
successEnd: NodeExtent(width: 228, height: 96),
|
|
};
|
|
}
|
|
|
|
/// Two stages in a cycle; both terminals are reached from inside the cycle.
|
|
Map<String, dynamic> cycleGraph() => <String, dynamic>{
|
|
'stages': <dynamic>[
|
|
domain.stage(
|
|
'a',
|
|
edges: <String, String?>{'success': 'b', 'error': '#'},
|
|
fallbackError: true,
|
|
),
|
|
domain.stage(
|
|
'b',
|
|
edges: <String, String?>{'success': 'a', 'error': '#success'},
|
|
),
|
|
],
|
|
};
|
|
|
|
/// Two independent routes and a stage with no edges at all.
|
|
Map<String, dynamic> disconnectedGraph() => <String, dynamic>{
|
|
'stages': <dynamic>[
|
|
domain.stage('a', edges: <String, String?>{'success': '#success'}),
|
|
domain.stage('b', edges: <String, String?>{'success': '#failure'}),
|
|
domain.stage('c'),
|
|
],
|
|
};
|
|
|
|
Map<String, dynamic> linearGraphFixture() => domain.linearGraph();
|
|
|
|
Map<String, dynamic> diamondGraphFixture() => domain.diamondGraph();
|
|
|
|
Map<String, dynamic> selfLoopGraphFixture() => domain.selfLoopGraph();
|
|
|
|
Map<String, dynamic> incompleteGraphFixture() => domain.incompleteGraph();
|
|
|
|
/// A long chain, used to prove the iterative rank walk cannot overflow.
|
|
Map<String, dynamic> chainGraph(int length) => <String, dynamic>{
|
|
'stages': <dynamic>[
|
|
for (var index = 0; index < length; index += 1)
|
|
domain.stage(
|
|
's$index',
|
|
edges: <String, String?>{
|
|
'success': index + 1 < length ? 's${index + 1}' : '#success',
|
|
},
|
|
),
|
|
],
|
|
};
|