File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ Data structures and helpers for managing plotting data
55*/
66
77pub mod histogram;
8+ pub mod scatter;
89pub mod axis;
910pub mod utils;
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments