2020-12-21 00:28:22 +00:00
|
|
|
use core::ops::Range;
|
|
|
|
use embedded_graphics::prelude::*;
|
2021-01-04 21:20:07 +00:00
|
|
|
use embedded_graphics::style::{TextStyle};
|
|
|
|
|
|
|
|
use crate::drawable_axis::DrawableAxis;
|
2020-12-21 00:28:22 +00:00
|
|
|
|
2020-12-31 00:44:57 +00:00
|
|
|
pub enum Placement {
|
2020-12-21 00:28:22 +00:00
|
|
|
X {
|
|
|
|
x1: i32,
|
|
|
|
x2: i32,
|
|
|
|
y: i32,
|
|
|
|
},
|
|
|
|
Y {
|
|
|
|
y1: i32,
|
|
|
|
y2: i32,
|
|
|
|
x: i32,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-12-30 15:33:08 +00:00
|
|
|
pub enum Scale {
|
|
|
|
Fixed(usize),
|
|
|
|
RangeFraction(usize),
|
2020-12-21 00:28:22 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 21:20:07 +00:00
|
|
|
pub struct Axis<'a> {
|
2020-12-30 15:33:08 +00:00
|
|
|
title: &'a str,
|
2020-12-21 00:28:22 +00:00
|
|
|
range: Range<i32>,
|
|
|
|
scale: Scale,
|
|
|
|
}
|
|
|
|
|
2021-01-04 21:20:07 +00:00
|
|
|
impl<'a> Axis<'a>
|
2020-12-21 00:28:22 +00:00
|
|
|
{
|
2021-01-04 21:20:07 +00:00
|
|
|
pub fn new(title: &'a str, range: Range<i32>, scale: Scale) -> Axis<'a> {
|
|
|
|
Axis{title, range, scale}
|
2020-12-21 00:28:22 +00:00
|
|
|
}
|
2021-01-02 09:28:38 +00:00
|
|
|
|
2021-02-25 22:53:10 +00:00
|
|
|
pub fn into_drawable_axis<C, F>(self, placement: Placement, plot_color: C, text_style: TextStyle<C, F>, tick_height: usize, thickness: usize) -> DrawableAxis<'a, C, F>
|
2021-01-04 21:20:07 +00:00
|
|
|
where
|
|
|
|
C: PixelColor,
|
|
|
|
F: Font,
|
|
|
|
TextStyle<C, F>: Clone,
|
|
|
|
{
|
2021-02-25 22:53:10 +00:00
|
|
|
DrawableAxis::new(self.title,placement,self.range,self.scale,plot_color,text_style,tick_height,thickness)
|
2021-01-02 09:28:38 +00:00
|
|
|
}
|
2020-12-21 00:28:22 +00:00
|
|
|
}
|