7872e57d40
The show_run card carries the run's graph and per-stage progress (bounded by the graph, not the run length) and draws a still mini-map with the run graph plus a stage strip with status, visits and time. Hovering or tapping an edge in the pipeline and run graphs highlights it, its label and endpoints, with a tooltip naming from -> to, the outcome and, for runs, how often it was taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.1 KiB
Dart
69 lines
2.1 KiB
Dart
import 'dart:math' as math;
|
|
import 'dart:ui' show Offset, Rect;
|
|
|
|
import '../layout/layout_models.dart';
|
|
import '../routing/route_models.dart';
|
|
|
|
/// Which routed edge a pointer at [point] (graph space) is on, or null.
|
|
///
|
|
/// A point inside a node box belongs to the node, never to an edge. A point on
|
|
/// an edge's label box is that edge. Otherwise the nearest route polyline
|
|
/// within [tolerance] wins, so overlapping corridors pick the closest lane and
|
|
/// self loops and back edges are hit along every bend they take.
|
|
int? hitTestEdge({
|
|
required List<EdgeRoute> routes,
|
|
required List<EdgeLabelBox> labels,
|
|
required List<GraphNodeBox> nodes,
|
|
required Offset point,
|
|
required double tolerance,
|
|
}) {
|
|
for (final node in nodes) {
|
|
if (Rect.fromLTWH(
|
|
node.x,
|
|
node.y,
|
|
node.width,
|
|
node.height,
|
|
).contains(point)) {
|
|
return null;
|
|
}
|
|
}
|
|
for (final label in labels) {
|
|
final box = Rect.fromLTWH(label.x, label.y, label.width, label.height);
|
|
if (box.inflate(2).contains(point)) return label.edgeId;
|
|
}
|
|
int? best;
|
|
var bestDistance = tolerance;
|
|
for (final route in routes) {
|
|
final distance = distanceToRoute(route, point);
|
|
if (distance <= bestDistance) {
|
|
best = route.id;
|
|
bestDistance = distance;
|
|
}
|
|
}
|
|
return best;
|
|
}
|
|
|
|
/// The shortest distance from [point] to [route]'s polyline.
|
|
double distanceToRoute(EdgeRoute route, Offset point) {
|
|
final points = route.points;
|
|
if (points.isEmpty) return double.infinity;
|
|
var best = double.infinity;
|
|
for (var index = 0; index < points.length; index += 1) {
|
|
final a = Offset(points[index].x, points[index].y);
|
|
final b = index + 1 < points.length
|
|
? Offset(points[index + 1].x, points[index + 1].y)
|
|
: a;
|
|
best = math.min(best, _distanceToSegment(point, a, b));
|
|
}
|
|
return best;
|
|
}
|
|
|
|
double _distanceToSegment(Offset p, Offset a, Offset b) {
|
|
final ab = b - a;
|
|
final lengthSquared = ab.distanceSquared;
|
|
if (lengthSquared == 0) return (p - a).distance;
|
|
final t = (((p.dx - a.dx) * ab.dx + (p.dy - a.dy) * ab.dy) / lengthSquared)
|
|
.clamp(0.0, 1.0);
|
|
return (p - (a + ab * t)).distance;
|
|
}
|