feat(app): graph pan, zoom and expanded view
This commit is contained in:
@@ -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