diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/3d-plot.rs | 47 | ||||
-rw-r--r-- | examples/animation.rs | 7 | ||||
-rw-r--r-- | examples/area-chart.rs | 6 | ||||
-rw-r--r-- | examples/blit-bitmap.rs | 6 | ||||
-rw-r--r-- | examples/boxplot.rs | 49 | ||||
-rw-r--r-- | examples/chart.rs | 40 | ||||
-rw-r--r-- | examples/console.rs | 34 | ||||
-rw-r--r-- | examples/errorbar.rs | 6 | ||||
-rw-r--r-- | examples/histogram.rs | 9 | ||||
-rw-r--r-- | examples/mandelbrot.rs | 6 | ||||
-rw-r--r-- | examples/matshow.rs | 6 | ||||
-rw-r--r-- | examples/nested_coord.rs | 43 | ||||
-rw-r--r-- | examples/normal-dist.rs | 22 | ||||
-rw-r--r-- | examples/normal-dist2.rs | 17 | ||||
-rw-r--r-- | examples/relative_size.rs | 6 | ||||
-rw-r--r-- | examples/sierpinski.rs | 4 | ||||
-rw-r--r-- | examples/slc-temp.rs | 10 | ||||
-rw-r--r-- | examples/snowflake.rs | 6 | ||||
-rw-r--r-- | examples/stock.rs | 8 | ||||
-rw-r--r-- | examples/two-scales.rs | 6 |
20 files changed, 239 insertions, 99 deletions
diff --git a/examples/3d-plot.rs b/examples/3d-plot.rs new file mode 100644 index 0000000..7d27e1f --- /dev/null +++ b/examples/3d-plot.rs @@ -0,0 +1,47 @@ +use plotters::prelude::*; +fn main() -> Result<(), Box<dyn std::error::Error>> { + let area = SVGBackend::new("plotters-doc-data/3d-plot.svg", (1024, 760)).into_drawing_area(); + + area.fill(&WHITE)?; + + let x_axis = (-3.0..3.0).step(0.1); + let z_axis = (-3.0..3.0).step(0.1); + + let mut chart = ChartBuilder::on(&area) + .caption(format!("3D Plot Test"), ("sans", 20)) + .build_cartesian_3d(x_axis.clone(), -3.0..3.0, z_axis.clone())?; + + chart.with_projection(|mut pb| { + pb.yaw = 0.5; + pb.scale = 0.9; + pb.into_matrix() + }); + + chart.configure_axes().draw()?; + + chart + .draw_series(SurfaceSeries::<f64, _, f64>::new( + x_axis.values(), + z_axis.values(), + |&x, &z| (x * x + z * z).cos(), + &BLUE.mix(0.2), + ))? + .label("Surface") + .legend(|(x, y)| Rectangle::new([(x + 5, y - 5), (x + 15, y + 5)], BLUE.mix(0.5).filled())); + + chart + .draw_series(LineSeries::new( + (-100..100) + .map(|y| y as f64 / 40.0) + .map(|y| ((y * 10.0).sin(), y, (y * 10.0).cos())), + &BLACK, + ))? + .label("Line") + .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &BLACK)); + + chart + .configure_series_labels() + .border_style(&BLACK) + .draw()?; + Ok(()) +} diff --git a/examples/animation.rs b/examples/animation.rs index 7f20bca..431e4ea 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -29,7 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { format!("Koch's Snowflake (n_iter = {})", i), ("sans-serif", 50), ) - .build_ranged(-2.0..2.0, -1.5..1.5)?; + .build_cartesian_2d(-2.0..2.0, -1.5..1.5)?; let mut snowflake_vertices = { let mut current: Vec<(f64, f64)> = vec![ @@ -56,3 +56,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } + +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/area-chart.rs b/examples/area-chart.rs index 707cc5a..f02e5ce 100644 --- a/examples/area-chart.rs +++ b/examples/area-chart.rs @@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .set_label_area_size(LabelAreaPosition::Left, 60) .set_label_area_size(LabelAreaPosition::Bottom, 60) .caption("Area Chart Demo", ("sans-serif", 40)) - .build_ranged(0..(data.len() - 1), 0.0..1500.0)?; + .build_cartesian_2d(0..(data.len() - 1), 0.0..1500.0)?; chart .configure_mesh() @@ -45,3 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/blit-bitmap.rs b/examples/blit-bitmap.rs index 1e0e47e..efc6590 100644 --- a/examples/blit-bitmap.rs +++ b/examples/blit-bitmap.rs @@ -15,7 +15,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .margin(5) .set_label_area_size(LabelAreaPosition::Left, 40) .set_label_area_size(LabelAreaPosition::Bottom, 40) - .build_ranged(0.0..1.0, 0.0..1.0)?; + .build_cartesian_2d(0.0..1.0, 0.0..1.0)?; chart.configure_mesh().disable_mesh().draw()?; @@ -31,3 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { chart.draw_series(std::iter::once(elem))?; Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/boxplot.rs b/examples/boxplot.rs index 47f3b1a..e67041e 100644 --- a/examples/boxplot.rs +++ b/examples/boxplot.rs @@ -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); @@ -73,23 +70,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .x_label_area_size(40) .y_label_area_size(80) .caption("Ping Boxplot", ("sans-serif", 20).into_font()) - .build_ranged( + .build_cartesian_2d( values_range.start - 1.0..values_range.end + 1.0, - category.range(), + host_list[..].into_segmented(), )?; chart .configure_mesh() .x_desc("Ping, ms") - .y_desc(category.name()) - .y_labels(category.len()) - .line_style_2(&WHITE) + .y_desc("Host") + .y_labels(host_list.len()) + .light_line_style(&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(SegmentValue::CenterOf(&x.0), &x.1) .width(20) .whisker_width(0.5) .style(style) @@ -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() @@ -124,24 +123,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .x_label_area_size(40) .y_label_area_size(40) .caption("Vertical Boxplot", ("sans-serif", 20).into_font()) - .build_ranged( - category_ab.clone(), + .build_cartesian_2d( + ab_axis[..].into_segmented(), values_range.start - 10.0..values_range.end + 10.0, )?; - chart.configure_mesh().line_style_2(&WHITE).draw()?; + chart.configure_mesh().light_line_style(&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(SegmentValue::CenterOf(&"a"), &quartiles_a), + Boxplot::new_vertical(SegmentValue::CenterOf(&"b"), &quartiles_b), ])?; let mut chart = ChartBuilder::on(&right) .x_label_area_size(40) .y_label_area_size(40) .caption("Horizontal Boxplot", ("sans-serif", 20).into_font()) - .build_ranged(-30f32..90f32, 0..3)?; + .build_cartesian_2d(-30f32..90f32, 0..3)?; - chart.configure_mesh().line_style_2(&WHITE).draw()?; + chart.configure_mesh().light_line_style(&WHITE).draw()?; chart.draw_series(vec![ Boxplot::new_horizontal(1, &quartiles_a), Boxplot::new_horizontal(2, &Quartiles::new(&[30])), @@ -220,3 +219,7 @@ fn get_data() -> String { ", ) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/chart.rs b/examples/chart.rs index 15fb23d..0502a5e 100644 --- a/examples/chart.rs +++ b/examples/chart.rs @@ -10,11 +10,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let (upper, lower) = root_area.split_vertically(512); + let x_axis = (-3.4f32..3.4).step(0.1); + let mut cc = ChartBuilder::on(&upper) .margin(5) .set_all_label_area_size(50) .caption("Sine and Cosine", ("sans-serif", 40).into_font()) - .build_ranged(-3.4f32..3.4f32, -1.2f32..1.2f32)?; + .build_cartesian_2d(-3.4f32..3.4, -1.2f32..1.2f32)?; cc.configure_mesh() .x_labels(20) @@ -24,20 +26,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .y_label_formatter(&|v| format!("{:.1}", v)) .draw()?; - cc.draw_series(LineSeries::new( - (0..12).map(|x| ((x - 6) as f32 / 2.0, ((x - 6) as f32 / 2.0).sin())), - &RED, - ))? - .label("Sine") - .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED)); + cc.draw_series(LineSeries::new(x_axis.values().map(|x| (x, x.sin())), &RED))? + .label("Sine") + .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED)); cc.draw_series(LineSeries::new( - (0..6800).map(|x| { - ( - (x - 3400) as f32 / 1000.0, - ((x - 3400) as f32 / 1000.0).cos(), - ) - }), + x_axis.values().map(|x| (x, x.cos())), &BLUE, ))? .label("Cosine") @@ -48,14 +42,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { /* // It's possible to use a existing pointing element cc.draw_series(PointSeries::<_, _, Circle<_>>::new( - (0..6).map(|x| ((x - 3) as f32 / 1.0, ((x - 3) as f32 / 1.0).sin())), + (-3.0f32..2.1f32).step(1.0).values().map(|x| (x, x.sin())), 5, Into::<ShapeStyle>::into(&RGBColor(255,0,0)).filled(), ))?;*/ // Otherwise you can use a function to construct your pointing element yourself cc.draw_series(PointSeries::of_element( - (0..6).map(|x| ((x - 3) as f32 / 1.0, ((x - 3) as f32 / 1.0).sin())), + (-3.0f32..2.1f32).step(1.0).values().map(|x| (x, x.sin())), 5, ShapeStyle::from(&RED).filled(), &|coord, size, style| { @@ -80,19 +74,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { format!("y = x^{}", 1 + 2 * idx), ("sans-serif", 40).into_font(), ) - .build_ranged(-1f32..1f32, -1f32..1f32)?; + .build_cartesian_2d(-1f32..1f32, -1f32..1f32)?; cc.configure_mesh().x_labels(5).y_labels(3).draw()?; cc.draw_series(LineSeries::new( - (-100..100).map(|x| { - ( - x as f32 / 100.0, - (x as f32 / 100.0).powf(idx as f32 * 2.0 + 1.0), - ) - }), + (-1f32..1f32) + .step(0.01) + .values() + .map(|x| (x, x.powf(idx as f32 * 2.0 + 1.0))), &BLUE, ))?; } Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/console.rs b/examples/console.rs index 663b3ef..6d21ab9 100644 --- a/examples/console.rs +++ b/examples/console.rs @@ -1,10 +1,8 @@ -use plotters::drawing::{ - backend::{BackendStyle, DrawingErrorKind}, - DrawingBackend, -}; use plotters::prelude::*; use plotters::style::text_anchor::{HPos, VPos}; -use plotters::style::RGBAColor; +use plotters_backend::{ + BackendColor, BackendStyle, BackendTextStyle, DrawingBackend, DrawingErrorKind, +}; use std::error::Error; #[derive(Copy, Clone)] @@ -80,9 +78,9 @@ impl DrawingBackend for TextDrawingBackend { fn draw_pixel( &mut self, pos: (i32, i32), - color: &RGBAColor, + color: BackendColor, ) -> Result<(), DrawingErrorKind<std::io::Error>> { - if color.alpha() > 0.3 { + if color.alpha > 0.3 { self.0[(pos.1 * 100 + pos.0) as usize].update(PixelState::Pixel); } Ok(()) @@ -114,31 +112,31 @@ impl DrawingBackend for TextDrawingBackend { return Ok(()); } - plotters::drawing::rasterizer::draw_line(self, from, to, style) + plotters_backend::rasterizer::draw_line(self, from, to, style) } - fn estimate_text_size<'a>( + fn estimate_text_size<S: BackendTextStyle>( &self, text: &str, - _font: &FontDesc<'a>, + _: &S, ) -> Result<(u32, u32), DrawingErrorKind<Self::ErrorType>> { Ok((text.len() as u32, 1)) } - fn draw_text( + fn draw_text<S: BackendTextStyle>( &mut self, text: &str, - style: &TextStyle, + style: &S, pos: (i32, i32), ) -> Result<(), DrawingErrorKind<Self::ErrorType>> { - let (width, height) = self.estimate_text_size(text, &style.font)?; + let (width, height) = self.estimate_text_size(text, style)?; let (width, height) = (width as i32, height as i32); - let dx = match style.pos.h_pos { + let dx = match style.anchor().h_pos { HPos::Left => 0, HPos::Right => -width, HPos::Center => -width / 2, }; - let dy = match style.pos.v_pos { + let dy = match style.anchor().v_pos { VPos::Top => 0, VPos::Center => -height / 2, VPos::Bottom => -height, @@ -162,7 +160,7 @@ where .caption("Sine and Cosine", ("sans-serif", (10).percent_height())) .set_label_area_size(LabelAreaPosition::Left, (5i32).percent_width()) .set_label_area_size(LabelAreaPosition::Bottom, (10i32).percent_height()) - .build_ranged(-std::f64::consts::PI..std::f64::consts::PI, -1.2..1.2)?; + .build_cartesian_2d(-std::f64::consts::PI..std::f64::consts::PI, -1.2..1.2)?; chart .configure_mesh() @@ -193,3 +191,7 @@ fn main() -> Result<(), Box<dyn Error>> { draw_chart(b)?; Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/errorbar.rs b/examples/errorbar.rs index 4ef46d2..7f11dd9 100644 --- a/examples/errorbar.rs +++ b/examples/errorbar.rs @@ -22,7 +22,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .margin(10) .set_label_area_size(LabelAreaPosition::Left, 40) .set_label_area_size(LabelAreaPosition::Bottom, 40) - .build_ranged(-10f64..10f64, -10f64..10f64)?; + .build_cartesian_2d(-10f64..10f64, -10f64..10f64)?; chart.configure_mesh().draw()?; @@ -88,3 +88,7 @@ fn down_sample(data: &[(f64, f64)]) -> Vec<(f64, f64, f64, f64)> { .collect(); down_sampled } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/histogram.rs b/examples/histogram.rs index c33363f..6cb5934 100644 --- a/examples/histogram.rs +++ b/examples/histogram.rs @@ -10,13 +10,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .y_label_area_size(40) .margin(5) .caption("Histogram Test", ("sans-serif", 50.0).into_font()) - .build_ranged(0u32..10u32, 0u32..10u32)?; + .build_cartesian_2d((0u32..10u32).into_segmented(), 0u32..10u32)?; chart .configure_mesh() .disable_x_mesh() - .line_style_1(&WHITE.mix(0.3)) - .x_label_offset(30) + .bold_line_style(&WHITE.mix(0.3)) .y_desc("Count") .x_desc("Bucket") .axis_desc_style(("sans-serif", 15).into_font()) @@ -34,3 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/mandelbrot.rs b/examples/mandelbrot.rs index 81fa688..5af585e 100644 --- a/examples/mandelbrot.rs +++ b/examples/mandelbrot.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .margin(20) .x_label_area_size(10) .y_label_area_size(10) - .build_ranged(-2.1f64..0.6f64, -1.2f64..1.2f64)?; + .build_cartesian_2d(-2.1f64..0.6f64, -1.2f64..1.2f64)?; chart .configure_mesh() @@ -61,3 +61,7 @@ fn mandelbrot_set( return (c.0, c.1, cnt); }); } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/matshow.rs b/examples/matshow.rs index 186fcba..8cc03ea 100644 --- a/examples/matshow.rs +++ b/examples/matshow.rs @@ -10,7 +10,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .margin(5) .top_x_label_area_size(40) .y_label_area_size(40) - .build_ranged(0i32..15i32, 15i32..0i32)?; + .build_cartesian_2d(0i32..15i32, 15i32..0i32)?; chart .configure_mesh() @@ -50,3 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/nested_coord.rs b/examples/nested_coord.rs new file mode 100644 index 0000000..9dbdc8e --- /dev/null +++ b/examples/nested_coord.rs @@ -0,0 +1,43 @@ +use plotters::prelude::*; +fn main() -> Result<(), Box<dyn std::error::Error>> { + let root = + BitMapBackend::new("plotters-doc-data/nested_coord.png", (640, 480)).into_drawing_area(); + + root.fill(&WHITE)?; + + let mut chart = ChartBuilder::on(&root) + .x_label_area_size(35) + .y_label_area_size(40) + .margin(5) + .caption("Nested Coord", ("sans-serif", 50.0).into_font()) + .build_cartesian_2d( + ["Linear", "Quadratic"].nested_coord(|_| 0.0..10.0), + 0.0..10.0, + )?; + + chart + .configure_mesh() + .disable_mesh() + .axis_desc_style(("sans-serif", 15).into_font()) + .draw()?; + + chart.draw_series(LineSeries::new( + (0..10) + .map(|x| x as f64 / 1.0) + .map(|x| ((&"Linear", x).into(), x)), + &RED, + ))?; + + chart.draw_series(LineSeries::new( + (0..10) + .map(|x| x as f64 / 1.0) + .map(|x| ((&"Quadratic", x).into(), x * x / 10.0)), + &RED, + ))?; + + Ok(()) +} +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/normal-dist.rs b/examples/normal-dist.rs index 65cf0e3..20d048a 100644 --- a/examples/normal-dist.rs +++ b/examples/normal-dist.rs @@ -25,14 +25,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let mut x_hist_ctx = ChartBuilder::on(&areas[0]) .y_label_area_size(40) - .build_ranged(0u32..100u32, 0f64..0.5f64)?; + .build_cartesian_2d((0.0..1.0).step(0.01).use_round().into_segmented(), 0..250)?; let mut y_hist_ctx = ChartBuilder::on(&areas[3]) .x_label_area_size(40) - .build_ranged(0f64..0.5f64, 0..100u32)?; + .build_cartesian_2d(0..250, (0.0..1.0).step(0.01).use_round())?; let mut scatter_ctx = ChartBuilder::on(&areas[2]) .x_label_area_size(40) .y_label_area_size(40) - .build_ranged(0f64..1f64, 0f64..1f64)?; + .build_cartesian_2d(0f64..1f64, 0f64..1f64)?; scatter_ctx .configure_mesh() .disable_x_mesh() @@ -46,21 +46,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let x_hist = Histogram::vertical(&x_hist_ctx) .style(GREEN.filled()) .margin(0) - .data( - random_points - .iter() - .map(|(x, _)| ((x * 100.0) as u32, 0.002)), - ); + .data(random_points.iter().map(|(x, _)| (*x, 1))); let y_hist = Histogram::horizontal(&y_hist_ctx) .style(GREEN.filled()) .margin(0) - .data( - random_points - .iter() - .map(|(_, y)| ((y * 100.0) as u32, 0.002)), - ); + .data(random_points.iter().map(|(_, y)| (*y, 1))); x_hist_ctx.draw_series(x_hist)?; y_hist_ctx.draw_series(y_hist)?; Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/normal-dist2.rs b/examples/normal-dist2.rs index 6155ea6..d03e98c 100644 --- a/examples/normal-dist2.rs +++ b/examples/normal-dist2.rs @@ -27,8 +27,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .set_label_area_size(LabelAreaPosition::Left, 60) .set_label_area_size(LabelAreaPosition::Bottom, 60) .set_label_area_size(LabelAreaPosition::Right, 60) - .build_ranged(-4f64..4f64, 0f64..0.1)? - .set_secondary_coord((-40i32..40i32).into_centric(), 0u32..500u32); + .build_cartesian_2d(-4f64..4f64, 0f64..0.1)? + .set_secondary_coord( + (-4f64..4f64).step(0.1).use_round().into_segmented(), + 0u32..500u32, + ); chart .configure_mesh() @@ -43,11 +46,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let actual = Histogram::vertical(chart.borrow_secondary()) .style(GREEN.filled()) .margin(3) - .data( - random_points - .iter() - .map(|x| ((x * 10.0).round() as i32, 1u32)), - ); + .data(random_points.iter().map(|x| (*x, 1))); chart .draw_secondary_series(actual)? @@ -74,3 +73,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/relative_size.rs b/examples/relative_size.rs index a915d8a..b0c70fa 100644 --- a/examples/relative_size.rs +++ b/examples/relative_size.rs @@ -10,7 +10,7 @@ fn draw_chart<B: DrawingBackend>(root: &DrawingArea<B, Shift>) -> DrawResult<(), .x_label_area_size((10).percent_height()) .y_label_area_size((10).percent_width()) .margin(5) - .build_ranged(-5.0..5.0, -1.0..1.0)?; + .build_cartesian_2d(-5.0..5.0, -1.0..1.0)?; chart .configure_mesh() @@ -47,3 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/sierpinski.rs b/examples/sierpinski.rs index 9e68589..ab4b2c8 100644 --- a/examples/sierpinski.rs +++ b/examples/sierpinski.rs @@ -31,3 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { sierpinski_carpet(5, &root) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/slc-temp.rs b/examples/slc-temp.rs index 7a1b509..c38f169 100644 --- a/examples/slc-temp.rs +++ b/examples/slc-temp.rs @@ -1,7 +1,6 @@ -use plotters::coord::IntoMonthly; use plotters::prelude::*; -use chrono::{Datelike, TimeZone, Utc}; +use chrono::{TimeZone, Utc}; use std::error::Error; @@ -20,7 +19,7 @@ fn main() -> Result<(), Box<dyn Error>> { .set_label_area_size(LabelAreaPosition::Left, 60) .set_label_area_size(LabelAreaPosition::Right, 60) .set_label_area_size(LabelAreaPosition::Bottom, 40) - .build_ranged( + .build_cartesian_2d( (Utc.ymd(2010, 1, 1)..Utc.ymd(2018, 12, 1)).monthly(), 14.0..104.0, )? @@ -34,7 +33,6 @@ fn main() -> Result<(), Box<dyn Error>> { .disable_x_mesh() .disable_y_mesh() .x_labels(30) - .x_label_formatter(&|d| format!("{}-{}", d.year(), d.month())) .y_desc("Average Temp (F)") .draw()?; chart @@ -165,3 +163,7 @@ const DATA: [(i32, u32, f64); 12 * 9] = [ (2018, 11, 39.7), (2018, 12, 33.6), ]; +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/snowflake.rs b/examples/snowflake.rs index ccefb8e..d188422 100644 --- a/examples/snowflake.rs +++ b/examples/snowflake.rs @@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let mut chart = ChartBuilder::on(&root) .caption("Koch's Snowflake", ("sans-serif", 50)) - .build_ranged(-2.0..2.0, -1.5..1.5)?; + .build_cartesian_2d(-2.0..2.0, -1.5..1.5)?; let mut snowflake_vertices = { let mut current: Vec<(f64, f64)> = vec![ @@ -48,3 +48,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/stock.rs b/examples/stock.rs index 5c5c2b5..e34043a 100644 --- a/examples/stock.rs +++ b/examples/stock.rs @@ -21,9 +21,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .x_label_area_size(40) .y_label_area_size(40) .caption("MSFT Stock Price", ("sans-serif", 50.0).into_font()) - .build_ranged(from_date..to_date, 110f32..135f32)?; + .build_cartesian_2d(from_date..to_date, 110f32..135f32)?; - chart.configure_mesh().line_style_2(&WHITE).draw()?; + chart.configure_mesh().light_line_style(&WHITE).draw()?; chart.draw_series( data.iter() @@ -67,3 +67,7 @@ fn get_data() -> Vec<(&'static str, f32, f32, f32, f32)> { ("2019-03-14", 114.5400, 115.2000, 114.3300, 114.5900), ]; } +#[test] +fn entry_point() { + main().unwrap() +} diff --git a/examples/two-scales.rs b/examples/two-scales.rs index 33939e6..46f8976 100644 --- a/examples/two-scales.rs +++ b/examples/two-scales.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .right_y_label_area_size(40) .margin(5) .caption("Dual Y-Axis Example", ("sans-serif", 50.0).into_font()) - .build_ranged(0f32..10f32, LogRange(0.1f32..1e10f32))? + .build_cartesian_2d(0f32..10f32, LogRange(0.1f32..1e10f32))? .set_secondary_coord(0f32..10f32, -1.0f32..1.0f32); chart @@ -50,3 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[test] +fn entry_point() { + main().unwrap() +} |