Skip to content

Slice range #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions examples/boxplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.map(|(k, v)| (k.0.clone(), k.1.clone(), Quartiles::new(&v)))
.collect();

let category = Category::new(
"Host",
dataset
.iter()
.unique_by(|x| x.0.clone())
.sorted_by(|a, b| b.2.median().partial_cmp(&a.2.median()).unwrap())
.map(|x| x.0.clone())
.collect(),
);
let host_list: Vec<_> = dataset
.iter()
.unique_by(|x| x.0.clone())
.sorted_by(|a, b| b.2.median().partial_cmp(&a.2.median()).unwrap())
.map(|x| x.0.clone())
.collect();

let mut colors = (0..).map(Palette99::pick);
let mut offsets = (-12..).step_by(24);
Expand All @@ -75,21 +72,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.caption("Ping Boxplot", ("sans-serif", 20).into_font())
.build_ranged(
values_range.start - 1.0..values_range.end + 1.0,
category.range(),
host_list[..].into_centric(),
)?;

chart
.configure_mesh()
.x_desc("Ping, ms")
.y_desc(category.name())
.y_labels(category.len())
.y_desc("Host")
.y_labels(host_list.len())
.line_style_2(&WHITE)
.draw()?;

for (label, (values, style, offset)) in &series {
chart
.draw_series(values.iter().map(|x| {
Boxplot::new_horizontal(category.get(&x.0).unwrap(), &x.1)
Boxplot::new_horizontal(CentricValues::CenterOf(&x.0), &x.1)
.width(20)
.whisker_width(0.5)
.style(style)
Expand All @@ -113,7 +110,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6.0, 7.0, 15.9, 36.9, 39.0, 40.0, 41.0, 42.0, 43.0, 47.0, 49.0,
]);
let quartiles_b = Quartiles::new(&[16.0, 17.0, 50.0, 60.0, 40.2, 41.3, 42.7, 43.3, 47.0]);
let category_ab = Category::new("", vec!["a", "b"]);

let ab_axis = ["a", "b"];

let values_range = fitting_range(
quartiles_a
.values()
Expand All @@ -125,14 +124,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.y_label_area_size(40)
.caption("Vertical Boxplot", ("sans-serif", 20).into_font())
.build_ranged(
category_ab.clone(),
ab_axis[..].into_centric(),
values_range.start - 10.0..values_range.end + 10.0,
)?;

chart.configure_mesh().line_style_2(&WHITE).draw()?;
chart.draw_series(vec![
Boxplot::new_vertical(category_ab.get(&"a").unwrap(), &quartiles_a),
Boxplot::new_vertical(category_ab.get(&"b").unwrap(), &quartiles_b),
Boxplot::new_vertical(CentricValues::CenterOf(&"a"), &quartiles_a),
Boxplot::new_vertical(CentricValues::CenterOf(&"b"), &quartiles_b),
])?;

let mut chart = ChartBuilder::on(&right)
Expand Down
204 changes: 0 additions & 204 deletions src/coord/category.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/coord/discrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ where
impl<R: AsRangedCoord> IntoCentric for R where R::CoordDescType: DiscreteRanged {}

/// The value that used by the centric coordinate
#[derive(Clone)]
pub enum CentricValues<T> {
Exact(T),
CenterOf(T),
Expand Down
8 changes: 4 additions & 4 deletions src/coord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Also, the ranged axis can be deserted, and this is required by the histogram ser
*/
use plotters_backend::BackendCoord;

mod category;
#[cfg(feature = "chrono")]
mod datetime;
mod discrete;
Expand All @@ -31,6 +30,9 @@ mod logarithmic;
mod numeric;
mod partial_axis;
mod ranged;
mod slice;

pub use slice::RangedSlice;

#[cfg(feature = "chrono")]
pub use datetime::{IntoMonthly, IntoYearly, RangedDate, RangedDateTime, RangedDuration};
Expand All @@ -42,16 +44,14 @@ pub use ranged::{AsRangedCoord, MeshLine, Ranged, RangedCoord, ReversibleRanged}

pub use partial_axis::{make_partial_axis, IntoPartialAxis};

pub use discrete::{DiscreteRanged, IntoCentric};
pub use discrete::{CentricValues, DiscreteRanged, IntoCentric};

pub use logarithmic::{LogCoord, LogRange, LogScalable};

pub use group_by::{GroupBy, ToGroupByRange};
use std::rc::Rc;
use std::sync::Arc;

pub use category::Category;

/// The trait that translates some customized object to the backend coordinate
pub trait CoordTranslate {
type From;
Expand Down
Loading