From d63b7b3353dd77166fc60476bc33dc483d3b5ee5 Mon Sep 17 00:00:00 2001 From: uandere Date: Fri, 15 Sep 2023 23:32:35 +0300 Subject: [PATCH 1/8] Made no-std lib --- Cargo.toml | 3 +++ src/lib.rs | 19 +++++++++++++++---- src/scale.rs | 2 +- src/utils.rs | 5 +++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e28cdc5..3a0b855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,13 @@ required-features = ["tool"] travis-ci = { repository = "loony-bean/textplots-rs", branch = "master" } [features] +default = ["std"] tool = [ "meval", "structopt", ] +std = [] +alloc = [] [dependencies] drawille = "0.3.0" diff --git a/src/lib.rs b/src/lib.rs index 8047f21..a96fffb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,11 @@ //! //! +// Marking lib.rs as no_std +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + pub mod scale; pub mod utils; @@ -56,10 +61,14 @@ use drawille::Canvas as BrailleCanvas; use drawille::PixelColor; use rgb::RGB8; use scale::Scale; -use std::cmp; -use std::default::Default; -use std::f32; -use std::fmt::{Display, Formatter, Result}; +use core::cmp; +use core::f32; +use core::default::Default; +use core::fmt::{Display, Formatter, Result}; +use alloc::vec::Vec; +use alloc::{format, string::String}; +use alloc::boxed::Box; +use alloc::borrow::ToOwned; /// How the chart will do the ranging on axes #[derive(PartialEq)] @@ -345,6 +354,7 @@ impl<'a> Chart<'a> { } /// Prints canvas content. + #[cfg(feature = "std")] pub fn display(&mut self) { self.axis(); self.figures(); @@ -353,6 +363,7 @@ impl<'a> Chart<'a> { } /// Prints canvas content with some additional visual elements (like borders). + #[cfg(feature = "std")] pub fn nice(&mut self) { self.borders(); self.display(); diff --git a/src/scale.rs b/src/scale.rs index ea42273..95f80de 100644 --- a/src/scale.rs +++ b/src/scale.rs @@ -1,6 +1,6 @@ //! Transformations between domain and range. -use std::ops::Range; +use core::ops::Range; /// Holds mapping between domain and range of the function. pub struct Scale { diff --git a/src/utils.rs b/src/utils.rs index 9f8cb46..baaa10a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,6 +10,11 @@ /// # use textplots::utils::histogram; /// assert_eq!(vec![(0.0, 1.0), (5.0, 1.0)], histogram( &[ (0.0, 0.0), (9.0, 9.0), (10.0, 10.0) ], 0.0, 10.0, 2 )); /// ``` + +use alloc::vec::Vec; +use alloc::vec; + + pub fn histogram(data: &[(f32, f32)], min: f32, max: f32, bins: usize) -> Vec<(f32, f32)> { let mut output = vec![0; bins]; From fb73bfd0af412168164a6ff559bd488f64b75b6f Mon Sep 17 00:00:00 2001 From: uandere Date: Sat, 16 Sep 2023 00:45:08 +0300 Subject: [PATCH 2/8] fixed formatting --- src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a96fffb..4bd71f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,18 +57,18 @@ extern crate alloc; pub mod scale; pub mod utils; +use alloc::borrow::ToOwned; +use alloc::boxed::Box; +use alloc::vec::Vec; +use alloc::{format, string::String}; +use core::cmp; +use core::default::Default; +use core::f32; +use core::fmt::{Display, Formatter, Result}; use drawille::Canvas as BrailleCanvas; use drawille::PixelColor; use rgb::RGB8; use scale::Scale; -use core::cmp; -use core::f32; -use core::default::Default; -use core::fmt::{Display, Formatter, Result}; -use alloc::vec::Vec; -use alloc::{format, string::String}; -use alloc::boxed::Box; -use alloc::borrow::ToOwned; /// How the chart will do the ranging on axes #[derive(PartialEq)] From cd15407f14bc5d994e8adb8c1f15e18611a3812d Mon Sep 17 00:00:00 2001 From: uandere Date: Sat, 16 Sep 2023 00:52:24 +0300 Subject: [PATCH 3/8] fixed formatting --- src/utils.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index baaa10a..371e293 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,6 +2,7 @@ //! //! Merely a bunch of functions hanging around while the library API is taking shape. +use alloc::vec; /// Transforms points into frequency distribution (for using in histograms). /// Values outside of [`min`, `max`] interval are ignored, and everything that /// falls into the specified interval is grouped into `bins` number of buckets of equal width. @@ -10,10 +11,7 @@ /// # use textplots::utils::histogram; /// assert_eq!(vec![(0.0, 1.0), (5.0, 1.0)], histogram( &[ (0.0, 0.0), (9.0, 9.0), (10.0, 10.0) ], 0.0, 10.0, 2 )); /// ``` - use alloc::vec::Vec; -use alloc::vec; - pub fn histogram(data: &[(f32, f32)], min: f32, max: f32, bins: usize) -> Vec<(f32, f32)> { let mut output = vec![0; bins]; From b48adab1b559248eb8fb3bb09c198a913ff02db6 Mon Sep 17 00:00:00 2001 From: uandere Date: Thu, 5 Oct 2023 22:03:29 +0300 Subject: [PATCH 4/8] Update Cargo.toml with new feature structure --- Cargo.toml | 17 ++++++++++++----- src/lib.rs | 21 ++++++--------------- src/utils.rs | 4 ++-- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a0b855..0ff7159 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,21 +24,28 @@ travis-ci = { repository = "loony-bean/textplots-rs", branch = "master" } [features] default = ["std"] + tool = [ "meval", "structopt", ] -std = [] -alloc = [] + +std = [ + "drawille", + "rgb" +] [dependencies] -drawille = "0.3.0" +# THESE CRATES ARE ENABLED BY DEFAULT +drawille-nostd = "0.1.2" +# THESE CRATES ARE ENABLED ONLY BY THE CORRESPONDING FEATURES +drawille = { version = "0.3.0" , optional = true} structopt = { version = "0.3", optional = true } meval = { version = "0.2", optional = true } -rgb = "0.8.27" +rgb = { version = "0.8.27", optional = true } + [dev-dependencies] ctrlc = "3" console = "0.15.7" chrono = "0.4.30" - diff --git a/src/lib.rs b/src/lib.rs index 4bd71f0..3e8f945 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,27 +49,20 @@ //! //! -// Marking lib.rs as no_std -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; - pub mod scale; pub mod utils; -use alloc::borrow::ToOwned; -use alloc::boxed::Box; -use alloc::vec::Vec; -use alloc::{format, string::String}; -use core::cmp; -use core::default::Default; -use core::f32; -use core::fmt::{Display, Formatter, Result}; use drawille::Canvas as BrailleCanvas; use drawille::PixelColor; use rgb::RGB8; use scale::Scale; +use std::cmp; +use std::default::Default; +use std::f32; + +use std::fmt::{Display, Formatter, Result}; + /// How the chart will do the ranging on axes #[derive(PartialEq)] enum ChartRangeMethod { @@ -354,7 +347,6 @@ impl<'a> Chart<'a> { } /// Prints canvas content. - #[cfg(feature = "std")] pub fn display(&mut self) { self.axis(); self.figures(); @@ -363,7 +355,6 @@ impl<'a> Chart<'a> { } /// Prints canvas content with some additional visual elements (like borders). - #[cfg(feature = "std")] pub fn nice(&mut self) { self.borders(); self.display(); diff --git a/src/utils.rs b/src/utils.rs index 371e293..1306711 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ //! //! Merely a bunch of functions hanging around while the library API is taking shape. -use alloc::vec; + /// Transforms points into frequency distribution (for using in histograms). /// Values outside of [`min`, `max`] interval are ignored, and everything that /// falls into the specified interval is grouped into `bins` number of buckets of equal width. @@ -11,7 +11,7 @@ use alloc::vec; /// # use textplots::utils::histogram; /// assert_eq!(vec![(0.0, 1.0), (5.0, 1.0)], histogram( &[ (0.0, 0.0), (9.0, 9.0), (10.0, 10.0) ], 0.0, 10.0, 2 )); /// ``` -use alloc::vec::Vec; + pub fn histogram(data: &[(f32, f32)], min: f32, max: f32, bins: usize) -> Vec<(f32, f32)> { let mut output = vec![0; bins]; From 5c5499931e99c8b970432b9c25061a6d66720f95 Mon Sep 17 00:00:00 2001 From: uandere Date: Thu, 5 Oct 2023 23:31:06 +0300 Subject: [PATCH 5/8] Made std and no_std versions compile --- Cargo.toml | 1 + src/lib.rs | 172 ++++++++++++++++++++++++++++++++++++++++----------- src/utils.rs | 5 +- 3 files changed, 140 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ff7159..02197dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ std = [ [dependencies] # THESE CRATES ARE ENABLED BY DEFAULT drawille-nostd = "0.1.2" +num-traits = { version = "0.2.16", default-features = false, features = ["libm"] } # THESE CRATES ARE ENABLED ONLY BY THE CORRESPONDING FEATURES drawille = { version = "0.3.0" , optional = true} structopt = { version = "0.3", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 3e8f945..5cb7849 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,19 +49,36 @@ //! //! +// If std feature isn't enabled, don't load standard library +#![cfg_attr(not(feature = "std"), no_std)] + pub mod scale; pub mod utils; -use drawille::Canvas as BrailleCanvas; -use drawille::PixelColor; -use rgb::RGB8; +// These imports are mutual for std and no_std +extern crate alloc; + +use alloc::borrow::ToOwned; +use alloc::boxed::Box; +use alloc::format; +use alloc::string::String; +use alloc::vec::Vec; +use core::cmp; +use core::default::Default; +use core::f32; +use core::fmt::{Display, Formatter}; +#[allow(unused_imports, clippy::single_component_path_imports)] +use drawille_nostd; use scale::Scale; +#[allow(unused_imports)] +use num_traits::real::Real; -use std::cmp; -use std::default::Default; -use std::f32; +// These imports are for std-version only +#[cfg(feature = "std")] +use drawille::PixelColor; +#[cfg(feature = "std")] +use rgb::RGB8; -use std::fmt::{Display, Formatter, Result}; /// How the chart will do the ranging on axes #[derive(PartialEq)] @@ -72,6 +89,18 @@ enum ChartRangeMethod { FixedRange, } +#[cfg(not(feature = "std"))] +type BrailleCanvas = drawille_nostd::Canvas; + +#[cfg(not(feature = "std"))] +type Shapes<'a> = Vec<&'a Shape<'a>>; + +#[cfg(feature = "std")] +type BrailleCanvas = drawille::Canvas; + +#[cfg(feature = "std")] +type Shapes<'a> = Vec<(&'a Shape<'a>, Option)>; + /// Controls the drawing. pub struct Chart<'a> { /// Canvas width in points. @@ -89,7 +118,7 @@ pub struct Chart<'a> { /// The type of y axis ranging we'll do y_ranging: ChartRangeMethod, /// Collection of shapes to be presented on the canvas. - shapes: Vec<(&'a Shape<'a>, Option)>, + shapes: Shapes<'a>, /// Underlying canvas object. canvas: BrailleCanvas, /// X-axis style. @@ -119,10 +148,15 @@ pub enum Shape<'a> { /// Provides an interface for drawing plots. pub trait Plot<'a> { /// Draws a [line chart](https://en.wikipedia.org/wiki/Line_chart) of points connected by straight line segments. + #[cfg(feature = "std")] fn lineplot(&'a mut self, shape: &'a Shape) -> &'a mut Chart; + + #[cfg(not(feature = "std"))] + fn lineplot_nostd(&'a mut self, shape: &'a Shape) -> &'a mut Chart; } /// Provides an interface for drawing colored plots. +#[cfg(feature = "std")] pub trait ColorPlot<'a> { /// Draws a [line chart](https://en.wikipedia.org/wiki/Line_chart) of points connected by straight line segments using the specified color fn linecolorplot(&'a mut self, shape: &'a Shape, color: RGB8) -> &'a mut Chart; @@ -177,7 +211,7 @@ pub enum LabelFormat { } impl<'a> Display for Chart<'a> { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { // get frame and replace space with U+2800 (BRAILLE PATTERN BLANK) let mut frame = self.canvas.frame().replace(' ', "\u{2800}"); @@ -270,7 +304,7 @@ impl<'a> Chart<'a> { } /// Displays bounding rect. - fn borders(&mut self) { + pub fn borders(&mut self) { let w = self.width; let h = self.height; @@ -347,6 +381,7 @@ impl<'a> Chart<'a> { } /// Prints canvas content. + #[cfg(feature = "std")] pub fn display(&mut self) { self.axis(); self.figures(); @@ -355,6 +390,7 @@ impl<'a> Chart<'a> { } /// Prints canvas content with some additional visual elements (like borders). + #[cfg(feature = "std")] pub fn nice(&mut self) { self.borders(); self.display(); @@ -402,39 +438,46 @@ impl<'a> Chart<'a> { } } + fn translate(&self, shape: &Shape, x_scale: &Scale, y_scale: &Scale) -> Vec<(u32, u32)> { + // translate (x, y) points into screen coordinates + let points: Vec<_> = match shape { + Shape::Continuous(f) => (0..self.width) + .filter_map(|i| { + let x = x_scale.inv_linear(i as f32); + let y = f(x); + if y.is_normal() { + let j = y_scale.linear(y).round(); + Some((i, self.height - j as u32)) + } else { + None + } + }) + .collect(), + Shape::Points(dt) | Shape::Lines(dt) | Shape::Steps(dt) | Shape::Bars(dt) => dt + .iter() + .filter_map(|(x, y)| { + let i = x_scale.linear(*x).round() as u32; + let j = y_scale.linear(*y).round() as u32; + if i <= self.width && j <= self.height { + Some((i, self.height - j)) + } else { + None + } + }) + .collect(), + }; + points + } + // Shows figures. + #[cfg(feature = "std")] pub fn figures(&mut self) { for (shape, color) in &self.shapes { let x_scale = Scale::new(self.xmin..self.xmax, 0.0..self.width as f32); let y_scale = Scale::new(self.ymin..self.ymax, 0.0..self.height as f32); // translate (x, y) points into screen coordinates - let points: Vec<_> = match shape { - Shape::Continuous(f) => (0..self.width) - .filter_map(|i| { - let x = x_scale.inv_linear(i as f32); - let y = f(x); - if y.is_normal() { - let j = y_scale.linear(y).round(); - Some((i, self.height - j as u32)) - } else { - None - } - }) - .collect(), - Shape::Points(dt) | Shape::Lines(dt) | Shape::Steps(dt) | Shape::Bars(dt) => dt - .iter() - .filter_map(|(x, y)| { - let i = x_scale.linear(*x).round() as u32; - let j = y_scale.linear(*y).round() as u32; - if i <= self.width && j <= self.height { - Some((i, self.height - j)) - } else { - None - } - }) - .collect(), - }; + let points = self.translate(shape, &x_scale, &y_scale); // display segments match shape { @@ -498,6 +541,51 @@ impl<'a> Chart<'a> { } } + #[cfg(not(feature = "std"))] + pub fn figures_nostd(&mut self) { + for shape in &self.shapes { + let x_scale = Scale::new(self.xmin..self.xmax, 0.0..self.width as f32); + let y_scale = Scale::new(self.ymin..self.ymax, 0.0..self.height as f32); + + // translate (x, y) points into screen coordinates + let points = self.translate(shape, &x_scale, &y_scale); + + // display segments + match shape { + Shape::Continuous(_) | Shape::Lines(_) => { + for pair in points.windows(2) { + let (x1, y1) = pair[0]; + let (x2, y2) = pair[1]; + self.canvas.line(x1, y1, x2, y2); + } + } + Shape::Points(_) => { + for (x, y) in points { + self.canvas.set(x, y); + } + } + Shape::Steps(_) => { + for pair in points.windows(2) { + let (x1, y1) = pair[0]; + let (x2, y2) = pair[1]; + self.canvas.line(x1, y2, x2, y2); + self.canvas.line(x1, y1, x1, y2); + } + } + Shape::Bars(_) => { + for pair in points.windows(2) { + let (x1, y1) = pair[0]; + let (x2, y2) = pair[1]; + self.canvas.line(x1, y2, x2, y2); + self.canvas.line(x1, y1, x1, y2); + self.canvas.line(x1, self.height, x1, y1); + self.canvas.line(x2, self.height, x2, y2); + } + } + } + } + } + /// Returns the frame. pub fn frame(&self) -> String { self.canvas.frame() @@ -545,6 +633,7 @@ impl<'a> Chart<'a> { } } +#[cfg(feature = "std")] impl<'a> ColorPlot<'a> for Chart<'a> { fn linecolorplot(&'a mut self, shape: &'a Shape, color: RGB8) -> &'a mut Chart { self.shapes.push((shape, Some(color))); @@ -556,6 +645,7 @@ impl<'a> ColorPlot<'a> for Chart<'a> { } impl<'a> Plot<'a> for Chart<'a> { + #[cfg(feature = "std")] fn lineplot(&'a mut self, shape: &'a Shape) -> &'a mut Chart { self.shapes.push((shape, None)); if self.y_ranging == ChartRangeMethod::AutoRange { @@ -563,8 +653,18 @@ impl<'a> Plot<'a> for Chart<'a> { } self } + + #[cfg(not(feature = "std"))] + fn lineplot_nostd(&'a mut self, shape: &'a Shape) -> &'a mut Chart { + self.shapes.push(shape); + if self.y_ranging == ChartRangeMethod::AutoRange { + self.rescale(shape); + } + self + } } +#[cfg(feature = "std")] fn rgb_to_pixelcolor(rgb: &RGB8) -> PixelColor { PixelColor::TrueColor { r: rgb.r, diff --git a/src/utils.rs b/src/utils.rs index 1306711..4c47c05 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -3,6 +3,9 @@ //! Merely a bunch of functions hanging around while the library API is taking shape. +use alloc::vec; +use alloc::vec::Vec; + /// Transforms points into frequency distribution (for using in histograms). /// Values outside of [`min`, `max`] interval are ignored, and everything that /// falls into the specified interval is grouped into `bins` number of buckets of equal width. @@ -11,8 +14,6 @@ /// # use textplots::utils::histogram; /// assert_eq!(vec![(0.0, 1.0), (5.0, 1.0)], histogram( &[ (0.0, 0.0), (9.0, 9.0), (10.0, 10.0) ], 0.0, 10.0, 2 )); /// ``` - - pub fn histogram(data: &[(f32, f32)], min: f32, max: f32, bins: usize) -> Vec<(f32, f32)> { let mut output = vec![0; bins]; From c5c89821c6113fd84d29d379e37c1d9aaa6b94f5 Mon Sep 17 00:00:00 2001 From: uandere Date: Fri, 6 Oct 2023 10:51:53 +0300 Subject: [PATCH 6/8] Method names for nostd version are the same now --- src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5cb7849..23ffca9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,11 +148,8 @@ pub enum Shape<'a> { /// Provides an interface for drawing plots. pub trait Plot<'a> { /// Draws a [line chart](https://en.wikipedia.org/wiki/Line_chart) of points connected by straight line segments. - #[cfg(feature = "std")] fn lineplot(&'a mut self, shape: &'a Shape) -> &'a mut Chart; - #[cfg(not(feature = "std"))] - fn lineplot_nostd(&'a mut self, shape: &'a Shape) -> &'a mut Chart; } /// Provides an interface for drawing colored plots. @@ -542,7 +539,7 @@ impl<'a> Chart<'a> { } #[cfg(not(feature = "std"))] - pub fn figures_nostd(&mut self) { + pub fn figures(&mut self) { for shape in &self.shapes { let x_scale = Scale::new(self.xmin..self.xmax, 0.0..self.width as f32); let y_scale = Scale::new(self.ymin..self.ymax, 0.0..self.height as f32); @@ -655,7 +652,7 @@ impl<'a> Plot<'a> for Chart<'a> { } #[cfg(not(feature = "std"))] - fn lineplot_nostd(&'a mut self, shape: &'a Shape) -> &'a mut Chart { + fn lineplot(&'a mut self, shape: &'a Shape) -> &'a mut Chart { self.shapes.push(shape); if self.y_ranging == ChartRangeMethod::AutoRange { self.rescale(shape); From 33c8c3817a95649f0f38822bc78d707c983c73e9 Mon Sep 17 00:00:00 2001 From: uandere Date: Fri, 6 Oct 2023 10:56:33 +0300 Subject: [PATCH 7/8] Fixed formatting --- Cargo.toml | 2 +- src/lib.rs | 4 +--- src/utils.rs | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02197dc..883c583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ std = [ drawille-nostd = "0.1.2" num-traits = { version = "0.2.16", default-features = false, features = ["libm"] } # THESE CRATES ARE ENABLED ONLY BY THE CORRESPONDING FEATURES -drawille = { version = "0.3.0" , optional = true} +drawille = { version = "0.3.0", optional = true } structopt = { version = "0.3", optional = true } meval = { version = "0.2", optional = true } rgb = { version = "0.8.27", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 23ffca9..652b3bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,9 +69,9 @@ use core::f32; use core::fmt::{Display, Formatter}; #[allow(unused_imports, clippy::single_component_path_imports)] use drawille_nostd; -use scale::Scale; #[allow(unused_imports)] use num_traits::real::Real; +use scale::Scale; // These imports are for std-version only #[cfg(feature = "std")] @@ -79,7 +79,6 @@ use drawille::PixelColor; #[cfg(feature = "std")] use rgb::RGB8; - /// How the chart will do the ranging on axes #[derive(PartialEq)] enum ChartRangeMethod { @@ -149,7 +148,6 @@ pub enum Shape<'a> { pub trait Plot<'a> { /// Draws a [line chart](https://en.wikipedia.org/wiki/Line_chart) of points connected by straight line segments. fn lineplot(&'a mut self, shape: &'a Shape) -> &'a mut Chart; - } /// Provides an interface for drawing colored plots. diff --git a/src/utils.rs b/src/utils.rs index 4c47c05..6569756 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,6 @@ //! //! Merely a bunch of functions hanging around while the library API is taking shape. - use alloc::vec; use alloc::vec::Vec; From e715c619c7973c216fcdc86f1d8cd31986141516 Mon Sep 17 00:00:00 2001 From: uandere Date: Fri, 6 Oct 2023 15:07:06 +0300 Subject: [PATCH 8/8] Add comments to lib.rs --- src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 652b3bd..ca270cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,6 +151,7 @@ pub trait Plot<'a> { } /// Provides an interface for drawing colored plots. +/// Available with `std` feature. #[cfg(feature = "std")] pub trait ColorPlot<'a> { /// Draws a [line chart](https://en.wikipedia.org/wiki/Line_chart) of points connected by straight line segments using the specified color @@ -376,6 +377,7 @@ impl<'a> Chart<'a> { } /// Prints canvas content. + /// Available with `std` feature. #[cfg(feature = "std")] pub fn display(&mut self) { self.axis(); @@ -385,6 +387,7 @@ impl<'a> Chart<'a> { } /// Prints canvas content with some additional visual elements (like borders). + /// Available with `std` feature. #[cfg(feature = "std")] pub fn nice(&mut self) { self.borders(); @@ -433,8 +436,8 @@ impl<'a> Chart<'a> { } } + /// Translates (x, y) points into screen coordinates fn translate(&self, shape: &Shape, x_scale: &Scale, y_scale: &Scale) -> Vec<(u32, u32)> { - // translate (x, y) points into screen coordinates let points: Vec<_> = match shape { Shape::Continuous(f) => (0..self.width) .filter_map(|i| { @@ -464,7 +467,8 @@ impl<'a> Chart<'a> { points } - // Shows figures. + // Shows colored figures. + // Available with `std` feature. #[cfg(feature = "std")] pub fn figures(&mut self) { for (shape, color) in &self.shapes { @@ -536,6 +540,7 @@ impl<'a> Chart<'a> { } } + // Shows figures. #[cfg(not(feature = "std"))] pub fn figures(&mut self) { for shape in &self.shapes {