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

Function new

examples/line_only.rs:52–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50}
51
52fn new() -> PlotWidget {
53 let positions = (0..100)
54 .map(|i| {
55 let x = i as f64 * 0.1;
56 let y = (x * 0.5).sin();
57 [x, y]
58 })
59 .collect();
60
61 let s1 = Series::line_only(positions, LineStyle::solid().with_pixel_width(4.0))
62 .with_label("sine_line_only")
63 .with_color(Color::from_rgb(0.3, 0.3, 0.9));
64
65 let positions = (0..50)
66 .map(|i| {
67 let x = i as f64 * 0.2;
68 let y = (x * 0.3).cos() + 0.5;
69 [x, y]
70 })
71 .collect();
72 let s2 = Series::markers_only(positions, MarkerStyle::circle(6.0))
73 .with_label("cosine_markers_only (not pickable)")
74 .with_pickable(false)
75 .with_color(Color::from_rgb(0.9, 0.3, 0.3));
76
77 let positions = (0..30)
78 .map(|i| {
79 let x = i as f64 * 0.3;
80 let y = (x * 0.8).sin() - 0.5;
81 [x, y]
82 })
83 .collect();
84 let s3 = Series::new(positions, MarkerStyle::square(4.0), LineStyle::dashed(10.0))
85 .with_label("both_markers_and_lines")
86 .with_color(Color::from_rgb(0.3, 0.9, 0.3));
87
88 PlotWidgetBuilder::new()
89 .with_hover_highlight_provider(|context, point| {
90 if point.marker_style.is_none() {
91 point.marker_style = Some(MarkerStyle::circle(6.0));
92 }
93 Some(format!(
94 "Index: {}\nX: {:.2}\nY: {:.2}",
95 context.point_index, point.x, point.y
96 ))
97 })
98 .with_pick_highlight_provider(|ctx, point| {
99 if point.marker_style.is_none() {
100 // set plot 1 to star in pick highlight
101 point.marker_style = Some(MarkerStyle::triangle(6.0));
102 }
103 point.mask_padding = None;
104 point.resize_marker(1.5);
105 point.color = Color::from_rgb(1.0, 0.0, 0.0);
106 Some(format!(
107 "Index: {}\nX: {:.2}\nY: {:.2}\n(Selected)",
108 ctx.point_index, point.x, point.y
109 ))

Callers

nothing calls this directly

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