Use axis in single plot

This commit is contained in:
Michał Chodzikiewicz 2021-01-02 10:28:38 +01:00
parent 098f89d908
commit dc2edc77f3
3 changed files with 18 additions and 1 deletions

View file

@ -26,7 +26,7 @@ fn main() -> Result<(), core::convert::Infallible> {
]; ];
let curve = Curve::from_data(data.as_slice()); let curve = Curve::from_data(data.as_slice());
let plot = SinglePlot::new(&curve, RgbColor::YELLOW, Point { x: 10, y: 10 }, Point { x: 470, y: 260 }); let plot = SinglePlot::new(&curve, RgbColor::YELLOW, Point { x: 50, y: 10 }, Point { x: 430, y: 250 });
plot.draw(&mut display)?; plot.draw(&mut display)?;
let output_settings = OutputSettingsBuilder::new() let output_settings = OutputSettingsBuilder::new()

View file

@ -51,6 +51,10 @@ impl<'a, C, F> Axis<'a, C, F>
pub fn new(title: &'a str, orientation: Placement, range: Range<i32>, scale: Scale, color: C, text_style: TextStyle<C,F>, tick_height: usize) -> Axis<'a, C, F> { pub fn new(title: &'a str, orientation: Placement, range: Range<i32>, scale: Scale, color: C, text_style: TextStyle<C,F>, tick_height: usize) -> Axis<'a, C, F> {
Axis { title, placement: orientation, range, scale, color, text_style, tick_size: tick_height } Axis { title, placement: orientation, range, scale, color, text_style, tick_size: tick_height }
} }
pub fn size(&self) -> Point {
Point{x: 50, y: 50}
}
} }

View file

@ -3,6 +3,9 @@ use embedded_graphics::drawable::Drawable;
use embedded_graphics::DrawTarget; use embedded_graphics::DrawTarget;
use embedded_graphics::prelude::Point; use embedded_graphics::prelude::Point;
use embedded_graphics::pixelcolor::PixelColor; use embedded_graphics::pixelcolor::PixelColor;
use crate::axis::{Scale, Placement, Axis};
use embedded_graphics::style::TextStyleBuilder;
use embedded_graphics::fonts::Font6x8;
pub struct SinglePlot<'a, C> pub struct SinglePlot<'a, C>
where where
@ -29,6 +32,16 @@ impl<'a, C> Drawable<C> for SinglePlot<'a, C>
{ {
fn draw<D: DrawTarget<C>>(self, display: &mut D) -> Result<(), D::Error> { fn draw<D: DrawTarget<C>>(self, display: &mut D) -> Result<(), D::Error> {
let text_style = TextStyleBuilder::new(Font6x8)
.text_color(self.color)
.build();
Axis::new("X", Placement::X{x1: self.top_left.x, x2: self.bottom_right.x, y: self.bottom_right.y}, 0..100, Scale::Fixed(10), self.color, text_style, 2)
.draw(display)?;
Axis::new("Y", Placement::Y{y1: self.top_left.y, y2: self.bottom_right.y, x: self.top_left.x}, 0..200, Scale::Fixed(10), self.color, text_style, 1)
.draw(display)?;
self.curve.into_drawable_curve( self.curve.into_drawable_curve(
&self.top_left, &self.top_left,
&self.bottom_right, &self.bottom_right,