pub enum Scale {
Linear,
Time,
Log {
base: f64,
},
}Expand description
A continuous, invertible map from an axis’s data space to scale space, with tick generation and default value formatting.
Construct with Scale::linear, Scale::time, or Scale::log and
hand it to a plot axis (plot(...).x(Scale::time())). The visible domain
is not carried here — it lives in the plot’s PlotView
state, the same way a CSS transform is separate from the element it
applies to. A Scale is just the warp + tick policy.
Variants§
Linear
A linear (identity-warp) numeric axis. Ticks are “nice” numbers (multiples of 1/2/5 × 10ⁿ).
Time
A time axis. Data is epoch seconds (f64, so millisecond
precision survives even for present-day timestamps — see the plan’s
decision 7). The warp is the identity (time is linear in seconds);
ticks land on natural calendar/clock boundaries and format as clock
time or dates.
Log
A logarithmic axis. The warp is log(value), so panning and zooming
stay affine in scale space. The domain must stay strictly positive;
non-positive values are clamped to a tiny epsilon by the warp.
Implementations§
Source§impl Scale
impl Scale
Sourcepub fn log() -> Self
pub fn log() -> Self
A base-10 logarithmic axis. Use Scale::Log directly for another
base.
Sourcepub fn inverse(&self, u: f64) -> f64
pub fn inverse(&self, u: f64) -> f64
Inverse of forward: map a scale-space coordinate
back to data space.
Sourcepub fn map(&self, v: f64, origin: f64) -> f32
pub fn map(&self, v: f64, origin: f64) -> f32
Map a data value to a GPU-ready scale-space coordinate measured
relative to origin (a data-space reference subtracted before
the cast to f32). Subtracting a per-axis origin is what keeps large
absolute coordinates — epoch timestamps especially — inside f32’s
~7 significant digits on the GPU (the plan’s decision 7). Pass the
same origin to invert.
Sourcepub fn invert(&self, s: f32, origin: f64) -> f64
pub fn invert(&self, s: f32, origin: f64) -> f64
Inverse of map: recover the data value from an
origin-relative scale-space coordinate (e.g. for a crosshair
readout).
Sourcepub fn ticks(&self, window: (f64, f64), target: usize) -> Vec<Tick>
pub fn ticks(&self, window: (f64, f64), target: usize) -> Vec<Tick>
Generate axis ticks across the visible data window (lo, hi),
aiming for about target of them. Returns ticks in ascending data
order, each with its data value and a default label. lo/hi are in
data space; an empty or inverted window yields no ticks.
Trait Implementations§
impl Copy for Scale
impl StructuralPartialEq for Scale
Auto Trait Implementations§
impl Freeze for Scale
impl RefUnwindSafe for Scale
impl Send for Scale
impl Sync for Scale
impl Unpin for Scale
impl UnsafeUnpin for Scale
impl UnwindSafe for Scale
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.