pub struct TracesController { /* private fields */ }Expand description
Controller to observe and modify traces UI state (color/visibility/marker selection).
Implementations§
Source§impl TracesController
impl TracesController
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/custom_colors.rs (line 43)
15fn main() -> eframe::Result<()> {
16 // Create multi-trace plot channel
17 let (sink, rx) = channel_plot();
18 let tr_sine = sink.create_trace("sine", None);
19 let tr_cos = sink.create_trace("cosine", None);
20
21 // Producer: 1 kHz sample rate, 3 Hz sine and cosine
22 std::thread::spawn(move || {
23 const FS_HZ: f64 = 1000.0; // 1 kHz sampling rate
24 const F_HZ: f64 = 3.0; // 3 Hz
25 let dt = Duration::from_millis(1);
26 let mut n: u64 = 0;
27 loop {
28 let t = n as f64 / FS_HZ;
29 let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
30 let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
31 let t_s = SystemTime::now()
32 .duration_since(UNIX_EPOCH)
33 .map(|d| d.as_secs_f64())
34 .unwrap_or(0.0);
35 let _ = sink.send_point(&tr_sine, PlotPoint { x: t_s, y: s_val });
36 let _ = sink.send_point(&tr_cos, PlotPoint { x: t_s, y: c_val });
37 n = n.wrapping_add(1);
38 std::thread::sleep(dt);
39 }
40 });
41
42 // Traces controller to set custom colors once traces appear
43 let traces_ctrl = TracesController::new();
44 {
45 // In a background thread, subscribe to trace info and set colors when seen
46 let ctrl = traces_ctrl.clone();
47 let rx_info = ctrl.subscribe();
48 std::thread::spawn(move || {
49 while let Ok(info) = rx_info.recv() {
50 for tr in info.traces {
51 match tr.name.as_str() {
52 "sine" => ctrl.request_set_color("sine", [0xFF, 0x66, 0x00]), // orange
53 "cosine" => ctrl.request_set_color("cosine", [0x00, 0x99, 0xFF]), // blue
54 _ => {}
55 }
56 }
57 }
58 });
59 }
60
61 // Run the UI with the controller attached via config
62 let mut cfg = LivePlotConfig::default();
63 cfg.title = "LivePlot (custom colors)".into();
64 cfg.traces_controller = Some(traces_ctrl);
65 run_liveplot(rx, cfg)
66}Sourcepub fn request_set_color<S: Into<String>>(&self, name: S, rgb: [u8; 3])
pub fn request_set_color<S: Into<String>>(&self, name: S, rgb: [u8; 3])
Request setting the RGB color of a trace by name.
Examples found in repository?
examples/custom_colors.rs (line 52)
15fn main() -> eframe::Result<()> {
16 // Create multi-trace plot channel
17 let (sink, rx) = channel_plot();
18 let tr_sine = sink.create_trace("sine", None);
19 let tr_cos = sink.create_trace("cosine", None);
20
21 // Producer: 1 kHz sample rate, 3 Hz sine and cosine
22 std::thread::spawn(move || {
23 const FS_HZ: f64 = 1000.0; // 1 kHz sampling rate
24 const F_HZ: f64 = 3.0; // 3 Hz
25 let dt = Duration::from_millis(1);
26 let mut n: u64 = 0;
27 loop {
28 let t = n as f64 / FS_HZ;
29 let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
30 let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
31 let t_s = SystemTime::now()
32 .duration_since(UNIX_EPOCH)
33 .map(|d| d.as_secs_f64())
34 .unwrap_or(0.0);
35 let _ = sink.send_point(&tr_sine, PlotPoint { x: t_s, y: s_val });
36 let _ = sink.send_point(&tr_cos, PlotPoint { x: t_s, y: c_val });
37 n = n.wrapping_add(1);
38 std::thread::sleep(dt);
39 }
40 });
41
42 // Traces controller to set custom colors once traces appear
43 let traces_ctrl = TracesController::new();
44 {
45 // In a background thread, subscribe to trace info and set colors when seen
46 let ctrl = traces_ctrl.clone();
47 let rx_info = ctrl.subscribe();
48 std::thread::spawn(move || {
49 while let Ok(info) = rx_info.recv() {
50 for tr in info.traces {
51 match tr.name.as_str() {
52 "sine" => ctrl.request_set_color("sine", [0xFF, 0x66, 0x00]), // orange
53 "cosine" => ctrl.request_set_color("cosine", [0x00, 0x99, 0xFF]), // blue
54 _ => {}
55 }
56 }
57 }
58 });
59 }
60
61 // Run the UI with the controller attached via config
62 let mut cfg = LivePlotConfig::default();
63 cfg.title = "LivePlot (custom colors)".into();
64 cfg.traces_controller = Some(traces_ctrl);
65 run_liveplot(rx, cfg)
66}Sourcepub fn request_set_visible<S: Into<String>>(&self, name: S, visible: bool)
pub fn request_set_visible<S: Into<String>>(&self, name: S, visible: bool)
Request setting the visibility of a trace by name.
Sourcepub fn request_set_offset<S: Into<String>>(&self, name: S, offset: f64)
pub fn request_set_offset<S: Into<String>>(&self, name: S, offset: f64)
Request setting the Y offset of a trace by name.
Sourcepub fn request_set_y_unit<S: Into<String>>(&self, unit: Option<S>)
pub fn request_set_y_unit<S: Into<String>>(&self, unit: Option<S>)
Request setting the global Y unit label (None for no unit).
Sourcepub fn request_set_y_log(&self, enable: bool)
pub fn request_set_y_log(&self, enable: bool)
Request toggling Y log scale.
Sourcepub fn request_select_marker_free(&self)
pub fn request_select_marker_free(&self)
Request selecting the marker to be “Free” (no snapping).
Sourcepub fn request_select_marker_trace<S: Into<String>>(&self, name: S)
pub fn request_select_marker_trace<S: Into<String>>(&self, name: S)
Request selecting a specific trace for markers.
Sourcepub fn subscribe(&self) -> Receiver<TracesInfo>
pub fn subscribe(&self) -> Receiver<TracesInfo>
Subscribe to receive updates about traces and current selection.
Examples found in repository?
examples/custom_colors.rs (line 47)
15fn main() -> eframe::Result<()> {
16 // Create multi-trace plot channel
17 let (sink, rx) = channel_plot();
18 let tr_sine = sink.create_trace("sine", None);
19 let tr_cos = sink.create_trace("cosine", None);
20
21 // Producer: 1 kHz sample rate, 3 Hz sine and cosine
22 std::thread::spawn(move || {
23 const FS_HZ: f64 = 1000.0; // 1 kHz sampling rate
24 const F_HZ: f64 = 3.0; // 3 Hz
25 let dt = Duration::from_millis(1);
26 let mut n: u64 = 0;
27 loop {
28 let t = n as f64 / FS_HZ;
29 let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
30 let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
31 let t_s = SystemTime::now()
32 .duration_since(UNIX_EPOCH)
33 .map(|d| d.as_secs_f64())
34 .unwrap_or(0.0);
35 let _ = sink.send_point(&tr_sine, PlotPoint { x: t_s, y: s_val });
36 let _ = sink.send_point(&tr_cos, PlotPoint { x: t_s, y: c_val });
37 n = n.wrapping_add(1);
38 std::thread::sleep(dt);
39 }
40 });
41
42 // Traces controller to set custom colors once traces appear
43 let traces_ctrl = TracesController::new();
44 {
45 // In a background thread, subscribe to trace info and set colors when seen
46 let ctrl = traces_ctrl.clone();
47 let rx_info = ctrl.subscribe();
48 std::thread::spawn(move || {
49 while let Ok(info) = rx_info.recv() {
50 for tr in info.traces {
51 match tr.name.as_str() {
52 "sine" => ctrl.request_set_color("sine", [0xFF, 0x66, 0x00]), // orange
53 "cosine" => ctrl.request_set_color("cosine", [0x00, 0x99, 0xFF]), // blue
54 _ => {}
55 }
56 }
57 }
58 });
59 }
60
61 // Run the UI with the controller attached via config
62 let mut cfg = LivePlotConfig::default();
63 cfg.title = "LivePlot (custom colors)".into();
64 cfg.traces_controller = Some(traces_ctrl);
65 run_liveplot(rx, cfg)
66}Trait Implementations§
Source§impl Clone for TracesController
impl Clone for TracesController
Source§fn clone(&self) -> TracesController
fn clone(&self) -> TracesController
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TracesController
impl RefUnwindSafe for TracesController
impl Send for TracesController
impl Sync for TracesController
impl Unpin for TracesController
impl UnwindSafe for TracesController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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