poloto/plotnum/
mod.rs

1//!
2//! Contains the [`PlotNum`] trait and their supporting structs.
3//!
4
5/// A disconnectable number. A number that can me marked as a hole to signify that there is a disconnect in plots.
6/// See [`crate::build::crop::Croppable`]
7///
8pub trait DiscNum {
9    /// Create a hole value.
10    fn hole() -> Self;
11}
12
13pub trait AsPlotnum {
14    type Target: PlotNum;
15    fn as_plotnum(&self) -> &Self::Target;
16}
17impl<P: PlotNum> AsPlotnum for P {
18    type Target = P;
19    fn as_plotnum(&self) -> &Self::Target {
20        self
21    }
22}
23
24///
25/// A plottable number. In order to be able to plot a number, we need information on how
26/// to display it as well as the interval ticks.
27///
28pub trait PlotNum: PartialOrd + Copy + std::fmt::Debug {
29    /// Is this a hole value to inject discontinuty?
30    fn is_hole(&self) -> bool;
31
32    fn scale(&self, range: &[Self; 2], max: f64) -> f64;
33
34    fn unit_range(offset: Option<Self>) -> [Self; 2];
35}
36
37pub trait HasDefaultTicks: Sized {
38    type DefaultTicks: crate::ticks::TickDistGen<Self>;
39    fn default_ticks() -> Self::DefaultTicks;
40}
41
42use std::fmt;
43
44///
45/// Group methods to write title/xname/yname
46///
47pub trait BaseFmt {
48    fn write_title(&self, writer: &mut dyn fmt::Write) -> fmt::Result;
49    fn write_xname(&self, writer: &mut dyn fmt::Write) -> fmt::Result;
50    fn write_yname(&self, writer: &mut dyn fmt::Write) -> fmt::Result;
51}
52
53///
54/// Signify if a number has a zero value.
55///
56pub trait HasZero {
57    fn zero() -> Self;
58}