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

Method update_ticks

src/plot_state.rs:386–450  ·  view source on GitHub ↗
(
        &mut self,
        x_tick_producer: Option<&TickProducer>,
        y_tick_producer: Option<&TickProducer>,
    )

Source from the content-addressed store, hash-verified

384
385 if let Some((x_min, x_max)) = self.x_lim
386 && let (Some(x_min), Some(x_max)) = (
387 self.x_axis_scale.data_to_plot(x_min),
388 self.x_axis_scale.data_to_plot(x_max),
389 )
390 {
391 min_v.x = x_min;
392 max_v.x = x_max;
393 }
394
395 self.camera.set_bounds(min_v, max_v, 0.05);
396 if update_axis_links {
397 self.update_axis_links();
398 }
399 }
400
401 /// Only scales the Y-axis according to data bounds; does not touch the X camera.
402 /// In follow mode: x is controlled by follow_x, y adapts to data.
403 pub(crate) fn autoscale_y_only(&mut self) {
404 let (Some(data_min), Some(data_max)) = (self.data_min, self.data_max) else {
405 return;
406 };
407 let y_min = if let Some((y_min, _)) = self.y_lim {
408 self.y_axis_scale.data_to_plot(y_min).unwrap_or(data_min.y)
409 } else {
410 data_min.y
411 };
412 let y_max = if let Some((_, y_max)) = self.y_lim {
413 self.y_axis_scale.data_to_plot(y_max).unwrap_or(data_max.y)
414 } else {
415 data_max.y
416 };
417 let range = (y_max - y_min).max(1e-6);
418 let padding = range * 0.05;
419 self.camera.half_extents.y = (range + padding) / 2.0;
420 self.camera.position.y = (y_min + y_max) / 2.0;
421 }
422
423 pub(crate) fn update_ticks(
424 &mut self,
425 x_tick_producer: Option<&TickProducer>,
426 y_tick_producer: Option<&TickProducer>,
427 ) {
428 // Calculate x-axis ticks
429 let min_x_plot = self.camera.position.x - self.camera.half_extents.x;
430 let max_x_plot = self.camera.position.x + self.camera.half_extents.x;
431 let min_x = self
432 .x_axis_scale
433 .plot_to_data(min_x_plot)
434 .unwrap_or(min_x_plot);
435 let max_x = self
436 .x_axis_scale
437 .plot_to_data(max_x_plot)
438 .unwrap_or(max_x_plot);
439
440 let x_tick_values = match x_tick_producer {
441 Some(producer) => producer(min_x, max_x, self.bounds.width.into()),
442 None => Vec::new(),
443 };

Callers 1

Calls 5

plot_to_dataMethod · 0.80
data_to_plotMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected