Skip to main content

Scale

Struct Scale 

Source
pub struct Scale {
    pub kind: ScaleKind,
    pub domain_min: f64,
    pub domain_max: f64,
    pub range_min: f64,
    pub range_max: f64,
    pub categories: Vec<String>,
    pub log_base: f64,
    pub band: f64,
    pub count: usize,
}
Expand description

A mapping from data values to pixel positions.

One scale serves one axis. The scale knows the data domain (the range of values the data cover) and the pixel range (the extent of the grid along the axis), and maps between them.

Fields§

§kind: ScaleKind

The kind of the scale.

§domain_min: f64

The lower end of the data domain.

§domain_max: f64

The upper end of the data domain.

§range_min: f64

The lower end of the pixel range.

§range_max: f64

The upper end of the pixel range.

§categories: Vec<String>

The categories of an ordinal scale.

§log_base: f64

The base of a logarithmic scale.

§band: f64

The width of one band of an ordinal scale, in pixels.

A band is the space one category occupies. It is larger than the distance between two category centres by exactly one band, which is what lets a bar chart draw a bar that fills its band without spilling into the neighbouring one.

§count: usize

The number of categories of an ordinal scale.

The count is kept apart from the names because the two are not the same: a chart over a million unnamed points has a million categories and not one name.

Implementations§

Source§

impl Scale

Inherent implementation of Scale.

Source

pub fn linear( domain_min: f64, domain_max: f64, range_min: f64, range_max: f64, ) -> Self

Returns a linear scale covering the given domain and range.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn log( domain_min: f64, domain_max: f64, range_min: f64, range_max: f64, base: f64, ) -> Self

Returns a logarithmic scale covering the given domain and range.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn category( categories: Vec<String>, range_min: f64, range_max: f64, band: f64, ) -> Self

Returns an ordinal scale over the given categories.

range_min and range_max are the positions of the centres of the first and the last band, and band is the width of one band.

§Arguments
  • Vec<String> - A Vec<String> parameter.
  • f64 - A 64-bit float (f64).
Source

pub fn category_count( count: usize, range_min: f64, range_max: f64, band: f64, ) -> Self

Returns an ordinal scale over the given number of categories.

The scale has no names: it is used for a chart whose points are not named, where keeping a million empty strings would be pure waste.

§Arguments
  • usize - A non-negative integer (usize).
  • f64 - A 64-bit float (f64).
Source

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

Maps a data value to a pixel position.

Values outside the domain are clamped to the range, which is what keeps a series that overflows its axis from drawing outside the grid.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • f64 - A 64-bit float.
Source

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

Maps a pixel position back to a data value.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • f64 - A 64-bit float.
Source

pub fn band_width(&self) -> f64

Returns the width of one band of an ordinal scale, in pixels.

Returns 0.0 for a scale that is not ordinal.

§Returns
  • f64 - A 64-bit float.
Source

pub fn is_ordinal(&self) -> bool

Returns true when the scale maps ordinal values.

§Returns
  • bool - A boolean.
Source§

impl Scale

Source

pub fn get_kind(&self) -> ScaleKind

Source

pub fn get_mut_kind(&mut self) -> &mut ScaleKind

Source

pub fn set_kind(&mut self, val: ScaleKind) -> &mut Self

Source

pub fn get_domain_min(&self) -> f64

Source

pub fn get_mut_domain_min(&mut self) -> &mut f64

Source

pub fn set_domain_min(&mut self, val: f64) -> &mut Self

Source

pub fn get_domain_max(&self) -> f64

Source

pub fn get_mut_domain_max(&mut self) -> &mut f64

Source

pub fn set_domain_max(&mut self, val: f64) -> &mut Self

Source

pub fn get_range_min(&self) -> f64

Source

pub fn get_mut_range_min(&mut self) -> &mut f64

Source

pub fn set_range_min(&mut self, val: f64) -> &mut Self

Source

pub fn get_range_max(&self) -> f64

Source

pub fn get_mut_range_max(&mut self) -> &mut f64

Source

pub fn set_range_max(&mut self, val: f64) -> &mut Self

Source

pub fn get_categories(&self) -> &Vec<String>

Source

pub fn get_mut_categories(&mut self) -> &mut Vec<String>

Source

pub fn set_categories(&mut self, val: Vec<String>) -> &mut Self

Source

pub fn get_log_base(&self) -> f64

Source

pub fn get_mut_log_base(&mut self) -> &mut f64

Source

pub fn set_log_base(&mut self, val: f64) -> &mut Self

Source

pub fn get_band(&self) -> f64

Source

pub fn get_mut_band(&mut self) -> &mut f64

Source

pub fn set_band(&mut self, val: f64) -> &mut Self

Source

pub fn get_count(&self) -> usize

Source

pub fn get_mut_count(&mut self) -> &mut usize

Source

pub fn set_count(&mut self, val: usize) -> &mut Self

Trait Implementations§

Source§

impl Clone for Scale

Source§

fn clone(&self) -> Self

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

impl PartialEq for Scale

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more