Skip to content

Commit 8e891c9

Browse files
committed
Add stub for scatter plotting
1 parent 050c2d7 commit 8e891c9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ Data structures and helpers for managing plotting data
55
*/
66

77
pub mod histogram;
8+
pub mod scatter;
89
pub mod axis;
910
pub mod utils;

src/scatter.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use std::f64;
2+
3+
use axis;
4+
5+
#[derive(Debug)]
6+
pub struct Scatter {
7+
pub data: Vec<(f64, f64)>,
8+
pub x_axis: axis::Axis,
9+
pub y_axis: axis::Axis,
10+
}
11+
12+
impl Scatter {
13+
pub fn from_vec(v: &[(f64, f64)]) -> Scatter {
14+
15+
let mut x_min = f64::INFINITY;
16+
let mut x_max = f64::NEG_INFINITY;
17+
let mut y_min = f64::INFINITY;
18+
let mut y_max = f64::NEG_INFINITY;
19+
let mut data: Vec<(f64, f64)> = vec![];
20+
for &(x, y) in v {
21+
x_min = x_min.min(x);
22+
x_max = x_max.max(x);
23+
y_min = y_min.min(y);
24+
y_max = y_max.max(y);
25+
data.push((x, y));
26+
}
27+
28+
let x_axis = axis::Axis::new(x_min, x_max);
29+
let y_axis = axis::Axis::new(y_min, y_max);
30+
31+
Scatter {
32+
data: data,
33+
x_axis: x_axis,
34+
y_axis: y_axis,
35+
}
36+
}
37+
}
38+

0 commit comments

Comments
 (0)