feat(app): graph pan, zoom and expanded view
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import 'graph_viewport.dart';
|
||||
import 'graph_viewport_controller.dart';
|
||||
|
||||
/// The expanded presentation's close wording (`Close`).
|
||||
const String graphExpandedClose = 'Close';
|
||||
|
||||
/// Builds the same canvas for another viewport, with the selection that
|
||||
/// presentation is showing.
|
||||
typedef GraphExpandedCanvasBuilder =
|
||||
Widget Function(
|
||||
BuildContext context,
|
||||
String? selectedStage,
|
||||
ValueChanged<String> onSelected,
|
||||
);
|
||||
|
||||
/// A native full-screen presentation of one graph canvas.
|
||||
///
|
||||
/// It fits the graph into the larger box (as the web does when its panel
|
||||
/// expands), keeps the selected node selected, and lets a tap in the larger
|
||||
/// canvas update that selection through [onSelected]. Closing pops the route;
|
||||
/// the inline canvas was never changed, so it returns to its previous state.
|
||||
class GraphExpandedView extends StatefulWidget {
|
||||
const GraphExpandedView({
|
||||
super.key,
|
||||
required this.contentSize,
|
||||
required this.canvasBuilder,
|
||||
required this.title,
|
||||
required this.onSelected,
|
||||
this.selectedStage,
|
||||
this.header,
|
||||
});
|
||||
|
||||
/// The measured graph extent, as in the inline canvas.
|
||||
final Size contentSize;
|
||||
|
||||
final GraphExpandedCanvasBuilder canvasBuilder;
|
||||
|
||||
/// The presentation's native title, e.g. `Run graph`.
|
||||
final String title;
|
||||
|
||||
/// Reports a node activated in the expanded canvas.
|
||||
final ValueChanged<String> onSelected;
|
||||
|
||||
/// Optional fixed content above the canvas, e.g. a legend that explains the
|
||||
/// graph's marks. It stays outside the pan/zoom transform.
|
||||
final Widget? header;
|
||||
|
||||
final String? selectedStage;
|
||||
|
||||
@override
|
||||
State<GraphExpandedView> createState() => _GraphExpandedViewState();
|
||||
}
|
||||
|
||||
class _GraphExpandedViewState extends State<GraphExpandedView> {
|
||||
final GraphViewportController _controller = GraphViewportController();
|
||||
late String? _selected = widget.selectedStage;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(GraphExpandedView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.selectedStage != oldWidget.selectedStage) {
|
||||
_selected = widget.selectedStage;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _select(String key) {
|
||||
setState(() => _selected = key);
|
||||
widget.onSelected(key);
|
||||
}
|
||||
|
||||
void _close() => Navigator.of(context).maybePop();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewport = GraphViewport(
|
||||
key: const Key('graph-expanded-viewport'),
|
||||
controller: _controller,
|
||||
contentSize: widget.contentSize,
|
||||
// The larger box fits the whole graph, as the web does when its panel
|
||||
// expands; a later resize re-fits until the reader pans or zooms, then
|
||||
// only clamps.
|
||||
child: widget.canvasBuilder(context, _selected, _select),
|
||||
);
|
||||
final body = widget.header == null
|
||||
? viewport
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
widget.header!,
|
||||
Expanded(child: viewport),
|
||||
],
|
||||
);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(widget.title),
|
||||
trailing: CupertinoButton(
|
||||
key: const Key('graph-expanded-close'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _close,
|
||||
child: const Text(graphExpandedClose),
|
||||
),
|
||||
),
|
||||
child: SafeArea(child: body),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('graph-expanded-close'),
|
||||
onPressed: _close,
|
||||
child: const Text(graphExpandedClose),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(child: body),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Pushes [GraphExpandedView] with the host's native full-screen transition.
|
||||
///
|
||||
/// This is the seam a Graph tab or run detail can call: pass the measured
|
||||
/// content size and a builder that draws the same canvas for the supplied
|
||||
/// selection. The expanded canvas fits that size; the inline canvas is
|
||||
/// untouched.
|
||||
Future<void> openGraphExpanded(
|
||||
BuildContext context, {
|
||||
required Size contentSize,
|
||||
required GraphExpandedCanvasBuilder canvasBuilder,
|
||||
required String title,
|
||||
required ValueChanged<String> onSelected,
|
||||
String? selectedStage,
|
||||
Widget? header,
|
||||
}) {
|
||||
final page = GraphExpandedView(
|
||||
contentSize: contentSize,
|
||||
canvasBuilder: canvasBuilder,
|
||||
title: title,
|
||||
onSelected: onSelected,
|
||||
selectedStage: selectedStage,
|
||||
header: header,
|
||||
);
|
||||
final route = usesCupertinoHost(context)
|
||||
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: (_) => page)
|
||||
: MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page);
|
||||
return Navigator.of(context).push(route);
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import 'graph_viewport_controller.dart';
|
||||
|
||||
/// The fit control's web wording (`Fit graph to view`).
|
||||
const String graphFitLabel = 'Fit graph to view';
|
||||
|
||||
/// The expand control's web wording (`Expand graph`).
|
||||
const String graphExpandLabel = 'Expand graph';
|
||||
|
||||
/// A bounded graph canvas with the host's own pan, pinch, wheel and trackpad
|
||||
/// zoom, plus a fit control and an optional expanded presentation.
|
||||
///
|
||||
/// [controller] owns the transform, so a caller can read or restore a
|
||||
/// [GraphViewportSnapshot]. Gestures are consumed only inside this widget's
|
||||
/// box: an ancestor scroll view keeps scrolling everywhere else, and a tap
|
||||
/// that does not move still reaches the native node under the pointer.
|
||||
class GraphViewport extends StatefulWidget {
|
||||
const GraphViewport({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.contentSize,
|
||||
required this.child,
|
||||
this.onExpand,
|
||||
});
|
||||
|
||||
final GraphViewportController controller;
|
||||
|
||||
/// The measured graph extent; the canvas never invents a fixed size.
|
||||
final Size contentSize;
|
||||
|
||||
/// The measured, already-routed graph content.
|
||||
final Widget child;
|
||||
|
||||
/// Opens the expanded presentation. Null hides the expand control.
|
||||
final VoidCallback? onExpand;
|
||||
|
||||
@override
|
||||
State<GraphViewport> createState() => _GraphViewportState();
|
||||
}
|
||||
|
||||
class _GraphViewportState extends State<GraphViewport> {
|
||||
Size? _scheduledViewport;
|
||||
Size? _scheduledContent;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(GraphViewport oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.controller != widget.controller) {
|
||||
_scheduledViewport = null;
|
||||
_scheduledContent = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Attaches the current extents after layout, never during build.
|
||||
void _scheduleAttach(Size viewport) {
|
||||
if (viewport == _scheduledViewport &&
|
||||
widget.contentSize == _scheduledContent) {
|
||||
return;
|
||||
}
|
||||
_scheduledViewport = viewport;
|
||||
_scheduledContent = widget.contentSize;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
widget.controller.attach(viewport: viewport, content: widget.contentSize);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final viewport =
|
||||
constraints.hasBoundedWidth && constraints.hasBoundedHeight
|
||||
? constraints.biggest
|
||||
: widget.contentSize;
|
||||
if (!widget.controller.isAttached) {
|
||||
// The very first layout has no `InteractiveViewer` listening yet, so
|
||||
// fitting here applies before the first paint instead of flashing an
|
||||
// identity transform for one frame.
|
||||
widget.controller.attach(
|
||||
viewport: viewport,
|
||||
content: widget.contentSize,
|
||||
);
|
||||
_scheduledViewport = viewport;
|
||||
_scheduledContent = widget.contentSize;
|
||||
} else {
|
||||
_scheduleAttach(viewport);
|
||||
}
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: InteractiveViewer(
|
||||
key: const Key('graph-viewport'),
|
||||
transformationController: widget.controller.transformation,
|
||||
constrained: false,
|
||||
// The graph owns its own bounds (fit and the visible-pan clamp),
|
||||
// so the viewer must not impose a second, cover-the-viewport
|
||||
// boundary that would fight the fit scale.
|
||||
boundaryMargin: const EdgeInsets.all(double.infinity),
|
||||
minScale: widget.controller.minScale,
|
||||
maxScale: widget.controller.maxScale,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: SizedBox.fromSize(
|
||||
size: widget.contentSize,
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
),
|
||||
PositionedDirectional(
|
||||
top: 8,
|
||||
end: 8,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
_ViewportButton(
|
||||
buttonKey: const Key('graph-fit'),
|
||||
icon: _fitIcon(context),
|
||||
label: graphFitLabel,
|
||||
onPressed: widget.controller.fitToViewport,
|
||||
),
|
||||
if (widget.onExpand != null)
|
||||
_ViewportButton(
|
||||
buttonKey: const Key('graph-expand'),
|
||||
icon: _expandIcon(context),
|
||||
label: graphExpandLabel,
|
||||
onPressed: widget.onExpand,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
IconData _fitIcon(BuildContext context) =>
|
||||
usesCupertinoHost(context) ? CupertinoIcons.resize : Icons.fit_screen;
|
||||
|
||||
IconData _expandIcon(BuildContext context) =>
|
||||
usesCupertinoHost(context) ? CupertinoIcons.fullscreen : Icons.fullscreen;
|
||||
}
|
||||
|
||||
/// One native graph control: a tinted icon button on either host.
|
||||
///
|
||||
/// The label and the button's own tap action must reach the same semantics
|
||||
/// node: the icon is the only excluded child, and [MergeSemantics] folds the
|
||||
/// host button's action into the labelled node, so a screen reader can activate
|
||||
/// Fit and Expand on either host. A hand-written `Semantics` sibling around an
|
||||
/// excluded button would announce the control with no action at all.
|
||||
class _ViewportButton extends StatelessWidget {
|
||||
const _ViewportButton({
|
||||
required this.buttonKey,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final Key buttonKey;
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MergeSemantics(
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
child: usesCupertinoHost(context)
|
||||
? CupertinoButton.tinted(
|
||||
key: buttonKey,
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: onPressed,
|
||||
child: ExcludeSemantics(child: Icon(icon)),
|
||||
)
|
||||
: Tooltip(
|
||||
message: label,
|
||||
// The merged node already carries the label; the tooltip is
|
||||
// only the pointer affordance.
|
||||
excludeFromSemantics: true,
|
||||
child: IconButton.filledTonal(
|
||||
key: buttonKey,
|
||||
onPressed: onPressed,
|
||||
icon: ExcludeSemantics(child: Icon(icon)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'graph_viewport_math.dart';
|
||||
|
||||
/// One graph viewport's scale and offset, independent of any viewport size.
|
||||
///
|
||||
/// A snapshot is what the expanded presentation carries over: the same scale
|
||||
/// and offset the inline canvas is showing, so opening and closing it never
|
||||
/// loses the reader's place.
|
||||
@immutable
|
||||
class GraphViewportSnapshot {
|
||||
const GraphViewportSnapshot({required this.scale, required this.offset});
|
||||
|
||||
final double scale;
|
||||
final Offset offset;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is GraphViewportSnapshot &&
|
||||
other.scale == scale &&
|
||||
other.offset == offset;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(scale, offset);
|
||||
|
||||
@override
|
||||
String toString() => 'GraphViewportSnapshot(scale: $scale, offset: $offset)';
|
||||
}
|
||||
|
||||
/// Owns one graph canvas's transform.
|
||||
///
|
||||
/// Pan and pinch stay the host's own gestures ([InteractiveViewer] drives the
|
||||
/// [transformation]); this controller only supplies the graph's bounds: a fit
|
||||
/// with padding, the min/max scale and a pan clamp that keeps part of the graph
|
||||
/// visible. It never changes a node, route or label. A snapshot lets a caller
|
||||
/// read or restore a place; the expanded presentation owns its own controller,
|
||||
/// so closing it leaves this transform exactly as it was.
|
||||
class GraphViewportController extends ChangeNotifier {
|
||||
GraphViewportController({
|
||||
this.minScale = graphMinScale,
|
||||
this.maxScale = graphMaxScale,
|
||||
this.fitPadding = graphFitPadding,
|
||||
this.minVisible = graphMinVisible,
|
||||
}) : assert(minScale > 0),
|
||||
assert(maxScale >= minScale),
|
||||
_transformation = TransformationController() {
|
||||
_transformation.addListener(_handleTransform);
|
||||
}
|
||||
|
||||
/// The native pan/zoom transform handed to [InteractiveViewer].
|
||||
final TransformationController _transformation;
|
||||
|
||||
TransformationController get transformation => _transformation;
|
||||
|
||||
final double minScale;
|
||||
final double maxScale;
|
||||
final double fitPadding;
|
||||
final double minVisible;
|
||||
|
||||
Size? _viewport;
|
||||
Size? _content;
|
||||
bool _userAdjusted = false;
|
||||
bool _applying = false;
|
||||
|
||||
/// The current uniform scale (`getMaxScaleOnAxis` of the transform).
|
||||
double get scale => _transformation.value.getMaxScaleOnAxis();
|
||||
|
||||
/// The current graph-space translation of the transform.
|
||||
Offset get offset {
|
||||
final translation = _transformation.value.getTranslation();
|
||||
return Offset(translation.x, translation.y);
|
||||
}
|
||||
|
||||
GraphViewportSnapshot get snapshot =>
|
||||
GraphViewportSnapshot(scale: scale, offset: offset);
|
||||
|
||||
/// Whether this controller has seen a viewport and content extent yet.
|
||||
bool get isAttached => _viewport != null && _content != null;
|
||||
|
||||
/// Records the current viewport and content extents.
|
||||
///
|
||||
/// The first attach (and any later resize before the reader interacts) fits
|
||||
/// the graph with [fitPadding]. Once the reader has panned or zoomed, a
|
||||
/// resize keeps their place and only re-clamps it.
|
||||
void attach({required Size viewport, required Size content}) {
|
||||
if (viewport == _viewport && content == _content) return;
|
||||
_viewport = viewport;
|
||||
_content = content;
|
||||
if (!_userAdjusted) {
|
||||
fitToViewport();
|
||||
} else {
|
||||
_clamp();
|
||||
}
|
||||
}
|
||||
|
||||
/// Fits the whole graph in the current viewport and clears the user-adjusted
|
||||
/// flag, so a later resize fits again.
|
||||
void fitToViewport() {
|
||||
final viewport = _viewport;
|
||||
final content = _content;
|
||||
if (viewport == null || content == null) return;
|
||||
final scale = graphFitScale(
|
||||
viewport,
|
||||
content,
|
||||
padding: fitPadding,
|
||||
minScale: minScale,
|
||||
maxScale: maxScale,
|
||||
);
|
||||
final scaled = Size(content.width * scale, content.height * scale);
|
||||
_apply(
|
||||
graphClampOffset(
|
||||
graphCenteredOffset(scaled, viewport),
|
||||
scaled,
|
||||
viewport,
|
||||
minVisible: minVisible,
|
||||
),
|
||||
scale,
|
||||
);
|
||||
_userAdjusted = false;
|
||||
}
|
||||
|
||||
/// Applies an explicit snapshot, e.g. when a caller restores a viewport.
|
||||
void applySnapshot(GraphViewportSnapshot snapshot) {
|
||||
_userAdjusted = true;
|
||||
_apply(snapshot.offset, snapshot.scale.clamp(minScale, maxScale));
|
||||
}
|
||||
|
||||
void _apply(Offset offset, double scale) {
|
||||
_applying = true;
|
||||
_transformation.value = graphViewportMatrix(offset, scale);
|
||||
_applying = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Keeps every externally driven transform (a gesture, a wheel or a trackpad
|
||||
/// pinch) inside the graph's scale and pan bounds.
|
||||
void _handleTransform() {
|
||||
if (_applying) return;
|
||||
_userAdjusted = true;
|
||||
_clamp();
|
||||
}
|
||||
|
||||
void _clamp() {
|
||||
final viewport = _viewport;
|
||||
final content = _content;
|
||||
if (viewport == null || content == null) return;
|
||||
final currentScale = scale;
|
||||
final boundedScale = currentScale.clamp(minScale, maxScale);
|
||||
final scaled = Size(
|
||||
content.width * boundedScale,
|
||||
content.height * boundedScale,
|
||||
);
|
||||
final currentOffset = offset;
|
||||
final boundedOffset = graphClampOffset(
|
||||
currentOffset,
|
||||
scaled,
|
||||
viewport,
|
||||
minVisible: minVisible,
|
||||
);
|
||||
if (boundedScale != currentScale || boundedOffset != currentOffset) {
|
||||
_apply(boundedOffset, boundedScale);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_transformation.removeListener(_handleTransform);
|
||||
_transformation.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart' show Matrix4, Offset, Size;
|
||||
|
||||
/// The smallest scale a graph viewport may reach (`MIN_SCALE`).
|
||||
const double graphMinScale = 0.3;
|
||||
|
||||
/// The largest scale a graph viewport may reach (`MAX_SCALE`).
|
||||
const double graphMaxScale = 3;
|
||||
|
||||
/// Padding kept around a fitted graph, in graph-space pixels
|
||||
/// (`GRAPH_FIT_PADDING`).
|
||||
const double graphFitPadding = 24;
|
||||
|
||||
/// The least amount of the scaled graph kept inside the viewport on each axis,
|
||||
/// so a pan can never leave an empty canvas (`GRAPH_MIN_VISIBLE`).
|
||||
const double graphMinVisible = 40;
|
||||
|
||||
/// The transform that draws graph space at `offset + point * scale`.
|
||||
Matrix4 graphViewportMatrix(Offset offset, double scale) => Matrix4.identity()
|
||||
..translateByDouble(offset.dx, offset.dy, 0, 1)
|
||||
..scaleByDouble(scale, scale, scale, 1);
|
||||
|
||||
/// Uniform scale that fits [content] inside [viewport] with [padding] on every
|
||||
/// side, never upscaling above 1:1 and never leaving the scale bounds.
|
||||
///
|
||||
/// Degenerate or non-finite sizes return 1 rather than dividing by zero, so no
|
||||
/// NaN or infinity ever reaches a transform. This is the web graph's
|
||||
/// `fitScale` rule.
|
||||
double graphFitScale(
|
||||
Size viewport,
|
||||
Size content, {
|
||||
double padding = graphFitPadding,
|
||||
double minScale = graphMinScale,
|
||||
double maxScale = graphMaxScale,
|
||||
}) {
|
||||
final availableWidth = viewport.width - 2 * padding;
|
||||
final availableHeight = viewport.height - 2 * padding;
|
||||
final finite =
|
||||
viewport.width.isFinite &&
|
||||
viewport.height.isFinite &&
|
||||
content.width.isFinite &&
|
||||
content.height.isFinite;
|
||||
if (!finite ||
|
||||
content.width <= 0 ||
|
||||
content.height <= 0 ||
|
||||
availableWidth <= 0 ||
|
||||
availableHeight <= 0) {
|
||||
return 1;
|
||||
}
|
||||
final scale = math.min(
|
||||
1.0,
|
||||
math.min(availableWidth / content.width, availableHeight / content.height),
|
||||
);
|
||||
return scale.clamp(minScale, maxScale);
|
||||
}
|
||||
|
||||
/// Bounds [offset] so at least [minVisible] pixels of the already scaled
|
||||
/// [scaledContent] stay inside [viewport] on each axis.
|
||||
///
|
||||
/// The web graph's `clampOffset`: `offset.x` stays in
|
||||
/// `[minVisible - width, viewport.width - minVisible]`. Degenerate content or
|
||||
/// an empty range returns the input unchanged.
|
||||
Offset graphClampOffset(
|
||||
Offset offset,
|
||||
Size scaledContent,
|
||||
Size viewport, {
|
||||
double minVisible = graphMinVisible,
|
||||
}) {
|
||||
if (scaledContent.width <= 0 ||
|
||||
scaledContent.height <= 0 ||
|
||||
!scaledContent.width.isFinite ||
|
||||
!scaledContent.height.isFinite ||
|
||||
!viewport.width.isFinite ||
|
||||
!viewport.height.isFinite) {
|
||||
return offset;
|
||||
}
|
||||
final minX = minVisible - scaledContent.width;
|
||||
final maxX = viewport.width - minVisible;
|
||||
final minY = minVisible - scaledContent.height;
|
||||
final maxY = viewport.height - minVisible;
|
||||
return Offset(
|
||||
minX <= maxX ? offset.dx.clamp(minX, maxX) : offset.dx,
|
||||
minY <= maxY ? offset.dy.clamp(minY, maxY) : offset.dy,
|
||||
);
|
||||
}
|
||||
|
||||
/// The centered offset that puts [scaledContent] in the middle of [viewport].
|
||||
Offset graphCenteredOffset(Size scaledContent, Size viewport) => Offset(
|
||||
(viewport.width - scaledContent.width) / 2,
|
||||
(viewport.height - scaledContent.height) / 2,
|
||||
);
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../domain/graph_definition.dart';
|
||||
import '../layout/layout_models.dart';
|
||||
import '../painting/graph_edge_layer.dart';
|
||||
import '../routing/route_models.dart';
|
||||
import 'graph_canvas_style.dart';
|
||||
import 'graph_stage_node.dart';
|
||||
|
||||
/// The measured definition canvas at any viewport size and selection.
|
||||
///
|
||||
/// Used by both the inline [GraphViewport] and the expanded presentation: the
|
||||
/// passive edge layer paints behind the native nodes and outcome labels, and
|
||||
/// every node reports selection through [onSelected].
|
||||
class DefinitionGraphCanvas extends StatelessWidget {
|
||||
const DefinitionGraphCanvas({
|
||||
super.key,
|
||||
required this.nodes,
|
||||
required this.layout,
|
||||
required this.routing,
|
||||
required this.style,
|
||||
required this.selectedStage,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final List<GraphNode> nodes;
|
||||
final GraphLayout layout;
|
||||
final GraphRouting routing;
|
||||
final GraphCanvasStyle style;
|
||||
final String? selectedStage;
|
||||
final ValueChanged<String> onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nodesByKey = <String, GraphNode>{
|
||||
for (final node in nodes) node.key: node,
|
||||
};
|
||||
final size = Size(routing.width, routing.height);
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
// The passive layer comes first so every edge paints behind the native
|
||||
// nodes and labels without taking their input.
|
||||
Positioned.fill(
|
||||
child: GraphEdgeLayer(
|
||||
routes: routing.routes,
|
||||
canvasSize: size,
|
||||
color: style.edgeColor,
|
||||
strokeWidth: style.edgeWidth,
|
||||
),
|
||||
),
|
||||
for (final box in layout.nodes)
|
||||
Positioned(
|
||||
left: box.x,
|
||||
top: box.y,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
child: GraphStageNode(
|
||||
node: nodesByKey[box.key]!,
|
||||
selected: box.key == selectedStage,
|
||||
onSelected: onSelected,
|
||||
),
|
||||
),
|
||||
for (final label in routing.labels)
|
||||
Positioned(
|
||||
left: label.x,
|
||||
top: label.y,
|
||||
child: Text(
|
||||
routing.routeFor(label.edgeId)!.label,
|
||||
style: style.labelStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,23 +5,29 @@ import '../../../core/api_gateway.dart';
|
||||
import '../domain/graph_definition.dart';
|
||||
import '../layout/graph_node_layout.dart';
|
||||
import '../layout/layout_models.dart';
|
||||
import '../painting/graph_edge_layer.dart';
|
||||
import '../routing/graph_edge_routing.dart';
|
||||
import '../routing/route_models.dart';
|
||||
import '../viewport/graph_expanded_view.dart';
|
||||
import '../viewport/graph_viewport.dart';
|
||||
import '../viewport/graph_viewport_controller.dart';
|
||||
import 'definition_graph_canvas.dart';
|
||||
import 'graph_canvas_style.dart';
|
||||
import 'graph_stage_node.dart';
|
||||
import 'graph_measurements.dart';
|
||||
|
||||
/// The definition's own empty-state wording (web `PIPELINE_GRAPH_EMPTY`).
|
||||
const String definitionGraphEmpty = 'This pipeline has no stages.';
|
||||
|
||||
/// The expanded definition presentation's title.
|
||||
const String definitionGraphExpandedTitle = 'Pipeline graph';
|
||||
|
||||
/// One pipeline definition as a readable native graph: measured stage nodes,
|
||||
/// routed passive edges behind them and native outcome labels on their boxes.
|
||||
///
|
||||
/// [selectedStage] is a node key (including `#success`/`#failure`) and
|
||||
/// [onSelected] reports the exact key activated. Nothing reads run evidence:
|
||||
/// nodes show no status and terminals stay plain, so no visit is implied. The
|
||||
/// view fills bounded caller constraints with a stock [InteractiveViewer].
|
||||
/// view fills bounded caller constraints with a pan/zoom [GraphViewport] and can
|
||||
/// present the same canvas full screen without losing the selection.
|
||||
class DefinitionGraphView extends StatefulWidget {
|
||||
const DefinitionGraphView({
|
||||
super.key,
|
||||
@@ -41,9 +47,16 @@ class DefinitionGraphView extends StatefulWidget {
|
||||
class _DefinitionGraphViewState extends State<DefinitionGraphView> {
|
||||
final Map<String, Size> _nodeSizes = {};
|
||||
final Map<String, Size> _labelSizes = {};
|
||||
final GraphViewportController _viewport = GraphViewportController();
|
||||
TextScaler? _scaler;
|
||||
bool _rebuildScheduled = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_viewport.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@@ -159,56 +172,22 @@ class _DefinitionGraphViewState extends State<DefinitionGraphView> {
|
||||
GraphRouting routing,
|
||||
GraphCanvasStyle style,
|
||||
) {
|
||||
final nodesByKey = <String, GraphNode>{
|
||||
for (final node in nodes) node.key: node,
|
||||
};
|
||||
final size = Size(routing.width, routing.height);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: InteractiveViewer(
|
||||
constrained: false,
|
||||
minScale: 0.3,
|
||||
maxScale: 3,
|
||||
child: SizedBox.fromSize(
|
||||
size: size,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
// The passive layer comes first so every edge paints behind
|
||||
// the native nodes and labels without taking their input.
|
||||
Positioned.fill(
|
||||
child: GraphEdgeLayer(
|
||||
routes: routing.routes,
|
||||
canvasSize: size,
|
||||
color: style.edgeColor,
|
||||
strokeWidth: style.edgeWidth,
|
||||
),
|
||||
),
|
||||
for (final box in layout.nodes)
|
||||
Positioned(
|
||||
left: box.x,
|
||||
top: box.y,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
child: GraphStageNode(
|
||||
node: nodesByKey[box.key]!,
|
||||
selected: box.key == widget.selectedStage,
|
||||
onSelected: widget.onSelected,
|
||||
),
|
||||
),
|
||||
for (final label in routing.labels)
|
||||
Positioned(
|
||||
left: label.x,
|
||||
top: label.y,
|
||||
child: Text(
|
||||
routing.routeFor(label.edgeId)!.label,
|
||||
style: style.labelStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: GraphViewport(
|
||||
controller: _viewport,
|
||||
contentSize: size,
|
||||
onExpand: () => _openExpanded(nodes, layout, routing, size),
|
||||
child: DefinitionGraphCanvas(
|
||||
nodes: nodes,
|
||||
layout: layout,
|
||||
routing: routing,
|
||||
style: style,
|
||||
selectedStage: widget.selectedStage,
|
||||
onSelected: widget.onSelected,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -228,4 +207,28 @@ class _DefinitionGraphViewState extends State<DefinitionGraphView> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Opens the same measured canvas full screen, keeping the selection.
|
||||
void _openExpanded(
|
||||
List<GraphNode> nodes,
|
||||
GraphLayout layout,
|
||||
GraphRouting routing,
|
||||
Size size,
|
||||
) {
|
||||
openGraphExpanded(
|
||||
context,
|
||||
contentSize: size,
|
||||
title: definitionGraphExpandedTitle,
|
||||
selectedStage: widget.selectedStage,
|
||||
onSelected: widget.onSelected,
|
||||
canvasBuilder: (context, selected, onSelected) => DefinitionGraphCanvas(
|
||||
nodes: nodes,
|
||||
layout: layout,
|
||||
routing: routing,
|
||||
style: GraphCanvasStyle.of(context),
|
||||
selectedStage: selected,
|
||||
onSelected: onSelected,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,8 @@ class RunGraphEdgePainter extends CustomPainter {
|
||||
/// outcome labels only for routes the run actually took.
|
||||
///
|
||||
/// [layout] and [routing] are the caller's measured geometry. The canvas never
|
||||
/// changes them and never assumes a node size.
|
||||
/// changes them and never assumes a node size; the caller supplies the pan/zoom
|
||||
/// viewport around this content.
|
||||
class RunGraphCanvas extends StatelessWidget {
|
||||
const RunGraphCanvas({
|
||||
super.key,
|
||||
@@ -202,55 +203,47 @@ class RunGraphCanvas extends StatelessWidget {
|
||||
final executedColor = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
return InteractiveViewer(
|
||||
constrained: false,
|
||||
minScale: 0.3,
|
||||
maxScale: 3,
|
||||
child: SizedBox.fromSize(
|
||||
size: size,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: RunGraphEdgeLayer(
|
||||
executedRoutes: executed,
|
||||
untakenRoutes: untaken,
|
||||
canvasSize: size,
|
||||
executedColor: executedColor,
|
||||
untakenColor: style.edgeColor,
|
||||
strokeWidth: style.edgeWidth,
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: RunGraphEdgeLayer(
|
||||
executedRoutes: executed,
|
||||
untakenRoutes: untaken,
|
||||
canvasSize: size,
|
||||
executedColor: executedColor,
|
||||
untakenColor: style.edgeColor,
|
||||
strokeWidth: style.edgeWidth,
|
||||
),
|
||||
),
|
||||
for (final box in layout.nodes)
|
||||
Positioned(
|
||||
left: box.x,
|
||||
top: box.y,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
child: RunGraphNode(
|
||||
node: nodesByKey[box.key]!,
|
||||
recordedStatus: recordedStatuses[box.key],
|
||||
selected: box.key == selectedStage,
|
||||
opensVisit:
|
||||
!nodesByKey[box.key]!.terminal &&
|
||||
state.isStageVisited(box.key),
|
||||
onSelected: onStageSelected,
|
||||
),
|
||||
),
|
||||
// A run labels only the routes that actually happened.
|
||||
for (final label in routing.labels)
|
||||
if (executedIds.contains(label.edgeId))
|
||||
Positioned(
|
||||
left: label.x,
|
||||
top: label.y,
|
||||
child: Text(
|
||||
routing.routeFor(label.edgeId)!.label,
|
||||
style: style.labelStyle,
|
||||
),
|
||||
),
|
||||
for (final box in layout.nodes)
|
||||
Positioned(
|
||||
left: box.x,
|
||||
top: box.y,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
child: RunGraphNode(
|
||||
node: nodesByKey[box.key]!,
|
||||
recordedStatus: recordedStatuses[box.key],
|
||||
selected: box.key == selectedStage,
|
||||
opensVisit:
|
||||
!nodesByKey[box.key]!.terminal &&
|
||||
state.isStageVisited(box.key),
|
||||
onSelected: onStageSelected,
|
||||
),
|
||||
),
|
||||
// A run labels only the routes that actually happened.
|
||||
for (final label in routing.labels)
|
||||
if (executedIds.contains(label.edgeId))
|
||||
Positioned(
|
||||
left: label.x,
|
||||
top: label.y,
|
||||
child: Text(
|
||||
routing.routeFor(label.edgeId)!.label,
|
||||
style: style.labelStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../domain/run_graph_state.dart';
|
||||
import 'graph_canvas_style.dart';
|
||||
|
||||
/// The run legend's route-class words (web graph legend).
|
||||
const String runGraphExecuted = 'Executed';
|
||||
const String runGraphNotExecuted = 'Not executed';
|
||||
|
||||
/// The run canvas' fixed header: the route legend, plus the elapsed line while
|
||||
/// the run is still executing.
|
||||
///
|
||||
/// It is shared by the inline view and the full-screen presentation so the
|
||||
/// expanded canvas explains its solid and dashed routes the way the web keeps
|
||||
/// its legend inside the graph panel.
|
||||
class RunGraphHeader extends StatelessWidget {
|
||||
const RunGraphHeader({
|
||||
super.key,
|
||||
required this.state,
|
||||
required this.style,
|
||||
this.now,
|
||||
});
|
||||
|
||||
final RunGraphState state;
|
||||
final GraphCanvasStyle style;
|
||||
|
||||
/// Injectable clock for deterministic elapsed labels; defaults to now.
|
||||
final DateTime Function()? now;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final executedColor = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final mutedColor = style.edgeColor;
|
||||
final active = state.activeStage;
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 0),
|
||||
child: Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Semantics(
|
||||
container: true,
|
||||
label: 'Route kinds',
|
||||
child: Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
_LegendEntry(
|
||||
icon: cupertino
|
||||
? CupertinoIcons.arrow_right
|
||||
: Icons.arrow_forward,
|
||||
label: runGraphExecuted,
|
||||
color: executedColor,
|
||||
),
|
||||
_LegendEntry(
|
||||
icon: cupertino ? CupertinoIcons.minus : Icons.remove,
|
||||
label: runGraphNotExecuted,
|
||||
color: mutedColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (active != null)
|
||||
_elapsed(context, active, state.currentStageStartedAt),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _elapsed(BuildContext context, String active, String? startedAt) {
|
||||
final started = startedAt == null ? null : DateTime.tryParse(startedAt);
|
||||
final duration = started == null
|
||||
? null
|
||||
: _formatElapsed((now ?? DateTime.now)().difference(started));
|
||||
final text = duration == null
|
||||
? 'Current stage $active'
|
||||
: 'Current stage $active · elapsed $duration';
|
||||
return Text(text, style: GraphCanvasStyle.of(context).labelStyle);
|
||||
}
|
||||
}
|
||||
|
||||
class _LegendEntry extends StatelessWidget {
|
||||
const _LegendEntry({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
ExcludeSemantics(child: Icon(icon, color: color)),
|
||||
Text(label),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatElapsed(Duration duration) {
|
||||
final seconds = duration.inSeconds < 0 ? 0 : duration.inSeconds;
|
||||
if (seconds < 60) return '${seconds}s';
|
||||
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
|
||||
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../domain/graph_definition.dart';
|
||||
import '../domain/run_graph_state.dart';
|
||||
import '../domain/stage_visits.dart';
|
||||
@@ -10,15 +8,20 @@ import '../layout/graph_node_layout.dart';
|
||||
import '../layout/layout_models.dart';
|
||||
import '../routing/graph_edge_routing.dart';
|
||||
import '../routing/route_models.dart';
|
||||
import '../viewport/graph_expanded_view.dart';
|
||||
import '../viewport/graph_viewport.dart';
|
||||
import '../viewport/graph_viewport_controller.dart';
|
||||
import 'graph_canvas_style.dart';
|
||||
import 'run_graph_canvas.dart';
|
||||
import 'run_graph_header.dart';
|
||||
|
||||
export 'run_graph_header.dart' show runGraphExecuted, runGraphNotExecuted;
|
||||
|
||||
/// The run tab's exact missing-graph wording (web `RUN_GRAPH_MISSING`).
|
||||
const String runGraphMissing = 'This server did not include the run graph.';
|
||||
|
||||
/// The run legend's route-class words (web graph legend).
|
||||
const String runGraphExecuted = 'Executed';
|
||||
const String runGraphNotExecuted = 'Not executed';
|
||||
/// The expanded run presentation's title.
|
||||
const String runGraphExpandedTitle = 'Run graph';
|
||||
|
||||
/// One run's definition drawn as evidence: visited stages carry their recorded
|
||||
/// status, only taken routes are solid and arrowed, and every other route stays
|
||||
@@ -32,9 +35,10 @@ const String runGraphNotExecuted = 'Not executed';
|
||||
/// shown with the outcome that resolved there but have no recorded visit to
|
||||
/// open, so they stay non-interactive.
|
||||
///
|
||||
/// The view fills its bounded constraints with a stock [InteractiveViewer] for
|
||||
/// pan and zoom; the elapsed line appears only while the run is executing and
|
||||
/// is static (no invented progress or timer).
|
||||
/// The view fills its bounded constraints with a pan/zoom [GraphViewport]; the
|
||||
/// elapsed line appears only while the run is executing and is static (no
|
||||
/// invented progress or timer). The same canvas can be opened full screen with
|
||||
/// its selection preserved and the route legend still explaining its marks.
|
||||
class RunGraphView extends StatefulWidget {
|
||||
const RunGraphView({
|
||||
super.key,
|
||||
@@ -67,9 +71,16 @@ class _RunGraphViewState extends State<RunGraphView> {
|
||||
final Map<String, Size> _nodeSizes = {};
|
||||
final Map<String, Size> _labelSizes = {};
|
||||
final Map<String, String?> _measuredStatuses = {};
|
||||
final GraphViewportController _viewport = GraphViewportController();
|
||||
TextScaler? _scaler;
|
||||
bool _rebuildScheduled = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_viewport.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@@ -188,21 +199,32 @@ class _RunGraphViewState extends State<RunGraphView> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_header(state, style),
|
||||
RunGraphHeader(state: state, style: style, now: widget.now),
|
||||
Expanded(
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
if (geometry != null)
|
||||
RunGraphCanvas(
|
||||
nodes: nodes,
|
||||
layout: geometry.$1,
|
||||
routing: geometry.$2,
|
||||
state: state,
|
||||
style: style,
|
||||
recordedStatuses: statuses,
|
||||
selectedStage: widget.selectedStage,
|
||||
onStageSelected: widget.onStageSelected,
|
||||
GraphViewport(
|
||||
controller: _viewport,
|
||||
contentSize: Size(geometry.$2.width, geometry.$2.height),
|
||||
onExpand: () => _openExpanded(
|
||||
nodes,
|
||||
geometry.$1,
|
||||
geometry.$2,
|
||||
state,
|
||||
statuses,
|
||||
),
|
||||
child: _runCanvas(
|
||||
nodes: nodes,
|
||||
layout: geometry.$1,
|
||||
routing: geometry.$2,
|
||||
state: state,
|
||||
style: style,
|
||||
statuses: statuses,
|
||||
selectedStage: widget.selectedStage,
|
||||
onStageSelected: widget.onStageSelected,
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox.shrink(),
|
||||
@@ -245,87 +267,58 @@ class _RunGraphViewState extends State<RunGraphView> {
|
||||
),
|
||||
);
|
||||
|
||||
Widget _header(RunGraphState state, GraphCanvasStyle style) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final executedColor = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final mutedColor = style.edgeColor;
|
||||
final active = state.activeStage;
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 0),
|
||||
child: Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Semantics(
|
||||
container: true,
|
||||
label: 'Route kinds',
|
||||
child: Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
_LegendEntry(
|
||||
icon: cupertino
|
||||
? CupertinoIcons.arrow_right
|
||||
: Icons.arrow_forward,
|
||||
label: runGraphExecuted,
|
||||
color: executedColor,
|
||||
),
|
||||
_LegendEntry(
|
||||
icon: cupertino ? CupertinoIcons.minus : Icons.remove,
|
||||
label: runGraphNotExecuted,
|
||||
color: mutedColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (active != null) _elapsed(active, state.currentStageStartedAt),
|
||||
],
|
||||
/// The same measured run canvas at any viewport size and selection, used by
|
||||
/// the inline viewport and the expanded presentation.
|
||||
Widget _runCanvas({
|
||||
required List<GraphNode> nodes,
|
||||
required GraphLayout layout,
|
||||
required GraphRouting routing,
|
||||
required RunGraphState state,
|
||||
required GraphCanvasStyle style,
|
||||
required Map<String, String?> statuses,
|
||||
required String? selectedStage,
|
||||
required ValueChanged<String> onStageSelected,
|
||||
}) => RunGraphCanvas(
|
||||
nodes: nodes,
|
||||
layout: layout,
|
||||
routing: routing,
|
||||
state: state,
|
||||
style: style,
|
||||
recordedStatuses: statuses,
|
||||
selectedStage: selectedStage,
|
||||
onStageSelected: onStageSelected,
|
||||
);
|
||||
|
||||
void _openExpanded(
|
||||
List<GraphNode> nodes,
|
||||
GraphLayout layout,
|
||||
GraphRouting routing,
|
||||
RunGraphState state,
|
||||
Map<String, String?> statuses,
|
||||
) {
|
||||
openGraphExpanded(
|
||||
context,
|
||||
contentSize: Size(routing.width, routing.height),
|
||||
title: runGraphExpandedTitle,
|
||||
selectedStage: widget.selectedStage,
|
||||
onSelected: widget.onStageSelected,
|
||||
// The full-screen canvas draws solid and dashed routes; the legend that
|
||||
// explains them must travel with it, as it does on the web.
|
||||
header: RunGraphHeader(
|
||||
state: state,
|
||||
style: GraphCanvasStyle.of(context),
|
||||
now: widget.now,
|
||||
),
|
||||
canvasBuilder: (context, selected, onSelected) => _runCanvas(
|
||||
nodes: nodes,
|
||||
layout: layout,
|
||||
routing: routing,
|
||||
state: state,
|
||||
style: GraphCanvasStyle.of(context),
|
||||
statuses: statuses,
|
||||
selectedStage: selected,
|
||||
onStageSelected: onSelected,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _elapsed(String active, String? startedAt) {
|
||||
final started = startedAt == null ? null : DateTime.tryParse(startedAt);
|
||||
final duration = started == null
|
||||
? null
|
||||
: _formatElapsed((widget.now ?? DateTime.now)().difference(started));
|
||||
final text = duration == null
|
||||
? 'Current stage $active'
|
||||
: 'Current stage $active · elapsed $duration';
|
||||
return Text(text, style: GraphCanvasStyle.of(context).labelStyle);
|
||||
}
|
||||
}
|
||||
|
||||
class _LegendEntry extends StatelessWidget {
|
||||
const _LegendEntry({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
ExcludeSemantics(child: Icon(icon, color: color)),
|
||||
Text(label),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatElapsed(Duration duration) {
|
||||
final seconds = duration.inSeconds < 0 ? 0 : duration.inSeconds;
|
||||
if (seconds < 60) return '${seconds}s';
|
||||
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
|
||||
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user