Keep graph edge labels clear of nodes and other labels

The linear layout used by the definition and run graphs placed each
outcome label at the middle of its widest run with no collision check,
and the run graph measured only the label text while rendering an order
badge in front of it, so taken labels ran into the next node.

Labels now try positions along their own route (horizontal runs above
and below, sliding along, then vertical runs) and take the first whose
box stays 4px clear of every node and earlier label, preferring spots
off other wires. If a label finds no spot, the layout widens its column
gaps and lanes and runs again; a last-resort shelf below the drawing
never overlaps. The run graph measures the exact badge+label widget it
renders, keyed by edge id.
This commit is contained in:
2026-10-31 16:36:48 +00:00
parent 4235cd858f
commit fb1935a62d
6 changed files with 794 additions and 111 deletions
@@ -76,7 +76,7 @@ class RunGraphView extends StatefulWidget {
class _RunGraphViewState extends State<RunGraphView> {
final Map<String, Size> _nodeSizes = {};
final Map<String, Size> _labelSizes = {};
final Map<int, Size> _labelSizes = {};
final Map<String, String?> _measuredStatuses = {};
final GraphViewportController _viewport = GraphViewportController();
TextScaler? _scaler;
@@ -99,7 +99,7 @@ class _RunGraphViewState extends State<RunGraphView> {
}
}
void _record(Map<String, Size> sizes, String key, Size size) {
void _record<K>(Map<K, Size> sizes, K key, Size size) {
if (sizes[key] == size) return;
sizes[key] = size;
if (_rebuildScheduled) return;
@@ -122,7 +122,7 @@ class _RunGraphViewState extends State<RunGraphView> {
}
final labelExtents = <int, LabelExtent>{};
for (final edge in edges) {
final size = _labelSizes[edge.label];
final size = _labelSizes[edge.id];
if (size == null) return null;
labelExtents[edge.id] = LabelExtent(
width: size.width,
@@ -239,6 +239,7 @@ class _RunGraphViewState extends State<RunGraphView> {
maxNodeWidth: constraints.maxWidth,
labelStyle: style.labelStyle,
recordedStatuses: statuses,
state: state,
onNodeSize: (key, size) => _record(_nodeSizes, key, size),
onLabelSize: (key, size) => _record(_labelSizes, key, size),
),