1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::cmp::PartialEq;

pub mod band;
pub mod linear;

/// ScaleKind represents supported scales.
#[derive(Debug, PartialEq)]
pub enum ScaleKind {
    Band,
    Linear,
}

/// Scale represents an axis scale that is used in views and chart.
pub trait Scale<T> {
    /// Scale the provided domain value for a scale range.
    fn scale(&self, domain: &T) -> f32;

    /// Get the list of ticks that represent the scale on an axis.
    fn ticks(&self) -> Vec<T>;

    /// Get the scale kind.
    fn kind(&self) -> ScaleKind;

    /// Get the scale bandwidth.
    fn bandwidth(&self) -> f32;

    /// Check if scale range is reversed.
    fn is_range_reversed(&self) -> bool;

    /// Get the offset for each tick.
    fn tick_offset(&self) -> f32;
}