Skip to content

Commit

Permalink
label_spacing is a more clear name
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 26, 2024
1 parent c5c64ff commit e01bfdf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions crates/egui_plot/src/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct AxisHints {
pub(super) formatter: Arc<AxisFormatterFn>,
pub(super) digits: usize,
pub(super) placement: Placement,
pub(super) spacing: Rangef,
pub(super) label_spacing: Rangef,
}

// TODO: this just a guess. It might cease to work if a user changes font size.
Expand Down Expand Up @@ -111,7 +111,7 @@ impl AxisHints {
formatter: Arc::new(Self::default_formatter),
digits: 5,
placement: Placement::LeftBottom,
spacing: match axis {
label_spacing: match axis {
Axis::X => Rangef::new(60.0, 80.0), // labels can get pretty wide
Axis::Y => Rangef::new(20.0, 30.0), // text isn't very high
},
Expand Down Expand Up @@ -184,8 +184,8 @@ impl AxisHints {
///
/// Labels can never be closer together than the [`crate::Plot::grid_spacing`] setting.
#[inline]
pub fn spacing(mut self, range: impl Into<Rangef>) -> Self {
self.spacing = range.into();
pub fn label_spacing(mut self, range: impl Into<Rangef>) -> Self {
self.label_spacing = range.into();
self
}

Expand Down Expand Up @@ -292,21 +292,21 @@ impl AxisWidget {
return response;
};

let spacing_range = self.hints.spacing;
let label_spacing = self.hints.label_spacing;

for step in self.steps.iter() {
let text = (self.hints.formatter)(*step, self.hints.digits, &self.range);
if !text.is_empty() {
let spacing_in_points =
(transform.dpos_dvalue()[usize::from(axis)] * step.step_size).abs() as f32;

if spacing_in_points <= spacing_range.min {
if spacing_in_points <= label_spacing.min {
// Labels are too close together - don't paint them.
continue;
}

// Fade in labels as they get further apart:
let strength = remap_clamp(spacing_in_points, spacing_range, 0.0..=1.0);
let strength = remap_clamp(spacing_in_points, label_spacing, 0.0..=1.0);

let text_color = super::color_from_strength(ui, strength);
let galley = ui
Expand Down

0 comments on commit e01bfdf

Please sign in to comment.