mod gen;
pub use gen::{
AlignedFloats, Format as TickFormat, GeneratedTicks, Generator as TickGen, HorizontalSpan,
Period, TickFormatFn, Timestamps, VerticalSpan,
};
use chrono::prelude::*;
mod private {
pub trait Sealed {}
}
pub trait Tick: Clone + PartialEq + PartialOrd + Send + Sync + 'static + private::Sealed {
fn tick_label_generator() -> impl TickGen<Tick = Self>;
fn tooltip_generator() -> impl TickGen<Tick = Self> {
Self::tick_label_generator()
}
fn position(&self) -> f64;
}
impl private::Sealed for f64 {}
impl<Tz: TimeZone> private::Sealed for DateTime<Tz> {}
impl Tick for f64 {
fn tick_label_generator() -> impl TickGen<Tick = Self> {
AlignedFloats::default()
}
fn position(&self) -> f64 {
*self
}
}
impl<Tz> Tick for DateTime<Tz>
where
Tz: TimeZone + Send + Sync + 'static,
Tz::Offset: std::fmt::Display + Send + Sync,
{
fn tick_label_generator() -> impl TickGen<Tick = Self> {
Timestamps::default()
}
fn tooltip_generator() -> impl TickGen<Tick = Self> {
Timestamps::default().with_long_format()
}
fn position(&self) -> f64 {
self.timestamp() as f64 + (self.timestamp_subsec_nanos() as f64 / 1e9)
}
}