egui_plotter/charts/
timedata.rs1use egui::Ui;
4use plotters::style::{RGBAColor, ShapeStyle};
5
6use crate::charts::XyTimeData;
7
8pub struct TimeData {
25 chart: XyTimeData,
26}
27
28impl TimeData {
29 pub fn new(points: &[(f32, f32)], unit: &str, caption: &str) -> Self {
31 let points: Vec<(f32, f32, f32)> = points
32 .into_iter()
33 .map(|(data, time)| (*data, *time, *time))
34 .collect();
35
36 let chart = XyTimeData::new(&points, "seconds", unit, caption);
37
38 Self { chart }
39 }
40
41 #[inline]
43 pub fn set_time(&mut self, time: f32) {
44 self.chart.set_time(time)
45 }
46
47 #[inline]
49 pub fn time(mut self, time: f32) -> Self {
50 self.set_time(time);
51
52 self
53 }
54
55 #[inline]
57 pub fn set_playback_speed(&mut self, speed: f32) {
58 self.chart.set_playback_speed(speed)
59 }
60
61 #[inline]
63 pub fn playback_speed(mut self, speed: f32) -> Self {
64 self.set_playback_speed(speed);
65
66 self
67 }
68
69 #[inline]
70 pub fn set_line_style(&mut self, line_style: ShapeStyle) {
72 self.chart.set_line_style(line_style)
73 }
74
75 #[inline]
76 pub fn line_style(mut self, line_style: ShapeStyle) -> Self {
78 self.set_line_style(line_style);
79
80 self
81 }
82
83 #[inline]
84 pub fn set_grid_style(&mut self, grid_style: ShapeStyle) {
86 self.chart.set_grid_style(grid_style)
87 }
88
89 #[inline]
90 pub fn grid_style(mut self, grid_style: ShapeStyle) -> Self {
92 self.set_grid_style(grid_style);
93
94 self
95 }
96
97 #[inline]
98 pub fn set_subgrid_style(&mut self, subgrid_style: ShapeStyle) {
100 self.chart.set_subgrid_style(subgrid_style)
101 }
102
103 #[inline]
104 pub fn subgrid_style(mut self, subgrid_style: ShapeStyle) -> Self {
106 self.set_subgrid_style(subgrid_style);
107
108 self
109 }
110
111 #[inline]
112 pub fn set_axes_style(&mut self, axes_style: ShapeStyle) {
114 self.chart.set_axes_style(axes_style)
115 }
116
117 #[inline]
118 pub fn axes_style(mut self, axes_style: ShapeStyle) -> Self {
120 self.set_axes_style(axes_style);
121
122 self
123 }
124
125 #[inline]
126 pub fn set_text_color<T>(&mut self, color: T)
128 where
129 T: Into<RGBAColor>,
130 {
131 self.chart.set_text_color(color)
132 }
133
134 #[inline]
135 pub fn text_color<T>(mut self, color: T) -> Self
137 where
138 T: Into<RGBAColor>,
139 {
140 self.set_text_color(color);
141
142 self
143 }
144
145 #[inline]
146 pub fn set_background_color<T>(&mut self, color: T)
148 where
149 T: Into<RGBAColor>,
150 {
151 self.chart.set_background_color(color);
152 }
153
154 #[inline]
155 pub fn background_color<T>(mut self, color: T) -> Self
157 where
158 T: Into<RGBAColor>,
159 {
160 self.set_background_color(color);
161
162 self
163 }
164
165 #[inline]
166 pub fn set_ratio(&mut self, ratio: f32) {
168 self.chart.set_ratio(ratio);
169 }
170
171 #[inline]
172 pub fn ratio(mut self, ratio: f32) -> Self {
174 self.set_ratio(ratio);
175
176 self
177 }
178
179 pub fn draw(&mut self, ui: &Ui) {
182 self.chart.draw(ui)
183 }
184
185 #[inline]
187 pub fn start_playback(&mut self) {
188 self.chart.start_playback()
189 }
190
191 #[inline]
193 pub fn stop_playback(&mut self) {
194 self.chart.stop_playback()
195 }
196
197 pub fn toggle_playback(&mut self) {
199 self.chart.toggle_playback()
200 }
201
202 #[inline]
204 pub fn is_playing(&self) -> bool {
205 self.chart.is_playing()
206 }
207
208 #[inline]
210 pub fn start_time(&self) -> f32 {
211 self.chart.start_time()
212 }
213
214 #[inline]
216 pub fn current_time(&mut self) -> f32 {
217 self.chart.current_time()
218 }
219
220 #[inline]
222 pub fn end_time(&self) -> f32 {
223 self.chart.end_time()
224 }
225
226 #[inline]
228 pub fn get_playback_speed(&self) -> f32 {
229 self.chart.get_playback_speed()
230 }
231}