Remove polyplot

This commit is contained in:
Michał Chodzikiewicz 2021-03-02 21:19:26 +01:00
parent 76c399ac6c
commit 16231f31b3
4 changed files with 0 additions and 138 deletions

View file

@ -1,50 +0,0 @@
use embedded_graphics::{
pixelcolor::BinaryColor,
prelude::*,
};
use embedded_graphics_simulator::{
SimulatorDisplay,
Window,
OutputSettingsBuilder,
BinaryColorTheme
};
use embedded_plots::{
polyplot::{PolyPlot},
curve::{PlotPoint, Curve},
};
fn main() -> Result<(), core::convert::Infallible> {
let mut display: SimulatorDisplay<BinaryColor> = SimulatorDisplay::new(Size::new(128, 48));
let data1 = vec![
PlotPoint { x: 0, y: 0 },
PlotPoint { x: 1, y: 1 },
PlotPoint { x: 2, y: 1 },
PlotPoint { x: 3, y: 0 },
];
let data2 = vec![
PlotPoint { x: 0, y: 1 },
PlotPoint { x: 1, y: 0 },
PlotPoint { x: 2, y: 3 },
PlotPoint { x: 3, y: 2 },
PlotPoint { x: 4, y: 2 },
];
let curves = vec![
(Curve::from_data(data1.as_slice()), BinaryColor::On),
(Curve::from_data(data2.as_slice()), BinaryColor::On),
];
let plot = PolyPlot::new(curves.as_slice(), Point { x: 10, y: 3 }, Point { x: 120, y: 45 });
plot.draw(&mut display)?;
let output_settings = OutputSettingsBuilder::new()
.theme(BinaryColorTheme::OledBlue)
.build();
Window::new("Basic plot", &output_settings).show_static(&display);
Ok(())
}

View file

@ -1,49 +0,0 @@
use embedded_graphics::{
pixelcolor::Rgb565,
prelude::*,
};
use embedded_graphics_simulator::{
SimulatorDisplay,
Window,
OutputSettingsBuilder,
};
use embedded_plots::{
polyplot::{PolyPlot},
curve::{PlotPoint, Curve},
};
fn main() -> Result<(), core::convert::Infallible> {
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(480, 272));
let data1 = vec![
PlotPoint { x: 0, y: 0 },
PlotPoint { x: 1, y: 1 },
PlotPoint { x: 2, y: 1 },
PlotPoint { x: 3, y: 0 },
];
let data2 = vec![
PlotPoint { x: 0, y: 1 },
PlotPoint { x: 1, y: 0 },
PlotPoint { x: 2, y: 3 },
PlotPoint { x: 3, y: 2 },
PlotPoint { x: 4, y: 2 },
];
let curves = vec![
(Curve::from_data(data1.as_slice()), RgbColor::YELLOW),
(Curve::from_data(data2.as_slice()), RgbColor::RED),
];
let plot = PolyPlot::new(curves.as_slice(), Point { x: 10, y: 10 }, Point { x: 470, y: 260 });
plot.draw(&mut display)?;
let output_settings = OutputSettingsBuilder::new()
.build();
Window::new("Basic plot", &output_settings).show_static(&display);
Ok(())
}

View file

@ -2,7 +2,6 @@
pub mod curve; pub mod curve;
pub mod axis; pub mod axis;
pub mod polyplot;
pub mod single_plot; pub mod single_plot;
mod range_conv; mod range_conv;

View file

@ -1,38 +0,0 @@
use crate::curve::Curve;
use embedded_graphics::drawable::Drawable;
use embedded_graphics::DrawTarget;
use embedded_graphics::prelude::Point;
use embedded_graphics::pixelcolor::PixelColor;
pub struct PolyPlot<'a, C>
{
curves: &'a [(Curve<'a>, C)],
top_left: Point,
bottom_right: Point,
}
impl<'a, C> PolyPlot<'a, C>
where
C: PixelColor
{
pub fn new(curves: &'a [(Curve<'a>, C)], top_left: Point, bottom_right: Point) -> PolyPlot<C> {
PolyPlot { curves, top_left, bottom_right }
}
}
impl<'a, C> Drawable<C> for PolyPlot<'a, C>
where
C: PixelColor + Default,
{
fn draw<D: DrawTarget<C>>(self, display: &mut D) -> Result<(), D::Error> {
for (curve, color) in self.curves {
curve.into_drawable_curve(
&self.top_left,
&self.bottom_right,
).set_color(*color)
.set_thickness(2)
.draw(display)?;
}
Ok(())
}
}