MCPcopy Create free account
hub / github.com/emilk/egui_plot / paint_grid_direction

Method paint_grid_direction

egui_plot/src/plot.rs:1456–1544  ·  view source on GitHub ↗
(
        &self,
        ui: &Ui,
        shapes: &mut Vec<(Shape, f32)>,
        axis: Axis,
        items: &[Box<dyn PlotItem + '_>],
        transform: &PlotTransform,
    )

Source from the content-addressed store, hash-verified

1454 }
1455
1456 fn paint_grid_direction(
1457 &self,
1458 ui: &Ui,
1459 shapes: &mut Vec<(Shape, f32)>,
1460 axis: Axis,
1461 items: &[Box<dyn PlotItem + '_>],
1462 transform: &PlotTransform,
1463 ) {
1464 let iaxis = usize::from(axis);
1465
1466 // Where on the cross-dimension to show the label values
1467 let bounds = transform.bounds();
1468 let value_cross = 0.0_f64.clamp(bounds.min[1 - iaxis], bounds.max[1 - iaxis]);
1469
1470 let input = GridInput {
1471 bounds: (bounds.min[iaxis], bounds.max[iaxis]),
1472 base_step_size: transform.dvalue_dpos()[iaxis].abs() * self.grid_spacing.min as f64,
1473 };
1474 let steps = (self.grid_spacers[iaxis])(input);
1475
1476 let clamp_range = self.clamp_grid.then(|| {
1477 let mut tight_bounds = PlotBounds::NOTHING;
1478 for item in items {
1479 let item_bounds = item.bounds();
1480 tight_bounds.merge_x(&item_bounds);
1481 tight_bounds.merge_y(&item_bounds);
1482 }
1483 tight_bounds
1484 });
1485
1486 for step in steps {
1487 let value_main = step.value;
1488
1489 if let Some(clamp_range) = clamp_range {
1490 match axis {
1491 Axis::X => {
1492 if !clamp_range.range_x().contains(&value_main) {
1493 continue;
1494 }
1495 }
1496 Axis::Y => {
1497 if !clamp_range.range_y().contains(&value_main) {
1498 continue;
1499 }
1500 }
1501 }
1502 }
1503
1504 let value = match axis {
1505 Axis::X => PlotPoint::new(value_main, value_cross),
1506 Axis::Y => PlotPoint::new(value_cross, value_main),
1507 };
1508
1509 let pos_in_gui = transform.position_from_point(&value);
1510 let spacing_in_points = (transform.dpos_dvalue()[iaxis] * step.step_size).abs() as f32;
1511
1512 if spacing_in_points <= self.grid_spacing.min {
1513 continue; // Too close together

Callers 1

paint_gridMethod · 0.80

Calls 11

dvalue_dposMethod · 0.80
merge_xMethod · 0.80
merge_yMethod · 0.80
range_xMethod · 0.80
range_yMethod · 0.80
position_from_pointMethod · 0.80
dpos_dvalueMethod · 0.80
frameMethod · 0.80
position_from_point_yMethod · 0.80
position_from_point_xMethod · 0.80
boundsMethod · 0.45

Tested by

no test coverage detected