Skip to main content

Scale

Enum Scale 

Source
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.

Fields

§base: f64

The logarithm base (e.g. 10.0). Tick placement uses powers of this base.

Implementations§

Source§

impl Scale

Source

pub fn linear() -> Self

A linear numeric axis.

Source

pub fn time() -> Self

A time axis over epoch seconds.

Source

pub fn log() -> Self

A base-10 logarithmic axis. Use Scale::Log directly for another base.

Source

pub fn forward(&self, v: f64) -> f64

Warp a data-space value into scale space. Identity for Linear/Time; log_base for Log.

Source

pub fn inverse(&self, u: f64) -> f64

Inverse of forward: map a scale-space coordinate back to data space.

Source

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.

Source

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).

Source

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.

Source

pub fn format(&self, v: f64, context: f64) -> String

Format a single data value the way this scale’s ticks would, e.g. for a crosshair readout. context is a neighbouring span (typically the visible window width) used to choose precision; pass 0.0 to accept the default.

Trait Implementations§

Source§

impl Clone for Scale

Source§

fn clone(&self) -> Scale

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Scale

Source§

impl Debug for Scale

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Scale

Source§

fn eq(&self, other: &Scale) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.