pub struct Axis<D, Theme = Theme> { /* private fields */ }Expand description
An axis that maps data values to screen coordinates.
The Axis struct is responsible for:
- Defining the scale (linear, log, etc.) for mapping data to pixels.
- Configuring visual elements like ticks, grid lines, and labels.
- Handling layout and rendering of the axis and its interactive marker.
§Example
use iced_aksel::{Axis, axis::{Position, TickResult, TickContext}, scale::Linear};
let axis = Axis::new(Linear::new(0.0, 100.0), Position::Bottom)
.with_thickness(40.0)
.with_tick_renderer(|ctx: TickContext<f64>| TickResult {
tick_line: Some(ctx.tickline()),
grid_line: Some(ctx.gridline()),
label: Some(ctx.label(format!("{:.2}", ctx.tick.value))),
..Default::default()
});Implementations§
Source§impl<D: Float, Theme> Axis<D, Theme>
impl<D: Float, Theme> Axis<D, Theme>
Sourcepub fn new(
scale: impl Scale<Domain = D, Normalized = f32> + 'static,
position: Position,
) -> Self
pub fn new( scale: impl Scale<Domain = D, Normalized = f32> + 'static, position: Position, ) -> Self
Creates a new Axis with the given scale and position.
By default, the axis will render:
- Major ticks with labels
- Minor ticks (smaller lines)
- Grid lines aligned with major ticks
Sourcepub fn with_thickness<P: Into<Pixels>>(self, thickness: P) -> Self
pub fn with_thickness<P: Into<Pixels>>(self, thickness: P) -> Self
Sets the reserved thickness of the axis in pixels.
This determines the space reserved for the axis in the chart layout. Increase this if your labels are being clipped or overlapping with the chart area.
Sourcepub fn style<F>(self, style_fn: F) -> Self
pub fn style<F>(self, style_fn: F) -> Self
Adds a function that overrides the default styling coming from chart.
If you just want to set a general style for the chart in general, see crate::Chart instead.
Sourcepub fn with_tick_renderer<F>(self, renderer: F) -> Self
pub fn with_tick_renderer<F>(self, renderer: F) -> Self
Sets a custom renderer for ticks.
This function gives you full control over which ticks render lines, grids, or labels.
§Example
iced_aksel::axis::Position::Bottom);
axis.with_tick_renderer(|ctx: TickContext<f64>| {
if ctx.tick.level == 0 {
TickResult::with_label(ctx.label(format!("{:.1}", ctx.tick.value)))
} else {
TickResult::default() // Empty tick result
}
});Sourcepub const fn without_grid(self) -> Self
pub const fn without_grid(self) -> Self
Disables grid line rendering for this axis.
Sourcepub fn skip_overlapping_labels(self, min_gap_px: f32) -> Self
pub fn skip_overlapping_labels(self, min_gap_px: f32) -> Self
Configures the axis to skip labels that would overlap.
min_gap_px specifies the minimum distance in pixels required between labels.
Sourcepub fn with_custom_label_policy<F>(self, policy: F) -> Self
pub fn with_custom_label_policy<F>(self, policy: F) -> Self
Sets a custom policy for determining which labels to render.
Useful for advanced collision detection or custom filtering logic.
Sourcepub const fn invisible(self) -> Self
pub const fn invisible(self) -> Self
Makes the axis invisible.
It will still occupy layout space (defined by thickness) but will not render
any ticks, lines, or labels. To remove it from layout entirely, set thickness to 0.
Sourcepub fn set_skip_overlapping_labels(&mut self, min_gap_px: f32)
pub fn set_skip_overlapping_labels(&mut self, min_gap_px: f32)
Configures the axis to skip labels that would overlap.
min_gap_px specifies the minimum distance in pixels required between labels.
Sourcepub fn set_tick_renderer<F>(&mut self, renderer: F)
pub fn set_tick_renderer<F>(&mut self, renderer: F)
Updates the tick renderer in-place.
Sourcepub const fn set_visibility(&mut self, visible: bool)
pub const fn set_visibility(&mut self, visible: bool)
Sets the visibility of the axis.
Sourcepub fn set_thickness<P: Into<Pixels>>(&mut self, thickness: P)
pub fn set_thickness<P: Into<Pixels>>(&mut self, thickness: P)
Updates the thickness of the axis in-place.
Sourcepub const fn is_visible(&self) -> bool
pub const fn is_visible(&self) -> bool
Returns true if the axis is currently visible.
Sourcepub fn orientation(&self) -> Orientation
pub fn orientation(&self) -> Orientation
Returns the orientation (Horizontal/Vertical) based on the position.
Trait Implementations§
Auto Trait Implementations§
impl<D, Theme = Theme> !Freeze for Axis<D, Theme>
impl<D, Theme = Theme> !RefUnwindSafe for Axis<D, Theme>
impl<D, Theme = Theme> !Send for Axis<D, Theme>
impl<D, Theme = Theme> !Sync for Axis<D, Theme>
impl<D, Theme> Unpin for Axis<D, Theme>
impl<D, Theme> UnsafeUnpin for Axis<D, Theme>
impl<D, Theme = Theme> !UnwindSafe for Axis<D, Theme>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more