box-plotters 0.1.0

An alternative to the Boxplot and Quartiles types found in plotters
Documentation
use std::marker::PhantomData;

use plotters_backend::BackendCoord;

/// Trait implemented by box plot orientations ([Vertical] and [Horizontal])
pub trait Orientation<K, V> {
    type XType;
    type YType;

    fn make_coord(key: K, val: V) -> (Self::XType, Self::YType);
    fn with_offset(coord: BackendCoord, offset: i32) -> BackendCoord;
}

/// Represents a vertical orientation.
pub struct Vertical<K, V>(PhantomData<(K, V)>);
/// Represents a horizontal orientation.
pub struct Horizontal<K, V>(PhantomData<(K, V)>);

impl<K, V> Orientation<K, V> for Vertical<K, V> {
    type XType = K;
    type YType = V;

    fn make_coord(key: K, val: V) -> (K, V) {
        (key, val)
    }

    fn with_offset(coord: BackendCoord, offset: i32) -> BackendCoord {
        (coord.0 + offset, coord.1)
    }
}

impl<K, V> Orientation<K, V> for Horizontal<K, V> {
    type XType = V;
    type YType = K;

    fn make_coord(key: K, val: V) -> (V, K) {
        (val, key)
    }

    fn with_offset(coord: BackendCoord, offset: i32) -> BackendCoord {
        (coord.0, coord.1 + offset)
    }
}