Skip to content

Commit

Permalink
Better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 26, 2024
1 parent 367bad8 commit 82467f1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 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) distance_fade_range: Rangef,
pub(super) 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,
distance_fade_range: match axis {
spacing: match axis {
Axis::X => Rangef::new(50.0, 100.0), // labels can get pretty wide
Axis::Y => Rangef::new(20.0, 30.0), // text isn't very high
},
Expand Down Expand Up @@ -177,13 +177,15 @@ impl AxisHints {
self
}

/// Fade in labels over this distance range.
/// Set the minimum spacing between labels
///
/// When labels get closer together than this min, then they become invisible.
/// When labels get closer together than the given minimum, then they become invisible.
/// When they get further apart than the max, they are at full opacity.
///
/// Labels can never be closer together than the [`Plot::grid_spacing`] setting.
#[inline]
pub fn distance_fade_range(mut self, range: impl Into<Rangef>) -> Self {
self.distance_fade_range = range.into();
pub fn spacing(mut self, range: impl Into<Rangef>) -> Self {
self.spacing = range.into();
self
}

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

let distance_fade_range = self.hints.distance_fade_range;
let spacing_range = self.hints.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 <= distance_fade_range.min {
if spacing_in_points <= spacing_range.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, distance_fade_range, 0.0..=1.0);
let strength = remap_clamp(spacing_in_points, spacing_range, 0.0..=1.0);

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

0 comments on commit 82467f1

Please sign in to comment.