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

Method new

examples/three_plots.rs:150–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

148 }
149
150 fn new() -> Self {
151 // Create a shared x-axis link so all three plots pan/zoom together on the x-axis
152 let x_link = AxisLink::new();
153 let no_scroll_pan_controls = || {
154 let mut controls = PlotControls::default();
155 controls.unbind_scroll(keyboard::Modifiers::NONE);
156 controls
157 };
158
159 let positions = (0..100)
160 .map(|i| {
161 let x = i as f64 * 0.1;
162 let y = (x * 0.5).sin();
163 [x, y]
164 })
165 .collect();
166 let s1 = Series::line_only(positions, LineStyle::solid()).with_label("sine_line_only");
167 let s1_id = s1.id;
168 let w1 = PlotWidgetBuilder::new()
169 .with_controls(no_scroll_pan_controls())
170 .with_hover_highlight_provider(Self::hover_highlight_provider)
171 .with_pick_highlight_provider(Self::pick_highlight_provider)
172 .with_x_lim(-1.0, 10.0) // Set x-axis limits
173 .with_y_lim(-2.0, 2.0) // Set y-axis limits
174 .with_x_axis_link(x_link.clone()) // Link the x-axis
175 .add_series(s1)
176 .with_crosshairs(true)
177 .build()
178 .unwrap();
179
180 let positions = (0..50)
181 .map(|i| {
182 let x = i as f64 * 0.2;
183 let y = (x * 0.3).cos() + 0.5;
184 [x, y]
185 })
186 .collect();
187 let s2 = Series::markers_only(positions, MarkerStyle::circle(6.0))
188 .with_label("cosine_markers_only")
189 .with_color([0.9, 0.3, 0.3]);
190 let s2_id = s2.id;
191 let w2 = PlotWidgetBuilder::new()
192 .with_controls(no_scroll_pan_controls())
193 .with_hover_highlight_provider(Self::hover_highlight_provider)
194 .with_pick_highlight_provider(Self::pick_highlight_provider)
195 .with_x_axis_link(x_link.clone()) // Link the x-axis
196 .with_x_tick_formatter(|_| String::new()) // Remove tick labels
197 .with_y_tick_formatter(|_| String::new())
198 .with_crosshairs(true)
199 .add_series(s2)
200 .build()
201 .unwrap();
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]

Callers

nothing calls this directly

Calls 15

unbind_scrollMethod · 0.80
mapMethod · 0.80
buildMethod · 0.80
with_crosshairsMethod · 0.80
with_x_axis_linkMethod · 0.80
with_y_limMethod · 0.80
with_x_limMethod · 0.80
with_controlsMethod · 0.80
with_y_tick_formatterMethod · 0.80
with_x_tick_formatterMethod · 0.80

Tested by

no test coverage detected