pub mod builder;
pub mod linear;
pub mod range;
pub mod scale;
pub mod style;
pub mod ticks;
pub mod traits;
pub use builder::presets;
pub use builder::*;
pub use linear::*;
pub use range::*;
pub use scale::*;
pub use style::*;
pub use ticks::*;
pub use traits::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AxisOrientation {
Horizontal,
Vertical,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AxisPosition {
Bottom,
Top,
Left,
Right,
}
#[derive(Debug, Clone)]
pub struct AxisConfig<T> {
pub min: T,
pub max: T,
pub orientation: AxisOrientation,
pub position: AxisPosition,
pub show_line: bool,
pub show_ticks: bool,
pub show_labels: bool,
pub show_grid: bool,
}
impl<T> AxisConfig<T>
where
T: Copy + PartialOrd,
{
pub fn new(min: T, max: T, orientation: AxisOrientation, position: AxisPosition) -> Self {
Self {
min,
max,
orientation,
position,
show_line: true,
show_ticks: true,
show_labels: true,
show_grid: false,
}
}
pub fn range(&self) -> (T, T) {
(self.min, self.max)
}
pub fn is_horizontal(&self) -> bool {
self.orientation == AxisOrientation::Horizontal
}
pub fn is_vertical(&self) -> bool {
self.orientation == AxisOrientation::Vertical
}
}
impl<T> Default for AxisConfig<T>
where
T: Default + Copy + PartialOrd,
{
fn default() -> Self {
Self {
min: T::default(),
max: T::default(),
orientation: AxisOrientation::Horizontal,
position: AxisPosition::Bottom,
show_line: true,
show_ticks: true,
show_labels: true,
show_grid: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_axis_config_creation() {
let config = AxisConfig::new(0.0, 10.0, AxisOrientation::Horizontal, AxisPosition::Bottom);
assert_eq!(config.min, 0.0);
assert_eq!(config.max, 10.0);
assert!(config.is_horizontal());
assert!(!config.is_vertical());
}
#[test]
fn test_axis_config_range() {
let config = AxisConfig::new(5, 15, AxisOrientation::Vertical, AxisPosition::Left);
assert_eq!(config.range(), (5, 15));
}
}