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

Function new_plot

examples/auto_backend.rs:178–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

176}
177
178fn new_plot() -> PlotWidget {
179 let positions = (0..100)
180 .map(|i| {
181 let x = i as f64 * 0.1;
182 let y = (x * 0.5).sin();
183 [x, y]
184 })
185 .collect();
186
187 let s1 = Series::line_only(positions, LineStyle::solid().with_pixel_width(4.0))
188 .with_label("sine_line_only")
189 .with_color(Color::from_rgb(0.3, 0.3, 0.9));
190
191 let positions = (0..50)
192 .map(|i| {
193 let x = i as f64 * 0.2;
194 let y = (x * 0.3).cos() + 0.5;
195 [x, y]
196 })
197 .collect();
198 let s2 = Series::markers_only(positions, MarkerStyle::circle(6.0))
199 .with_label("cosine_markers_only (not pickable)")
200 .with_pickable(false)
201 .with_color(Color::from_rgb(0.9, 0.3, 0.3));
202
203 let positions = (0..30)
204 .map(|i| {
205 let x = i as f64 * 0.3;
206 let y = (x * 0.8).sin() - 0.5;
207 [x, y]
208 })
209 .collect();
210 let s3 = Series::new(positions, MarkerStyle::square(4.0), LineStyle::dashed(10.0))
211 .with_label("both_markers_and_lines")
212 .with_color(Color::from_rgb(0.3, 0.9, 0.3));
213
214 PlotWidgetBuilder::new()
215 .with_hover_highlight_provider(|context, point| {
216 if point.marker_style.is_none() {
217 point.marker_style = Some(MarkerStyle::circle(6.0));
218 }
219 Some(format!(
220 "Index: {}\nX: {:.2}\nY: {:.2}",
221 context.point_index, point.x, point.y
222 ))
223 })
224 .with_pick_highlight_provider(|ctx, point| {
225 if point.marker_style.is_none() {
226 // set plot 1 to star in pick highlight
227 point.marker_style = Some(MarkerStyle::triangle(6.0));
228 }
229 point.mask_padding = None;
230 point.resize_marker(1.5);
231 point.color = Color::from_rgb(1.0, 0.0, 0.0);
232 Some(format!(
233 "Index: {}\nX: {:.2}\nY: {:.2}\n(Selected)",
234 ctx.point_index, point.x, point.y
235 ))

Callers 1

newMethod · 0.85

Calls 15

mapMethod · 0.80
with_pixel_widthMethod · 0.80
with_pickableMethod · 0.80
buildMethod · 0.80
with_crosshairsMethod · 0.80
with_axis_label_sizeMethod · 0.80
with_tick_label_sizeMethod · 0.80
with_x_tick_formatterMethod · 0.80
with_x_labelMethod · 0.80
with_y_labelMethod · 0.80
with_cursor_providerMethod · 0.80
with_cursor_overlayMethod · 0.80

Tested by

no test coverage detected