embedded_plots/
lib.rs

1//!# Embedded Plots
2//! Heapless plotting library for small embedded targets, based on [embedded-graphics](https://crates.io/crates/embedded-graphics)
3//! crate.
4//!
5//! Thanks to basing it on `embedded-graphics` crate the library is very portable out of the box.
6//! It is not dependent on any hardware target.
7//! To throw it into your project, you only need to have a display that implements `DrawTarget` trait.
8//! For more details see [DrawTarget](https://docs.rs/embedded-graphics/latest/embedded_graphics/prelude/trait.DrawTarget.html) docs.
9//!
10//! Bonus feature of `embedded-graphics` is the simulator.
11//! You can use it to develop your plots without your target hardware, easily create documentation and so on.
12//!
13//! Library utilizes builder pattern and type states - it allows easy separation of the data and decoration in the target application.
14//!
15//! ## Examples
16//! ### Single plot
17//! Simple plot example
18//! #### On color display:
19//! ![single plot on color display](https://gitlab.com/mchodzikiewicz/embedded-plots/-/raw/master/single-plot-color.png "Color plot of single curve")
20//! #### On monochromatic display:
21//! ![single plot on monochromatic display](https://gitlab.com/mchodzikiewicz/embedded-plots/-/raw/master/single-plot-mono.png "Monochromatic plot of single curve")
22//!
23//! Code to render:
24//! ```rust
25//! use embedded_plots::curve::{Curve, PlotPoint};
26//! use embedded_plots::single_plot::SinglePlot;
27//! use embedded_plots::axis::Scale;
28//! use embedded_graphics::geometry::{Point, Size};
29//! use embedded_graphics::pixelcolor::{RgbColor, Rgb565};
30//! use embedded_graphics::Drawable;
31//!
32//! //simulator dependencies, aka screen driver
33//! use embedded_graphics_simulator::SimulatorDisplay;
34//!
35//! let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(480, 272));
36//! let data = vec![
37//!         PlotPoint { x: 0, y: 0 },
38//!         PlotPoint { x: 1, y: 2 },
39//!         PlotPoint { x: 2, y: 2 },
40//!         PlotPoint { x: 3, y: 0 },
41//!     ];
42//! let curve = Curve::from_data(data.as_slice());
43//!
44//! let plot = SinglePlot::new(
45//!     &curve,
46//!     Scale::RangeFraction(3),
47//!     Scale::RangeFraction(2))
48//! .into_drawable(
49//!     Point { x: 50, y: 10 },
50//!     Point { x: 430, y: 250 })
51//! .set_color(RgbColor::YELLOW)
52//! .set_text_color(RgbColor::WHITE);
53//!
54//! plot.draw(&mut display).unwrap();
55//! ```
56//!
57//! ### Axis
58//! You can also use axis on its own, it looks like this:
59//! ![free axis examples](https://gitlab.com/mchodzikiewicz/embedded-plots/-/raw/master/doc-resources/free-axis-example.png "Free axis example")
60//! Code to render example axis:
61//! ```rust
62//! use embedded_plots::axis::{Axis, Scale, Placement};
63//! use embedded_graphics::pixelcolor::{RgbColor, Rgb565};
64//! use embedded_graphics::Drawable;
65//! use embedded_graphics::geometry::Size;
66//!
67//! //simulator dependencies, aka screen driver
68//! use embedded_graphics_simulator::SimulatorDisplay;
69//! use embedded_graphics::mono_font::MonoTextStyleBuilder;
70//! use embedded_graphics::mono_font::ascii::FONT_5X8;
71//!
72//! let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(480, 272));
73//!
74//! let text_style_white = MonoTextStyleBuilder::new()
75//!     .font(&FONT_5X8)
76//!     .text_color(RgbColor::WHITE)
77//!     .build();
78//! Axis::new(0..100)
79//!     .set_title("Title")
80//!     .set_scale(Scale::Fixed(10))
81//!     .into_drawable_axis(Placement::X { x1: 40, x2: 230, y: 10 })
82//!     .set_text_style(text_style_white)
83//!     .set_color(RgbColor::WHITE)
84//!     .draw(&mut display).unwrap();
85//! ```
86//! For more details, see `free_axis` example
87//!
88//! ## Current limitations and future plans
89//! This is very beginning of the development, however it is functional to the point where single plot can be drawn.
90//!
91//! Main issue for now is that you need to predict on how much space will be occupied by axis ticks,
92//! numbers and titles, points passed to `.into_drawable()` are the boundaries for which curve is scaled.
93//! This will be fixed, please be prepared for it since it might be a breaking change for you.
94//!
95//! #### Main features planned soon:
96//! * Drawing multiple curves that share the same X and Y domains on a single plot (take curves slice instead of single curve)
97//! * Dual plot - drawing curves that have two separate domains (either only on one axis or both).
98//!   Axis on both sides, left and right (or top and bottom) will be drawn with color corresponding to plot
99//! * Support for floating point domains
100//! * Support for fixed point curve data with intermediate floating point scales (to avoid floating point calculations for each drawn point)
101//!
102//! #### Features I'd love to see in the future:
103//! * Partial redrawing - possibility to substitute data and detect which parts of the screen needs to be redrawed
104//! * Oscilloscope style live mode (adding new points without any redrawing, no data retention)
105//! * Cursors - manual and math based (max,min,avg and so on...)
106//!
107//! ## Contributions
108//! Contributions are more than welcome, if you have particular improvement, raise an issue or submit merge request on project's Gitlab page.
109//!
110//! If you just want to help but don't have anything specific in mind, please take a look at [issue tracker](https://gitlab.com/mchodzikiewicz/embedded-plots/-/issues) and pick one.
111
112#![no_std]
113pub mod axis;
114pub mod curve;
115/// plot that draws single data series
116pub mod single_plot;
117
118mod range_conv;