Skip to content

Commit 6da6db4

Browse files
committed
Merge branch 'master' of github.com:38/plotters
2 parents 12acc59 + dd5ca1f commit 6da6db4

File tree

8 files changed

+177
-131
lines changed

8 files changed

+177
-131
lines changed

examples/boxplot.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6969
let mut chart = ChartBuilder::on(&upper)
7070
.x_label_area_size(40)
7171
.y_label_area_size(80)
72-
.caption("Ping Boxplot", ("sans-serif", 20).into_font())
72+
.caption("Ping Boxplot", ("sans-serif", 20))
7373
.build_cartesian_2d(
7474
values_range.start - 1.0..values_range.end + 1.0,
7575
host_list[..].into_segmented(),
@@ -122,7 +122,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
122122
let mut chart = ChartBuilder::on(&left)
123123
.x_label_area_size(40)
124124
.y_label_area_size(40)
125-
.caption("Vertical Boxplot", ("sans-serif", 20).into_font())
125+
.caption("Vertical Boxplot", ("sans-serif", 20))
126126
.build_cartesian_2d(
127127
ab_axis[..].into_segmented(),
128128
values_range.start - 10.0..values_range.end + 10.0,
@@ -137,7 +137,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
137137
let mut chart = ChartBuilder::on(&right)
138138
.x_label_area_size(40)
139139
.y_label_area_size(40)
140-
.caption("Horizontal Boxplot", ("sans-serif", 20).into_font())
140+
.caption("Horizontal Boxplot", ("sans-serif", 20))
141141
.build_cartesian_2d(-30f32..90f32, 0..3)?;
142142

143143
chart.configure_mesh().light_line_style(&WHITE).draw()?;

examples/chart.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
66

77
root_area.fill(&WHITE)?;
88

9-
let root_area = root_area.titled("Image Title", ("sans-serif", 60).into_font())?;
9+
let root_area = root_area.titled("Image Title", ("sans-serif", 60))?;
1010

1111
let (upper, lower) = root_area.split_vertically(512);
1212

@@ -15,7 +15,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1515
let mut cc = ChartBuilder::on(&upper)
1616
.margin(5)
1717
.set_all_label_area_size(50)
18-
.caption("Sine and Cosine", ("sans-serif", 40).into_font())
18+
.caption("Sine and Cosine", ("sans-serif", 40))
1919
.build_cartesian_2d(-3.4f32..3.4, -1.2f32..1.2f32)?;
2020

2121
cc.configure_mesh()
@@ -55,11 +55,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5555
&|coord, size, style| {
5656
EmptyElement::at(coord)
5757
+ Circle::new((0, 0), size, style)
58-
+ Text::new(
59-
format!("{:?}", coord),
60-
(0, 15),
61-
("sans-serif", 15).into_font(),
62-
)
58+
+ Text::new(format!("{:?}", coord), (0, 15), ("sans-serif", 15))
6359
},
6460
))?;
6561

@@ -70,10 +66,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7066
.x_label_area_size(30)
7167
.y_label_area_size(30)
7268
.margin_right(20)
73-
.caption(
74-
format!("y = x^{}", 1 + 2 * idx),
75-
("sans-serif", 40).into_font(),
76-
)
69+
.caption(format!("y = x^{}", 1 + 2 * idx), ("sans-serif", 40))
7770
.build_cartesian_2d(-1f32..1f32, -1f32..1f32)?;
7871
cc.configure_mesh().x_labels(5).y_labels(3).draw()?;
7972

examples/histogram.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99
.x_label_area_size(35)
1010
.y_label_area_size(40)
1111
.margin(5)
12-
.caption("Histogram Test", ("sans-serif", 50.0).into_font())
12+
.caption("Histogram Test", ("sans-serif", 50.0))
1313
.build_cartesian_2d((0u32..10u32).into_segmented(), 0u32..10u32)?;
1414

1515
chart
@@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1818
.bold_line_style(&WHITE.mix(0.3))
1919
.y_desc("Count")
2020
.x_desc("Bucket")
21-
.axis_desc_style(("sans-serif", 15).into_font())
21+
.axis_desc_style(("sans-serif", 15))
2222
.draw()?;
2323

2424
let data = [

examples/nested_coord.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99
.x_label_area_size(35)
1010
.y_label_area_size(40)
1111
.margin(5)
12-
.caption("Nested Coord", ("sans-serif", 50.0).into_font())
12+
.caption("Nested Coord", ("sans-serif", 50.0))
1313
.build_cartesian_2d(
1414
["Linear", "Quadratic"].nested_coord(|_| 0.0..10.0),
1515
0.0..10.0,
@@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1818
chart
1919
.configure_mesh()
2020
.disable_mesh()
21-
.axis_desc_style(("sans-serif", 15).into_font())
21+
.axis_desc_style(("sans-serif", 15))
2222
.draw()?;
2323

2424
chart.draw_series(LineSeries::new(

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ pub mod prelude {
786786
// Styles
787787
pub use crate::style::{
788788
AsRelative, Color, FontDesc, FontFamily, FontStyle, FontTransform, HSLColor, IntoFont,
789-
Palette, Palette100, Palette99, Palette9999, PaletteColor, RGBColor, ShapeStyle, TextStyle,
789+
IntoTextStyle, Palette, Palette100, Palette99, Palette9999, PaletteColor, RGBColor,
790+
ShapeStyle, TextStyle,
790791
};
791792
pub use crate::style::{BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, TRANSPARENT, WHITE, YELLOW};
792793

src/style/font/font_desc.rs

+48-60
Original file line numberDiff line numberDiff line change
@@ -22,66 +22,6 @@ pub struct FontDesc<'a> {
2222
style: FontStyle,
2323
}
2424

25-
impl<'a> From<&'a str> for FontDesc<'a> {
26-
fn from(from: &'a str) -> FontDesc<'a> {
27-
FontDesc::new(from.into(), 12.0, FontStyle::Normal)
28-
}
29-
}
30-
31-
impl<'a> From<FontFamily<'a>> for FontDesc<'a> {
32-
fn from(family: FontFamily<'a>) -> FontDesc<'a> {
33-
FontDesc::new(family, 12.0, FontStyle::Normal)
34-
}
35-
}
36-
37-
impl<'a, T: Into<f64>> From<(FontFamily<'a>, T)> for FontDesc<'a> {
38-
fn from((family, size): (FontFamily<'a>, T)) -> FontDesc<'a> {
39-
FontDesc::new(family, size.into(), FontStyle::Normal)
40-
}
41-
}
42-
43-
impl From<f64> for FontDesc<'static> {
44-
fn from(size: f64) -> FontDesc<'static> {
45-
FontDesc::new(FontFamily::SansSerif, size.into(), FontStyle::Normal)
46-
}
47-
}
48-
49-
impl From<u32> for FontDesc<'static> {
50-
fn from(size: u32) -> FontDesc<'static> {
51-
FontDesc::new(FontFamily::SansSerif, size.into(), FontStyle::Normal)
52-
}
53-
}
54-
55-
impl<'a, T: Into<f64>> From<(&'a str, T)> for FontDesc<'a> {
56-
fn from((typeface, size): (&'a str, T)) -> FontDesc<'a> {
57-
FontDesc::new(typeface.into(), size.into(), FontStyle::Normal)
58-
}
59-
}
60-
61-
impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(FontFamily<'a>, T, S)> for FontDesc<'a> {
62-
fn from((family, size, style): (FontFamily<'a>, T, S)) -> FontDesc<'a> {
63-
FontDesc::new(family, size.into(), style.into())
64-
}
65-
}
66-
67-
impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(&'a str, T, S)> for FontDesc<'a> {
68-
fn from((typeface, size, style): (&'a str, T, S)) -> FontDesc<'a> {
69-
FontDesc::new(typeface.into(), size.into(), style.into())
70-
}
71-
}
72-
73-
/// The trait that allows some type turns into a font description
74-
pub trait IntoFont<'a> {
75-
/// Make the font description from the source type
76-
fn into_font(self) -> FontDesc<'a>;
77-
}
78-
79-
impl<'a, T: Into<FontDesc<'a>>> IntoFont<'a> for T {
80-
fn into_font(self) -> FontDesc<'a> {
81-
self.into()
82-
}
83-
}
84-
8525
impl<'a> FontDesc<'a> {
8626
/// Create a new font
8727
///
@@ -207,3 +147,51 @@ impl<'a> FontDesc<'a> {
207147
}
208148
}
209149
}
150+
151+
impl<'a> From<&'a str> for FontDesc<'a> {
152+
fn from(from: &'a str) -> FontDesc<'a> {
153+
FontDesc::new(from.into(), 12.0, FontStyle::Normal)
154+
}
155+
}
156+
157+
impl<'a> From<FontFamily<'a>> for FontDesc<'a> {
158+
fn from(family: FontFamily<'a>) -> FontDesc<'a> {
159+
FontDesc::new(family, 12.0, FontStyle::Normal)
160+
}
161+
}
162+
163+
impl<'a, T: Into<f64>> From<(FontFamily<'a>, T)> for FontDesc<'a> {
164+
fn from((family, size): (FontFamily<'a>, T)) -> FontDesc<'a> {
165+
FontDesc::new(family, size.into(), FontStyle::Normal)
166+
}
167+
}
168+
169+
impl<'a, T: Into<f64>> From<(&'a str, T)> for FontDesc<'a> {
170+
fn from((typeface, size): (&'a str, T)) -> FontDesc<'a> {
171+
FontDesc::new(typeface.into(), size.into(), FontStyle::Normal)
172+
}
173+
}
174+
175+
impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(FontFamily<'a>, T, S)> for FontDesc<'a> {
176+
fn from((family, size, style): (FontFamily<'a>, T, S)) -> FontDesc<'a> {
177+
FontDesc::new(family, size.into(), style.into())
178+
}
179+
}
180+
181+
impl<'a, T: Into<f64>, S: Into<FontStyle>> From<(&'a str, T, S)> for FontDesc<'a> {
182+
fn from((typeface, size, style): (&'a str, T, S)) -> FontDesc<'a> {
183+
FontDesc::new(typeface.into(), size.into(), style.into())
184+
}
185+
}
186+
187+
/// The trait that allows some type turns into a font description
188+
pub trait IntoFont<'a> {
189+
/// Make the font description from the source type
190+
fn into_font(self) -> FontDesc<'a>;
191+
}
192+
193+
impl<'a, T: Into<FontDesc<'a>>> IntoFont<'a> for T {
194+
fn into_font(self) -> FontDesc<'a> {
195+
self.into()
196+
}
197+
}

src/style/size.rs

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ impl SizeDesc for u32 {
4545
}
4646
}
4747

48+
impl SizeDesc for f32 {
49+
fn in_pixels<D: HasDimension>(&self, _parent: &D) -> i32 {
50+
*self as i32
51+
}
52+
}
53+
54+
55+
impl SizeDesc for f64 {
56+
fn in_pixels<D: HasDimension>(&self, _parent: &D) -> i32 {
57+
*self as i32
58+
}
59+
}
60+
4861
/// Describes a relative size, might be
4962
/// 1. portion of height
5063
/// 2. portion of width

0 commit comments

Comments
 (0)