Skip to content

Commit fb2619f

Browse files
committed
fmt
1 parent 52ccc32 commit fb2619f

File tree

12 files changed

+482
-305
lines changed

12 files changed

+482
-305
lines changed

examples/scatter_svg.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
extern crate plotlib;
22

33
fn main() {
4-
let data = [(-3.0, 2.3), (-1.6, 5.3), (0.3, 0.7), (4.3, -1.4), (6.4, 4.3), (8.5, 3.7)];
5-
let s1 = plotlib::scatter::Scatter::from_vec(&data).style(plotlib::scatter::Style::new()
6-
.marker(plotlib::scatter::Marker::Square)
7-
.colour("#DD3355"));
4+
let data = [
5+
(-3.0, 2.3),
6+
(-1.6, 5.3),
7+
(0.3, 0.7),
8+
(4.3, -1.4),
9+
(6.4, 4.3),
10+
(8.5, 3.7),
11+
];
12+
let s1 = plotlib::scatter::Scatter::from_vec(&data).style(
13+
plotlib::scatter::Style::new()
14+
.marker(plotlib::scatter::Marker::Square)
15+
.colour("#DD3355"),
16+
);
817
let s2 = plotlib::scatter::Scatter::from_vec(&[(-1.4, 2.5), (7.2, -0.3)])
918
.style(plotlib::scatter::Style::new().colour("#35C788"));
1019
let v = plotlib::view::View::new()

examples/scatter_text.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
extern crate plotlib;
22

33
fn main() {
4-
let data = [(-3.0, 2.3), (-1.6, 5.3), (0.3, 0.7), (4.3, -1.4), (6.4, 4.3), (8.5, 3.7)];
4+
let data = [
5+
(-3.0, 2.3),
6+
(-1.6, 5.3),
7+
(0.3, 0.7),
8+
(4.3, -1.4),
9+
(6.4, 4.3),
10+
(8.5, 3.7),
11+
];
512
let s1 = plotlib::scatter::Scatter::from_vec(&data);
613
let s2 = plotlib::scatter::Scatter::from_vec(&[(-1.4, 2.5), (7.2, -0.3)])
714
.style(plotlib::scatter::Style::new().marker(plotlib::scatter::Marker::Square));

src/axis.rs

Lines changed: 112 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A module for managing axes
44
55
*/
66

7-
#[derive(Debug,Clone)]
7+
#[derive(Debug, Clone)]
88
pub struct Range {
99
pub lower: f64,
1010
pub upper: f64,
@@ -47,7 +47,8 @@ impl Axis {
4747
}
4848

4949
pub fn label<S>(mut self, l: S) -> Self
50-
where S: Into<String>
50+
where
51+
S: Into<String>,
5152
{
5253
self.label = l.into();
5354
self
@@ -67,7 +68,7 @@ impl Axis {
6768
/// They should be within one order of magnitude, e.g. [1,10)
6869
const BASE_STEPS: [u32; 4] = [1, 2, 4, 5];
6970

70-
#[derive(Debug,Clone)]
71+
#[derive(Debug, Clone)]
7172
struct TickSteps {
7273
next: f64,
7374
}
@@ -76,15 +77,23 @@ impl TickSteps {
7677
fn start_at(start: f64) -> TickSteps {
7778
let start_options = TickSteps::scaled_steps(start);
7879
let overflow = start_options[0] * 10.0;
79-
let curr = start_options.iter().skip_while(|&step| step < &start).next();
80+
let curr = start_options
81+
.iter()
82+
.skip_while(|&step| step < &start)
83+
.next();
8084

81-
TickSteps { next: *curr.unwrap_or(&overflow) }
85+
TickSteps {
86+
next: *curr.unwrap_or(&overflow),
87+
}
8288
}
8389

8490
fn scaled_steps(curr: f64) -> Vec<f64> {
8591
let power = curr.log10().floor();
8692
let base_step_scale = 10f64.powf(power);
87-
BASE_STEPS.iter().map(|&s| (s as f64 * base_step_scale)).collect()
93+
BASE_STEPS
94+
.iter()
95+
.map(|&s| (s as f64 * base_step_scale))
96+
.collect()
8897
}
8998
}
9099

@@ -95,7 +104,11 @@ impl Iterator for TickSteps {
95104
let curr = self.next; // cache the value we're currently on
96105
let curr_steps = TickSteps::scaled_steps(self.next);
97106
let overflow = curr_steps[0] * 10.0;
98-
self.next = *curr_steps.iter().skip_while(|&s| s <= &curr).next().unwrap_or(&overflow);
107+
self.next = *curr_steps
108+
.iter()
109+
.skip_while(|&s| s <= &curr)
110+
.next()
111+
.unwrap_or(&overflow);
99112
Some(curr)
100113
}
101114
}
@@ -105,30 +118,40 @@ fn generate_ticks(min: f64, max: f64, step_size: f64) -> Vec<f64> {
105118
if min <= 0.0 {
106119
if max >= 0.0 {
107120
// standard spanning axis
108-
ticks.extend((1..)
109-
.map(|n| -1.0 * n as f64 * step_size)
110-
.take_while(|&v| v >= min)
111-
.collect::<Vec<f64>>()
112-
.iter()
113-
.rev());
121+
ticks.extend(
122+
(1..)
123+
.map(|n| -1.0 * n as f64 * step_size)
124+
.take_while(|&v| v >= min)
125+
.collect::<Vec<f64>>()
126+
.iter()
127+
.rev(),
128+
);
114129
ticks.push(0.0);
115-
ticks.extend((1..).map(|n| n as f64 * step_size).take_while(|&v| v <= max));
130+
ticks.extend(
131+
(1..)
132+
.map(|n| n as f64 * step_size)
133+
.take_while(|&v| v <= max),
134+
);
116135
} else {
117136
// entirely negative axis
118-
ticks.extend((1..)
119-
.map(|n| -1.0 * n as f64 * step_size)
120-
.skip_while(|&v| v > max)
121-
.take_while(|&v| v >= min)
122-
.collect::<Vec<f64>>()
123-
.iter()
124-
.rev());
137+
ticks.extend(
138+
(1..)
139+
.map(|n| -1.0 * n as f64 * step_size)
140+
.skip_while(|&v| v > max)
141+
.take_while(|&v| v >= min)
142+
.collect::<Vec<f64>>()
143+
.iter()
144+
.rev(),
145+
);
125146
}
126147
} else {
127148
// entirely positive axis
128-
ticks.extend((1..)
129-
.map(|n| n as f64 * step_size)
130-
.skip_while(|&v| v < min)
131-
.take_while(|&v| v <= max));
149+
ticks.extend(
150+
(1..)
151+
.map(|n| n as f64 * step_size)
152+
.skip_while(|&v| v < min)
153+
.take_while(|&v| v <= max),
154+
);
132155
}
133156
ticks
134157
}
@@ -213,7 +236,6 @@ mod tests {
213236

214237
#[test]
215238
fn test_calculate_ticks() {
216-
217239
macro_rules! assert_approx_eq {
218240
($a:expr, $b:expr) => ({
219241
let (a, b) = (&$a, &$b);
@@ -224,12 +246,14 @@ mod tests {
224246

225247
for (prod, want) in calculate_ticks(0.0, 1.0, 6)
226248
.iter()
227-
.zip([0.0, 0.2, 0.4, 0.6, 0.8, 1.0].iter()) {
249+
.zip([0.0, 0.2, 0.4, 0.6, 0.8, 1.0].iter())
250+
{
228251
assert_approx_eq!(prod, want);
229252
}
230253
for (prod, want) in calculate_ticks(0.0, 2.0, 6)
231254
.iter()
232-
.zip([0.0, 0.4, 0.8, 1.2, 1.6, 2.0].iter()) {
255+
.zip([0.0, 0.4, 0.8, 1.2, 1.6, 2.0].iter())
256+
{
233257
assert_approx_eq!(prod, want);
234258
}
235259
assert_eq!(calculate_ticks(0.0, 3.0, 6), [0.0, 1.0, 2.0, 3.0]);
@@ -239,10 +263,14 @@ mod tests {
239263
assert_eq!(calculate_ticks(0.0, 7.0, 6), [0.0, 2.0, 4.0, 6.0]);
240264
assert_eq!(calculate_ticks(0.0, 8.0, 6), [0.0, 2.0, 4.0, 6.0, 8.0]);
241265
assert_eq!(calculate_ticks(0.0, 9.0, 6), [0.0, 2.0, 4.0, 6.0, 8.0]);
242-
assert_eq!(calculate_ticks(0.0, 10.0, 6),
243-
[0.0, 2.0, 4.0, 6.0, 8.0, 10.0]);
244-
assert_eq!(calculate_ticks(0.0, 11.0, 6),
245-
[0.0, 2.0, 4.0, 6.0, 8.0, 10.0]);
266+
assert_eq!(
267+
calculate_ticks(0.0, 10.0, 6),
268+
[0.0, 2.0, 4.0, 6.0, 8.0, 10.0]
269+
);
270+
assert_eq!(
271+
calculate_ticks(0.0, 11.0, 6),
272+
[0.0, 2.0, 4.0, 6.0, 8.0, 10.0]
273+
);
246274
assert_eq!(calculate_ticks(0.0, 12.0, 6), [0.0, 4.0, 8.0, 12.0]);
247275
assert_eq!(calculate_ticks(0.0, 13.0, 6), [0.0, 4.0, 8.0, 12.0]);
248276
assert_eq!(calculate_ticks(0.0, 14.0, 6), [0.0, 4.0, 8.0, 12.0]);
@@ -251,46 +279,72 @@ mod tests {
251279
assert_eq!(calculate_ticks(0.0, 17.0, 6), [0.0, 4.0, 8.0, 12.0, 16.0]);
252280
assert_eq!(calculate_ticks(0.0, 18.0, 6), [0.0, 4.0, 8.0, 12.0, 16.0]);
253281
assert_eq!(calculate_ticks(0.0, 19.0, 6), [0.0, 4.0, 8.0, 12.0, 16.0]);
254-
assert_eq!(calculate_ticks(0.0, 20.0, 6),
255-
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]);
256-
assert_eq!(calculate_ticks(0.0, 21.0, 6),
257-
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]);
258-
assert_eq!(calculate_ticks(0.0, 22.0, 6),
259-
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]);
260-
assert_eq!(calculate_ticks(0.0, 23.0, 6),
261-
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]);
282+
assert_eq!(
283+
calculate_ticks(0.0, 20.0, 6),
284+
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]
285+
);
286+
assert_eq!(
287+
calculate_ticks(0.0, 21.0, 6),
288+
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]
289+
);
290+
assert_eq!(
291+
calculate_ticks(0.0, 22.0, 6),
292+
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]
293+
);
294+
assert_eq!(
295+
calculate_ticks(0.0, 23.0, 6),
296+
[0.0, 4.0, 8.0, 12.0, 16.0, 20.0]
297+
);
262298
assert_eq!(calculate_ticks(0.0, 24.0, 6), [0.0, 5.0, 10.0, 15.0, 20.0]);
263-
assert_eq!(calculate_ticks(0.0, 25.0, 6),
264-
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]);
265-
assert_eq!(calculate_ticks(0.0, 26.0, 6),
266-
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]);
267-
assert_eq!(calculate_ticks(0.0, 27.0, 6),
268-
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]);
269-
assert_eq!(calculate_ticks(0.0, 28.0, 6),
270-
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]);
271-
assert_eq!(calculate_ticks(0.0, 29.0, 6),
272-
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]);
299+
assert_eq!(
300+
calculate_ticks(0.0, 25.0, 6),
301+
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]
302+
);
303+
assert_eq!(
304+
calculate_ticks(0.0, 26.0, 6),
305+
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]
306+
);
307+
assert_eq!(
308+
calculate_ticks(0.0, 27.0, 6),
309+
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]
310+
);
311+
assert_eq!(
312+
calculate_ticks(0.0, 28.0, 6),
313+
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]
314+
);
315+
assert_eq!(
316+
calculate_ticks(0.0, 29.0, 6),
317+
[0.0, 5.0, 10.0, 15.0, 20.0, 25.0]
318+
);
273319
assert_eq!(calculate_ticks(0.0, 30.0, 6), [0.0, 10.0, 20.0, 30.0]);
274320
assert_eq!(calculate_ticks(0.0, 31.0, 6), [0.0, 10.0, 20.0, 30.0]);
275321
//...
276322
assert_eq!(calculate_ticks(0.0, 40.0, 6), [0.0, 10.0, 20.0, 30.0, 40.0]);
277-
assert_eq!(calculate_ticks(0.0, 50.0, 6),
278-
[0.0, 10.0, 20.0, 30.0, 40.0, 50.0]);
323+
assert_eq!(
324+
calculate_ticks(0.0, 50.0, 6),
325+
[0.0, 10.0, 20.0, 30.0, 40.0, 50.0]
326+
);
279327
assert_eq!(calculate_ticks(0.0, 60.0, 6), [0.0, 20.0, 40.0, 60.0]);
280328
assert_eq!(calculate_ticks(0.0, 70.0, 6), [0.0, 20.0, 40.0, 60.0]);
281329
assert_eq!(calculate_ticks(0.0, 80.0, 6), [0.0, 20.0, 40.0, 60.0, 80.0]);
282330
assert_eq!(calculate_ticks(0.0, 90.0, 6), [0.0, 20.0, 40.0, 60.0, 80.0]);
283-
assert_eq!(calculate_ticks(0.0, 100.0, 6),
284-
[0.0, 20.0, 40.0, 60.0, 80.0, 100.0]);
285-
assert_eq!(calculate_ticks(0.0, 110.0, 6),
286-
[0.0, 20.0, 40.0, 60.0, 80.0, 100.0]);
331+
assert_eq!(
332+
calculate_ticks(0.0, 100.0, 6),
333+
[0.0, 20.0, 40.0, 60.0, 80.0, 100.0]
334+
);
335+
assert_eq!(
336+
calculate_ticks(0.0, 110.0, 6),
337+
[0.0, 20.0, 40.0, 60.0, 80.0, 100.0]
338+
);
287339
assert_eq!(calculate_ticks(0.0, 120.0, 6), [0.0, 40.0, 80.0, 120.0]);
288340
assert_eq!(calculate_ticks(0.0, 130.0, 6), [0.0, 40.0, 80.0, 120.0]);
289341
assert_eq!(calculate_ticks(0.0, 140.0, 6), [0.0, 40.0, 80.0, 120.0]);
290342
assert_eq!(calculate_ticks(0.0, 150.0, 6), [0.0, 50.0, 100.0, 150.0]);
291343
//...
292-
assert_eq!(calculate_ticks(0.0, 3475.0, 6),
293-
[0.0, 1000.0, 2000.0, 3000.0]);
344+
assert_eq!(
345+
calculate_ticks(0.0, 3475.0, 6),
346+
[0.0, 1000.0, 2000.0, 3000.0]
347+
);
294348

295349
assert_eq!(calculate_ticks(-10.0, -3.0, 6), [-10.0, -8.0, -6.0, -4.0]);
296350
}

src/function.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ pub struct Style {
2828

2929
impl Style {
3030
pub fn new() -> Self {
31-
Style {
32-
colour: None,
33-
}
31+
Style { colour: None }
3432
}
3533

3634
pub fn overlay(&mut self, other: Self) {
@@ -41,7 +39,8 @@ impl Style {
4139
}
4240

4341
pub fn colour<T>(mut self, value: T) -> Self
44-
where T: Into<String>
42+
where
43+
T: Into<String>,
4544
{
4645
self.colour = Some(value.into());
4746
self
@@ -62,9 +61,13 @@ pub struct Function {
6261

6362
impl Function {
6463
pub fn new<F>(f: F, lower: f64, upper: f64) -> Self
65-
where F: Fn(f64) -> f64 {
64+
where
65+
F: Fn(f64) -> f64,
66+
{
6667
let sampling = (upper - lower) / 200.;
67-
let samples = (0..).map(|x| lower + (x as f64 * sampling)).take_while(|&x| x <= upper);
68+
let samples = (0..)
69+
.map(|x| lower + (x as f64 * sampling))
70+
.take_while(|&x| x <= upper);
6871
let values = samples.map(|s| (s, f(s))).collect();
6972
Function {
7073
data: values,
@@ -111,21 +114,23 @@ impl Representation for Function {
111114
}
112115
}
113116

114-
fn to_svg(&self,
115-
x_axis: &axis::Axis,
116-
y_axis: &axis::Axis,
117-
face_width: f64,
118-
face_height: f64)
119-
-> svg::node::element::Group {
117+
fn to_svg(
118+
&self,
119+
x_axis: &axis::Axis,
120+
y_axis: &axis::Axis,
121+
face_width: f64,
122+
face_height: f64,
123+
) -> svg::node::element::Group {
120124
svg_render::draw_face_line(self, x_axis, y_axis, face_width, face_height, &self.style)
121125
}
122126

123-
fn to_text(&self,
124-
x_axis: &axis::Axis,
125-
y_axis: &axis::Axis,
126-
face_width: u32,
127-
face_height: u32)
128-
-> String {
127+
fn to_text(
128+
&self,
129+
x_axis: &axis::Axis,
130+
y_axis: &axis::Axis,
131+
face_width: u32,
132+
face_height: u32,
133+
) -> String {
129134
"".into()
130135
}
131136
}

0 commit comments

Comments
 (0)