MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / update

Method update

examples/scrolling_plot.rs:36–62  ·  view source on GitHub ↗
(&mut self, message: Message, now: std::time::Instant)

Source from the content-addressed store, hash-verified

34
35impl App {
36 fn update(&mut self, message: Message, now: std::time::Instant) {
37 match message {
38 Message::PlotMessage(plot_msg) => {
39 self.widget.update(plot_msg);
40 }
41 Message::Tick => {
42 if self.last_tick.elapsed() < Duration::from_millis(30) {
43 return;
44 }
45 self.last_tick = now;
46
47 let y = (self.x * 0.5).sin();
48 // Update the series
49 self.widget
50 .update_series(&self.series_id, |series| {
51 // Add new point
52 series.positions.push([self.x, y]);
53 // Keep only last 300 points for scrolling effect
54 if series.positions.len() > 300 {
55 series.positions.remove(0);
56 }
57 })
58 .unwrap();
59 self.x += 0.1f64;
60 }
61 }
62 }
63
64 fn view(&self) -> Element<'_, Message> {
65 self.widget.view().map(Message::PlotMessage)

Callers

nothing calls this directly

Calls 1

update_seriesMethod · 0.80

Tested by

no test coverage detected