| 1 | mod band; |
| 2 | mod linear; |
| 3 | mod ordinal; |
| 4 | mod point; |
| 5 | mod sealed; |
| 6 | |
| 7 | pub use band::ScaleBand; |
| 8 | pub use linear::ScaleLinear; |
| 9 | pub use ordinal::ScaleOrdinal; |
| 10 | pub use point::ScalePoint; |
| 11 | |
| 12 | use num_traits::{Num, ToPrimitive}; |
| 13 | |
| 14 | /// A number a [`ScaleLinear`] and the charts built on it can place: `f32`, |
| 15 | /// `f64`, and `rust_decimal::Decimal` with the `decimal` feature. |
| 16 | /// |
| 17 | /// Sealed: integer types are left out on purpose, because a linear scale |
| 18 | /// divides values and integer division would truncate every position. |
| 19 | pub trait PlotValue: sealed::Sealed + Copy + PartialOrd + Num + ToPrimitive + 'static {} |
| 20 | |
| 21 | impl PlotValue for f32 {} |
| 22 | impl PlotValue for f64 {} |
| 23 | #[cfg(feature = "decimal")] |
| 24 | impl PlotValue for rust_decimal::Decimal {} |
| 25 | |
| 26 | pub trait Scale<T> { |
| 27 | /// Get the tick of the scale. |
| 28 | fn tick(&self, value: &T) -> Option<f32>; |
| 29 | |
| 30 | /// The index of the domain value whose position is nearest `tick`; `0` for |
| 31 | /// an empty domain or a scale without discrete positions. |
| 32 | fn nearest_index(&self, _tick: f32) -> usize { |
| 33 | 0 |
| 34 | } |
| 35 | } |