damascene_core/plot/request.rs
1//! Programmatic [`plot()`](crate::tree::plot) view commands — the plot
2//! counterpart of [`crate::viewport::ViewportRequest`].
3//!
4//! Apps accumulate requests from event handlers (a "Fit" toolbar button,
5//! a "last 60 s" preset) and hand them to the host once per frame via
6//! [`crate::event::App::drain_plot_requests`]; each is consumed during
7//! [`UiState::prepare_plots`](crate::state::UiState) by the plot whose
8//! `.key(...)` it names, where the live data bounds are known. This is
9//! the app-side write half of the view API —
10//! [`plot_view_by_key`](crate::state::UiState::plot_view_by_key) is the
11//! read half — so `build` / `on_event` code can drive the view without
12//! `&mut UiState`.
13
14// Lock in full per-item documentation for this module (issue #73).
15#![warn(missing_docs)]
16
17/// What an app produces to drive a [`plot()`](crate::tree::plot)'s view
18/// programmatically. Push once per build via
19/// [`App::drain_plot_requests`](crate::event::App::drain_plot_requests);
20/// unmatched requests (the keyed plot wasn't in the tree this frame) are
21/// dropped, like [`crate::viewport::ViewportRequest`]s.
22#[derive(Clone, Debug, PartialEq)]
23pub enum PlotRequest {
24 /// Re-fit both axes to the full data extent and restore per-axis
25 /// autoscaling — the programmatic double-click reset. Re-arms
26 /// [`x_autoscale`](crate::plot::PlotSpec::x_autoscale) /
27 /// [`y_autoscale`](crate::plot::PlotSpec::y_autoscale) tracking that a
28 /// manual gesture had released.
29 FitAll {
30 /// `.key(...)` of the target plot.
31 key: String,
32 },
33 /// Pin the horizontal window to `[min, max]` in data space, taking
34 /// manual X control (autoscale-X stops tracking until a reset /
35 /// [`Self::FitAll`]). Y still autoscales to the new window unless the
36 /// user holds manual Y. Ignored when the window is empty or
37 /// non-finite.
38 SetXWindow {
39 /// `.key(...)` of the target plot.
40 key: String,
41 /// Lower edge of the window, in X data space.
42 min: f64,
43 /// Upper edge of the window, in X data space (must exceed `min`).
44 max: f64,
45 },
46}
47
48impl PlotRequest {
49 /// The `.key(...)` of the plot this request targets.
50 pub fn key(&self) -> &str {
51 match self {
52 PlotRequest::FitAll { key } | PlotRequest::SetXWindow { key, .. } => key,
53 }
54 }
55}