Skip to content

Commit 77bf7c2

Browse files
authored
Merge branch 'master' into dash
2 parents 8108c9e + d540c33 commit 77bf7c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+193
-187
lines changed

plotters-backend/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
```text
3434
.ensure_prepared() &&
3535
+-------------+ +-------------+ .draw_pixels() +--------------+ drop
36-
|Start drwaing|--->|Ready to draw| ------------------------+---->|Finish 1 frame| --------->
36+
|Start drawing|--->|Ready to draw| ------------------------+---->|Finish 1 frame| --------->
3737
+-------------+ +-------------+ | +--------------+
3838
^ ^ | |
3939
| +------------------------------- + |

plotters-backend/src/text.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ impl<'a> From<&'a str> for FontFamily<'a> {
6060
/// ```
6161
pub mod text_anchor {
6262
/// The horizontal position of the anchor point relative to the text.
63-
#[derive(Clone, Copy)]
63+
#[derive(Clone, Copy, Default)]
6464
pub enum HPos {
6565
/// Anchor point is on the left side of the text
66+
#[default]
6667
Left,
6768
/// Anchor point is on the right side of the text
6869
Right,
@@ -71,9 +72,10 @@ pub mod text_anchor {
7172
}
7273

7374
/// The vertical position of the anchor point relative to the text.
74-
#[derive(Clone, Copy)]
75+
#[derive(Clone, Copy, Default)]
7576
pub enum VPos {
7677
/// Anchor point is on the top of the text
78+
#[default]
7779
Top,
7880
/// Anchor point is in the vertical center of the text
7981
Center,
@@ -82,7 +84,7 @@ pub mod text_anchor {
8284
}
8385

8486
/// The text anchor position.
85-
#[derive(Clone, Copy)]
87+
#[derive(Clone, Copy, Default)]
8688
pub struct Pos {
8789
/// The horizontal position of the anchor point
8890
pub h_pos: HPos,
@@ -106,21 +108,6 @@ pub mod text_anchor {
106108
Pos { h_pos, v_pos }
107109
}
108110

109-
/// Create a default text anchor position (top left).
110-
///
111-
/// - **returns** The default text anchor position
112-
///
113-
/// ```rust
114-
/// use plotters_backend::text_anchor::{Pos, HPos, VPos};
115-
///
116-
/// let pos = Pos::default();
117-
/// ```
118-
pub fn default() -> Self {
119-
Pos {
120-
h_pos: HPos::Left,
121-
v_pos: VPos::Top,
122-
}
123-
}
124111
}
125112
}
126113

plotters-bitmap/src/bitmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a> BitMapBackend<'a, RGBPixel> {
9191

9292
/// Create a new bitmap backend which only lives in-memory
9393
///
94-
/// When this is used, the bitmap backend will write to a user provided [u8] array (or Vec<u8>)
94+
/// When this is used, the bitmap backend will write to a user provided [u8] array (or `Vec<u8>`)
9595
/// in RGB pixel format.
9696
///
9797
/// Note: This function provides backward compatibility for those code that assumes Plotters

plotters/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repository = "https://github.com/plotters-rs/plotters"
99
homepage = "https://plotters-rs.github.io/"
1010
keywords = ["WebAssembly", "Visualization", "Plotting", "Drawing"]
1111
categories = ["visualization", "wasm"]
12-
readme = "README.md"
12+
readme = "../README.md"
1313
exclude = ["doc-template", "plotters-doc-data"]
1414

1515
[dependencies]

plotters/examples/3d-plot.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use plotters::prelude::*;
2-
const OUT_FILE_NAME: &'static str = "plotters-doc-data/3d-plot.svg";
2+
const OUT_FILE_NAME: &str = "plotters-doc-data/3d-plot.svg";
33
fn main() -> Result<(), Box<dyn std::error::Error>> {
44
let area = SVGBackend::new(OUT_FILE_NAME, (1024, 760)).into_drawing_area();
55

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

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

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

49-
chart
50-
.configure_series_labels()
51-
.border_style(&BLACK)
52-
.draw()?;
49+
chart.configure_series_labels().border_style(BLACK).draw()?;
5350

5451
// To avoid the IO failure being ignored silently, we manually call the present function
5552
area.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir");

plotters/examples/3d-plot2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ fn pdf(x: f64, y: f64) -> f64 {
33
const SDX: f64 = 0.1;
44
const SDY: f64 = 0.1;
55
const A: f64 = 5.0;
6-
let x = x as f64 / 10.0;
7-
let y = y as f64 / 10.0;
6+
let x = x / 10.0;
7+
let y = y / 10.0;
88
A * (-x * x / 2.0 / SDX / SDX - y * y / 2.0 / SDY / SDY).exp()
99
}
1010

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

plotters/examples/animation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn snowflake_iter(points: &[(f64, f64)]) -> Vec<(f64, f64)> {
1717
ret
1818
}
1919

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

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

4646
chart.draw_series(std::iter::once(Polygon::new(
4747
snowflake_vertices.clone(),
48-
&RED.mix(0.2),
48+
RED.mix(0.2),
4949
)))?;
5050

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

5454
root.present()?;
5555
}

plotters/examples/area-chart.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rand::SeedableRng;
44
use rand_distr::{Distribution, Normal};
55
use rand_xorshift::XorShiftRng;
66

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

4646
// To avoid the IO failure being ignored silently, we manually call the present function

plotters/examples/blit-bitmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use image::{imageops::FilterType, ImageFormat};
55
use std::fs::File;
66
use std::io::BufReader;
77

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

1010
fn main() -> Result<(), Box<dyn std::error::Error>> {
1111
let root = BitMapBackend::new(OUT_FILE_NAME, (1024, 768)).into_drawing_area();

plotters/examples/boxplot.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn read_data<BR: BufRead>(reader: BR) -> HashMap<(String, String), Vec<f64>> {
2121
ds
2222
}
2323

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

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

63-
let values: Vec<f32> = dataset
64-
.iter()
65-
.map(|x| x.2.values().to_vec())
66-
.flatten()
67-
.collect();
63+
let values: Vec<f32> = dataset.iter().flat_map(|x| x.2.values().to_vec()).collect();
6864
let values_range = fitting_range(values.iter());
6965

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

8783
for (label, (values, style, offset)) in &series {
8884
chart
8985
.draw_series(values.iter().map(|x| {
90-
Boxplot::new_horizontal(SegmentValue::CenterOf(&x.0), &x.1)
86+
Boxplot::new_horizontal(SegmentValue::CenterOf(&x.0), x.1)
9187
.width(20)
9288
.whisker_width(0.5)
9389
.style(style)
@@ -100,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
10096
.configure_series_labels()
10197
.position(SeriesLabelPosition::UpperRight)
10298
.background_style(WHITE.filled())
103-
.border_style(&BLACK.mix(0.5))
99+
.border_style(BLACK.mix(0.5))
104100
.legend_area_size(22)
105101
.draw()?;
106102

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

132-
chart.configure_mesh().light_line_style(&WHITE).draw()?;
128+
chart.configure_mesh().light_line_style(WHITE).draw()?;
133129
chart.draw_series(vec![
134130
Boxplot::new_vertical(SegmentValue::CenterOf(&"a"), &quartiles_a),
135131
Boxplot::new_vertical(SegmentValue::CenterOf(&"b"), &quartiles_b),
136132
])?;
137133

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

144-
chart.configure_mesh().light_line_style(&WHITE).draw()?;
140+
chart.configure_mesh().light_line_style(WHITE).draw()?;
145141
chart.draw_series(vec![
146142
Boxplot::new_horizontal(1, &quartiles_a),
147143
Boxplot::new_horizontal(2, &Quartiles::new(&[30])),

0 commit comments

Comments
 (0)