Skip to main content

Scale

Enum Scale 

Source
pub enum Scale {
    Linear {
        domain: (f64, f64),
        range: (f32, f32),
    },
    Log {
        domain: (f64, f64),
        range: (f32, f32),
        base: f64,
    },
    Band {
        domain: Vec<String>,
        range: (f32, f32),
        padding: f32,
    },
    Time {
        domain: (i64, i64),
        range: (f32, f32),
    },
    Sqrt {
        domain: (f64, f64),
        range: (f32, f32),
    },
    Power {
        domain: (f64, f64),
        range: (f32, f32),
        exponent: f64,
    },
    Symlog {
        domain: (f64, f64),
        range: (f32, f32),
        constant: f64,
    },
    Ordinal {
        domain: Vec<String>,
        range: Vec<f32>,
    },
}
Expand description

A scale maps data values to visual coordinates.

Data stays f64 (scientific precision) until mapped through a Scale to f32 visual coordinates.

Variants§

§

Linear

Linear mapping.

Fields

§domain: (f64, f64)

Data domain (min, max).

§range: (f32, f32)

Visual range (min, max) in pixels.

§

Log

Logarithmic mapping.

Fields

§domain: (f64, f64)

Data domain (min, max) — must be positive.

§range: (f32, f32)

Visual range (min, max).

§base: f64

Log base (typically 10 or e).

§

Band

Band scale for categorical data.

Fields

§domain: Vec<String>

Category labels.

§range: (f32, f32)

Visual range.

§padding: f32

Padding between bands as fraction [0, 1).

§

Time

Time scale (Unix milliseconds).

Fields

§domain: (i64, i64)

Domain as Unix ms (start, end).

§range: (f32, f32)

Visual range.

§

Sqrt

Square root mapping (emphasizes smaller values).

Fields

§domain: (f64, f64)

Data domain (min, max).

§range: (f32, f32)

Visual range.

§

Power

Power mapping with configurable exponent.

Fields

§domain: (f64, f64)

Data domain (min, max).

§range: (f32, f32)

Visual range.

§exponent: f64

Exponent (1 = linear, 2 = quadratic, 0.5 = sqrt).

§

Symlog

Symmetric log: handles positive, negative, and zero.

Fields

§domain: (f64, f64)

Data domain (min, max).

§range: (f32, f32)

Visual range.

§constant: f64

Linearity threshold constant.

§

Ordinal

Ordinal: maps discrete string values to specific positions.

Fields

§domain: Vec<String>

Ordered labels.

§range: Vec<f32>

Corresponding pixel positions.

Implementations§

Source§

impl Scale

Source

pub fn map(&self, value: f64) -> f32

Map a continuous data value to a visual coordinate.

Source

pub fn map_band(&self, category: &str) -> Option<(f32, f32)>

Map a band category to its center position and width.

Source

pub fn invert(&self, visual: f32) -> f64

Invert: map from visual coordinate back to data value.

Source

pub fn ticks(&self, target_count: usize) -> Vec<f64>

Generate nice tick positions.

Source

pub fn nice(&self, target_count: usize) -> Self

Extend the domain to nice round boundaries so ticks align with domain edges.

For Linear scales, this expands the domain outward to the nearest nice tick boundaries using D3-style tick step computation. After nicing, ticks() will never produce values outside the domain.

Source

pub fn format_tick(&self, value: f64) -> String

Format a tick value as a label.

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 Debug for Scale

Source§

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

Formats the value using the given formatter. Read more

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