Skip to content

Commit

Permalink
Merge pull request #509 from martinfrances107/clippy
Browse files Browse the repository at this point in the history
Chore: ran cargo clippy --fix
  • Loading branch information
AaronErhardt authored Oct 17, 2023
2 parents 4323ec2 + 10a53df commit 7c4ed88
Show file tree
Hide file tree
Showing 38 changed files with 147 additions and 162 deletions.
11 changes: 4 additions & 7 deletions plotters/examples/3d-plot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use plotters::prelude::*;
const OUT_FILE_NAME: &'static str = "plotters-doc-data/3d-plot.svg";
const OUT_FILE_NAME: &str = "plotters-doc-data/3d-plot.svg";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let area = SVGBackend::new(OUT_FILE_NAME, (1024, 760)).into_drawing_area();

Expand All @@ -9,7 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let z_axis = (-3.0..3.0).step(0.1);

let mut chart = ChartBuilder::on(&area)
.caption(format!("3D Plot Test"), ("sans", 20))
.caption("3D Plot Test".to_string(), ("sans", 20))
.build_cartesian_3d(x_axis.clone(), -3.0..3.0, z_axis.clone())?;

chart.with_projection(|mut pb| {
Expand Down Expand Up @@ -44,12 +44,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
&BLACK,
))?
.label("Line")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &BLACK));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLACK));

chart
.configure_series_labels()
.border_style(&BLACK)
.draw()?;
chart.configure_series_labels().border_style(BLACK).draw()?;

// To avoid the IO failure being ignored silently, we manually call the present function
area.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir");
Expand Down
6 changes: 3 additions & 3 deletions plotters/examples/3d-plot2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ fn pdf(x: f64, y: f64) -> f64 {
const SDX: f64 = 0.1;
const SDY: f64 = 0.1;
const A: f64 = 5.0;
let x = x as f64 / 10.0;
let y = y as f64 / 10.0;
let x = x / 10.0;
let y = y / 10.0;
A * (-x * x / 2.0 / SDX / SDX - y * y / 2.0 / SDY / SDY).exp()
}

const OUT_FILE_NAME: &'static str = "plotters-doc-data/3d-plot2.gif";
const OUT_FILE_NAME: &str = "plotters-doc-data/3d-plot2.gif";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::gif(OUT_FILE_NAME, (600, 400), 100)?.into_drawing_area();

Expand Down
6 changes: 3 additions & 3 deletions plotters/examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn snowflake_iter(points: &[(f64, f64)]) -> Vec<(f64, f64)> {
ret
}

const OUT_FILE_NAME: &'static str = "plotters-doc-data/animation.gif";
const OUT_FILE_NAME: &str = "plotters-doc-data/animation.gif";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::gif(OUT_FILE_NAME, (800, 600), 1_000)?.into_drawing_area();

Expand Down Expand Up @@ -45,11 +45,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

chart.draw_series(std::iter::once(Polygon::new(
snowflake_vertices.clone(),
&RED.mix(0.2),
RED.mix(0.2),
)))?;

snowflake_vertices.push(snowflake_vertices[0]);
chart.draw_series(std::iter::once(PathElement::new(snowflake_vertices, &RED)))?;
chart.draw_series(std::iter::once(PathElement::new(snowflake_vertices, RED)))?;

root.present()?;
}
Expand Down
6 changes: 3 additions & 3 deletions plotters/examples/area-chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::SeedableRng;
use rand_distr::{Distribution, Normal};
use rand_xorshift::XorShiftRng;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/area-chart.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/area-chart.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data: Vec<_> = {
let norm_dist = Normal::new(500.0, 100.0).unwrap();
Expand Down Expand Up @@ -38,9 +38,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
AreaSeries::new(
(0..).zip(data.iter()).map(|(x, y)| (x, *y)),
0.0,
&RED.mix(0.2),
RED.mix(0.2),
)
.border_style(&RED),
.border_style(RED),
)?;

// To avoid the IO failure being ignored silently, we manually call the present function
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/blit-bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use image::{imageops::FilterType, ImageFormat};
use std::fs::File;
use std::io::BufReader;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/blit-bitmap.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/blit-bitmap.png";

fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();
Expand Down
24 changes: 10 additions & 14 deletions plotters/examples/boxplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn read_data<BR: BufRead>(reader: BR) -> HashMap<(String, String), Vec<f64>> {
ds
}

const OUT_FILE_NAME: &'static str = "plotters-doc-data/boxplot.svg";
const OUT_FILE_NAME: &str = "plotters-doc-data/boxplot.svg";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = SVGBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();
root.fill(&WHITE)?;
Expand All @@ -40,7 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let dataset: Vec<(String, String, Quartiles)> = ds
.iter()
.map(|(k, v)| (k.0.clone(), k.1.clone(), Quartiles::new(&v)))
.map(|(k, v)| (k.0.clone(), k.1.clone(), Quartiles::new(v)))
.collect();

let host_list: Vec<_> = dataset
Expand All @@ -60,11 +60,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
entry.0.push((x.0.clone(), &x.2));
}

let values: Vec<f32> = dataset
.iter()
.map(|x| x.2.values().to_vec())
.flatten()
.collect();
let values: Vec<f32> = dataset.iter().flat_map(|x| x.2.values().to_vec()).collect();
let values_range = fitting_range(values.iter());

let mut chart = ChartBuilder::on(&upper)
Expand All @@ -81,13 +77,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.x_desc("Ping, ms")
.y_desc("Host")
.y_labels(host_list.len())
.light_line_style(&WHITE)
.light_line_style(WHITE)
.draw()?;

for (label, (values, style, offset)) in &series {
chart
.draw_series(values.iter().map(|x| {
Boxplot::new_horizontal(SegmentValue::CenterOf(&x.0), &x.1)
Boxplot::new_horizontal(SegmentValue::CenterOf(&x.0), x.1)
.width(20)
.whisker_width(0.5)
.style(style)
Expand All @@ -100,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.configure_series_labels()
.position(SeriesLabelPosition::UpperRight)
.background_style(WHITE.filled())
.border_style(&BLACK.mix(0.5))
.border_style(BLACK.mix(0.5))
.legend_area_size(22)
.draw()?;

Expand All @@ -120,7 +116,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.iter()
.chain(quartiles_b.values().iter()),
);
let mut chart = ChartBuilder::on(&left)
let mut chart = ChartBuilder::on(left)
.x_label_area_size(40)
.y_label_area_size(40)
.caption("Vertical Boxplot", ("sans-serif", 20))
Expand All @@ -129,19 +125,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
values_range.start - 10.0..values_range.end + 10.0,
)?;

chart.configure_mesh().light_line_style(&WHITE).draw()?;
chart.configure_mesh().light_line_style(WHITE).draw()?;
chart.draw_series(vec![
Boxplot::new_vertical(SegmentValue::CenterOf(&"a"), &quartiles_a),
Boxplot::new_vertical(SegmentValue::CenterOf(&"b"), &quartiles_b),
])?;

let mut chart = ChartBuilder::on(&right)
let mut chart = ChartBuilder::on(right)
.x_label_area_size(40)
.y_label_area_size(40)
.caption("Horizontal Boxplot", ("sans-serif", 20))
.build_cartesian_2d(-30f32..90f32, 0..3)?;

chart.configure_mesh().light_line_style(&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])),
Expand Down
10 changes: 5 additions & 5 deletions plotters/examples/chart.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use plotters::prelude::*;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/sample.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/sample.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root_area = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();

Expand Down Expand Up @@ -28,16 +28,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

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));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], RED));

cc.draw_series(LineSeries::new(
x_axis.values().map(|x| (x, x.cos())),
&BLUE,
))?
.label("Cosine")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &BLUE));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLUE));

cc.configure_series_labels().border_style(&BLACK).draw()?;
cc.configure_series_labels().border_style(BLACK).draw()?;

/*
// It's possible to use a existing pointing element
Expand All @@ -62,7 +62,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let drawing_areas = lower.split_evenly((1, 2));

for (drawing_area, idx) in drawing_areas.iter().zip(1..) {
let mut cc = ChartBuilder::on(&drawing_area)
let mut cc = ChartBuilder::on(drawing_area)
.x_label_area_size(30)
.y_label_area_size(30)
.margin_right(20)
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/colormaps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use plotters::prelude::*;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/colormaps.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/colormaps.png";

fn main() -> Result<(), Box<dyn std::error::Error>> {
let colormaps_rgb: [(Box<dyn ColorMap<RGBColor>>, &str); 4] = [
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ where
Ok(())
}

const OUT_FILE_NAME: &'static str = "plotters-doc-data/console-example.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/console-example.png";
fn main() -> Result<(), Box<dyn Error>> {
draw_chart(TextDrawingBackend(vec![PixelState::Empty; 5000]).into_drawing_area())?;
let b = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/customized_coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use plotters::{
coord::ranged1d::{KeyPointHint, NoDefaultFormatting, ValueFormatter},
prelude::*,
};
const OUT_FILE_NAME: &'static str = "plotters-doc-data/customized_coord.svg";
const OUT_FILE_NAME: &str = "plotters-doc-data/customized_coord.svg";

struct CustomizedX(u32);

Expand Down
6 changes: 3 additions & 3 deletions plotters/examples/errorbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::Itertools;

use num_traits::sign::Signed;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/errorbar.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/errorbar.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = generate_random_data();
let down_sampled = down_sample(&data[..]);
Expand All @@ -29,7 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
chart
.draw_series(LineSeries::new(data, &GREEN.mix(0.3)))?
.label("Raw Data")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &GREEN));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], GREEN));

chart.draw_series(LineSeries::new(
down_sampled.iter().map(|(x, _, y, _)| (*x, *y)),
Expand All @@ -43,7 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}),
)?
.label("Down-sampled")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &BLUE));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLUE));

chart
.configure_series_labels()
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/full_palette.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use plotters::prelude::*;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/full_palette.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/full_palette.png";

fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (2000, 850)).into_drawing_area();
Expand Down
4 changes: 2 additions & 2 deletions plotters/examples/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use plotters::prelude::*;
const OUT_FILE_NAME: &'static str = "plotters-doc-data/histogram.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/histogram.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (640, 480)).into_drawing_area();

Expand All @@ -15,7 +15,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
chart
.configure_mesh()
.disable_x_mesh()
.bold_line_style(&WHITE.mix(0.3))
.bold_line_style(WHITE.mix(0.3))
.y_desc("Count")
.x_desc("Bucket")
.axis_desc_style(("sans-serif", 15))
Expand Down
8 changes: 4 additions & 4 deletions plotters/examples/mandelbrot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use plotters::prelude::*;
use std::ops::Range;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/mandelbrot.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/mandelbrot.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (800, 600)).into_drawing_area();

Expand Down Expand Up @@ -51,7 +51,7 @@ fn mandelbrot_set(
(real.end - real.start) / samples.0 as f64,
(complex.end - complex.start) / samples.1 as f64,
);
return (0..(samples.0 * samples.1)).map(move |k| {
(0..(samples.0 * samples.1)).map(move |k| {
let c = (
real.start + step.0 * (k % samples.0) as f64,
complex.start + step.1 * (k / samples.0) as f64,
Expand All @@ -62,8 +62,8 @@ fn mandelbrot_set(
z = (z.0 * z.0 - z.1 * z.1 + c.0, 2.0 * z.0 * z.1 + c.1);
cnt += 1;
}
return (c.0, c.1, cnt);
});
(c.0, c.1, cnt)
})
}
#[test]
fn entry_point() {
Expand Down
5 changes: 2 additions & 3 deletions plotters/examples/matshow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use plotters::prelude::*;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/matshow.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/matshow.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();

Expand Down Expand Up @@ -35,8 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
matrix
.iter()
.zip(0..)
.map(|(l, y)| l.iter().zip(0..).map(move |(v, x)| (x as i32, y as i32, v)))
.flatten()
.flat_map(|(l, y)| l.iter().zip(0..).map(move |(v, x)| (x, y, v)))
.map(|(x, y, v)| {
Rectangle::new(
[(x, y), (x + 1, y + 1)],
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/nested_coord.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use plotters::prelude::*;
const OUT_FILE_NAME: &'static str = "plotters-doc-data/nested_coord.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/nested_coord.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (640, 480)).into_drawing_area();

Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/normal-dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::SeedableRng;
use rand_distr::{Distribution, Normal};
use rand_xorshift::XorShiftRng;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/normal-dist.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/normal-dist.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();

Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/normal-dist2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand_xorshift::XorShiftRng;

use num_traits::sign::Signed;

const OUT_FILE_NAME: &'static str = "plotters-doc-data/normal-dist2.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/normal-dist2.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let sd = 0.60;

Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/pie.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use plotters::{prelude::*, style::full_palette::ORANGE};

const OUT_FILE_NAME: &'static str = "plotters-doc-data/pie-chart.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/pie-chart.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root_area = BitMapBackend::new(&OUT_FILE_NAME, (950, 700)).into_drawing_area();
root_area.fill(&WHITE).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/relative_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn draw_chart<B: DrawingBackend>(root: &DrawingArea<B, Shift>) -> DrawResult<(),
Ok(())
}

const OUT_FILE_NAME: &'static str = "plotters-doc-data/relative_size.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/relative_size.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();

Expand Down
2 changes: 1 addition & 1 deletion plotters/examples/sierpinski.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn sierpinski_carpet(
Ok(())
}

const OUT_FILE_NAME: &'static str = "plotters-doc-data/sierpinski.png";
const OUT_FILE_NAME: &str = "plotters-doc-data/sierpinski.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();

Expand Down
Loading

0 comments on commit 7c4ed88

Please sign in to comment.