Skip to main content

LivePlotApp

Struct LivePlotApp 

Source
pub struct LivePlotApp {
    pub main_panel: LivePlotPanel,
    pub window_ctrl: Option<WindowController>,
    pub ui_ctrl: Option<UiActionController>,
    pub traces_ctrl: Option<TracesController>,
    pub scopes_ctrl: Option<ScopesController>,
    pub liveplot_ctrl: Option<LiveplotController>,
    pub fft_ctrl: Option<FFTController>,
    pub threshold_ctrl: Option<ThresholdController>,
    pub headline: Option<String>,
    pub subheadline: Option<String>,
    pub color_scheme: Option<ColorScheme>,
    /* private fields */
}
Expand description

Standalone LivePlot application that implements eframe::App.

LivePlotApp is the top-level container used when LivePlot runs in its own native window (via run_liveplot). It:

  1. Owns a LivePlotPanel that does the actual rendering.
  2. Holds optional controller handles for programmatic interaction.
  3. Processes controller requests each frame in apply_controllers.
  4. Applies initial configuration from LivePlotConfig.

Fields§

§main_panel: LivePlotPanel

The inner panel widget that owns all data and UI state.

§window_ctrl: Option<WindowController>

Controls the host window (size, position).

§ui_ctrl: Option<UiActionController>

Programmatic UI actions (pause, screenshot, export).

§traces_ctrl: Option<TracesController>

Programmatic trace manipulation (colour, visibility, offset, etc.).

§scopes_ctrl: Option<ScopesController>

Programmatic scope management (add/remove/configure scopes).

§liveplot_ctrl: Option<LiveplotController>

High-level liveplot control (pause all, clear all, save/load state).

§fft_ctrl: Option<FFTController>

FFT panel control (show/hide, resize).

§threshold_ctrl: Option<ThresholdController>

Threshold management (add/remove thresholds, listen for threshold events).

§headline: Option<String>

Optional heading text shown at the top of the window.

§subheadline: Option<String>

Optional sub-heading text shown below the headline.

§color_scheme: Option<ColorScheme>

Color scheme to apply to the egui context. Applied once on the first frame.

Implementations§

Source§

impl LivePlotApp

Source

pub fn new(rx: Receiver<PlotCommand>) -> Self

Create a new LivePlotApp without any controllers.

Examples found in repository?
examples/embedded_window.rs (line 41)
37    fn new() -> Self {
38        let (sink, rx) = channel_plot();
39        let trace_sine = sink.create_trace("sine", None);
40        let trace_cos = sink.create_trace("cosine", None);
41        let mut plot = LivePlotApp::new(rx);
42        // Configure the embedded main panel's data
43        for scope in plot.main_panel.liveplot_panel.get_data_mut() {
44            scope.time_window = 10.0;
45        }
46        plot.main_panel.traces_data.max_points = 10_000;
47        Self {
48            kind: WaveKind::Sine,
49            sink,
50            trace_sine,
51            trace_cos,
52            plot,
53            show_plot_window: false,
54        }
55    }
More examples
Hide additional examples
examples/color_scheme.rs (line 112)
81fn main() -> eframe::Result<()> {
82    let scheme = std::env::args()
83        .nth(1)
84        .map(|a| parse_scheme(&a))
85        .unwrap_or(ColorScheme::Dark);
86
87    let (sink, rx) = channel_plot();
88    let tr_sine = sink.create_trace("sine", None);
89    let tr_cos = sink.create_trace("cosine", None);
90
91    // Producer: 1 kHz, 3 Hz sine + cosine
92    std::thread::spawn(move || {
93        const FS_HZ: f64 = 1000.0;
94        const F_HZ: f64 = 3.0;
95        let dt = Duration::from_millis(1);
96        let mut n: u64 = 0;
97        loop {
98            let t = n as f64 / FS_HZ;
99            let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
100            let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
101            let t_s = SystemTime::now()
102                .duration_since(UNIX_EPOCH)
103                .map(|d| d.as_secs_f64())
104                .unwrap_or(0.0);
105            let _ = sink.send_point(&tr_sine, PlotPoint { x: t_s, y: s_val });
106            let _ = sink.send_point(&tr_cos, PlotPoint { x: t_s, y: c_val });
107            n = n.wrapping_add(1);
108            std::thread::sleep(dt);
109        }
110    });
111
112    let plot = LivePlotApp::new(rx);
113    let app = ColorSchemePickerApp { scheme, plot };
114
115    eframe::run_native(
116        "Color Scheme Demo",
117        eframe::NativeOptions::default(),
118        Box::new(|_cc| Ok(Box::new(app))),
119    )
120}
examples/features.rs (line 67)
37    fn new() -> Self {
38        // create shared sink/receiver pair and register traces
39        let (sink, rx) = channel_plot();
40        let tr_sine = sink.create_trace("sine", None);
41        let tr_cos = sink.create_trace("cosine", None);
42
43        // spawn the producer thread (1 kHz sample rate as in sine_cosine.rs)
44        let sink_clone = sink.clone();
45        let sine_clone = tr_sine.clone();
46        let cos_clone = tr_cos.clone();
47        std::thread::spawn(move || {
48            const FS_HZ: f64 = 1000.0;
49            const F_HZ: f64 = 3.0;
50            let dt = Duration::from_millis(1);
51            let mut n: u64 = 0;
52            loop {
53                let t = n as f64 / FS_HZ;
54                let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
55                let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
56                let t_s = SystemTime::now()
57                    .duration_since(UNIX_EPOCH)
58                    .map(|d| d.as_secs_f64())
59                    .unwrap_or(0.0);
60                let _ = sink_clone.send_point(&sine_clone, PlotPoint { x: t_s, y: s_val });
61                let _ = sink_clone.send_point(&cos_clone, PlotPoint { x: t_s, y: c_val });
62                n = n.wrapping_add(1);
63                std::thread::sleep(dt);
64            }
65        });
66
67        let plot = LivePlotApp::new(rx);
68        let features = FeatureFlags::default();
69
70        Self {
71            plot,
72            features,
73            _sink: sink,
74            _tr_sine: tr_sine,
75            _tr_cos: tr_cos,
76        }
77    }
Source

pub fn with_controllers( rx: Receiver<PlotCommand>, window_ctrl: Option<WindowController>, ui_ctrl: Option<UiActionController>, traces_ctrl: Option<TracesController>, scopes_ctrl: Option<ScopesController>, liveplot_ctrl: Option<LiveplotController>, fft_ctrl: Option<FFTController>, threshold_ctrl: Option<ThresholdController>, ) -> Self

Create a new LivePlotApp with the given controller handles already wired.

Trait Implementations§

Source§

impl App for LivePlotApp

Source§

fn update(&mut self, ctx: &Context, frame: &mut Frame)

Called each time the UI needs repainting, which may be many times per second. Read more
Source§

fn save(&mut self, _storage: &mut dyn Storage)

Called on shutdown, and perhaps at regular intervals. Allows you to save state. Read more
Source§

fn on_exit(&mut self, _gl: Option<&Context>)

Called once on shutdown, after Self::save. Read more
Source§

fn auto_save_interval(&self) -> Duration

Time between automatic calls to Self::save
Source§

fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]

Background color values for the app, e.g. what is sent to gl.clearColor. Read more
Source§

fn persist_egui_memory(&self) -> bool

Controls whether or not the egui memory (window positions etc) will be persisted (only if the “persistence” feature is enabled).
Source§

fn raw_input_hook(&mut self, _ctx: &Context, _raw_input: &mut RawInput)

A hook for manipulating or filtering raw input before it is processed by Self::update. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more