Skip to main content

ScaleLinear

Struct ScaleLinear 

Source
pub struct ScaleLinear { /* private fields */ }
Expand description

Maps a continuous domain to a continuous range via linear interpolation. Equivalent to D3’s scaleLinear().

Implementations§

Source§

impl ScaleLinear

Source

pub fn new(domain: (f64, f64), range: (f64, f64)) -> Self

Create a new linear scale with the given domain and range.

Source

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

Map a domain value to a range value using linear interpolation.

Source

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

Inverse mapping: range value back to domain value.

Source

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

Generate approximately count nice tick values using the D3 “nice numbers” algorithm. Ticks are returned in the same order as the domain (descending if domain is reversed).

Source

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

Extend the domain to nice round numbers (like D3’s .nice()). Uses D3’s iterative algorithm (up to 10 passes) so the domain expands until the tick step stabilises — matching d3-scale’s linearish.nice(). Preserves domain direction (reversed domains stay reversed).

Source

pub fn domain(&self) -> (f64, f64)

Get the domain extent.

Source

pub fn range(&self) -> (f64, f64)

Get the range extent.

Trait Implementations§

Source§

impl ContinuousScale for ScaleLinear

Source§

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

Map a domain value to a range value.
Source§

fn domain(&self) -> (f64, f64)

Get the domain extent as (min, max).
Source§

fn range(&self) -> (f64, f64)

Get the range extent as (min, max).
Source§

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

Generate approximately count nice tick values within the domain.
Source§

fn clamp(&self, value: f64) -> f64

Clamp a value to domain bounds.

Auto Trait Implementations§

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

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,