mod linear;
mod band;
mod time;
mod ordinal;
mod sqrt;
pub use linear::ScaleLinear;
pub use band::ScaleBand;
pub use time::ScaleTime;
pub use ordinal::ScaleOrdinal;
pub use sqrt::ScaleSqrt;
pub trait ContinuousScale {
fn map(&self, value: f64) -> f64;
fn domain(&self) -> (f64, f64);
fn range(&self) -> (f64, f64);
fn ticks(&self, count: usize) -> Vec<f64>;
fn clamp(&self, value: f64) -> f64;
}
pub(crate) fn tick_step(min: f64, max: f64, count: usize) -> f64 {
let raw_step = (max - min) / count as f64;
let magnitude = 10_f64.powf(raw_step.log10().floor());
let error = raw_step / magnitude;
if error >= 50_f64.sqrt() {
10.0 * magnitude
} else if error >= 10_f64.sqrt() {
5.0 * magnitude
} else if error >= 2_f64.sqrt() {
2.0 * magnitude
} else {
magnitude
}
}
pub(crate) fn round_to_precision(value: f64, step: f64) -> f64 {
if step == 0.0 {
return value;
}
let decimals = (-step.log10().floor()).max(0.0) as i32;
let factor = 10_f64.powi(decimals);
(value * factor).round() / factor
}