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
Log
Logarithmic mapping.
Fields
Band
Band scale for categorical data.
Fields
Time
Time scale (Unix milliseconds).
Sqrt
Square root mapping (emphasizes smaller values).
Power
Power mapping with configurable exponent.
Fields
Symlog
Symmetric log: handles positive, negative, and zero.
Fields
Ordinal
Ordinal: maps discrete string values to specific positions.
Implementations§
Source§impl Scale
impl Scale
Sourcepub fn map_band(&self, category: &str) -> Option<(f32, f32)>
pub fn map_band(&self, category: &str) -> Option<(f32, f32)>
Map a band category to its center position and width.
Sourcepub fn invert(&self, visual: f32) -> f64
pub fn invert(&self, visual: f32) -> f64
Invert: map from visual coordinate back to data value.
Sourcepub fn nice(&self, target_count: usize) -> Self
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.
Sourcepub fn format_tick(&self, value: f64) -> String
pub fn format_tick(&self, value: f64) -> String
Format a tick value as a label.