@@ -7,8 +7,43 @@ use representation::Representation;
77
88use svg_render;
99
10+ #[ derive( Debug ) ]
11+ pub struct Style {
12+ colour : Option < String > ,
13+ }
14+
15+ impl Style {
16+ pub fn new ( ) -> Self {
17+ Style {
18+ colour : None ,
19+ }
20+ }
21+
22+ pub fn overlay ( & mut self , other : Self ) {
23+ match other. colour {
24+ Some ( v) => self . colour = Some ( v) ,
25+ None => { }
26+ }
27+ }
28+
29+ pub fn colour < T > ( mut self , value : T ) -> Self
30+ where T : Into < String >
31+ {
32+ self . colour = Some ( value. into ( ) ) ;
33+ self
34+ }
35+
36+ pub fn get_colour ( & self ) -> String {
37+ match self . colour . clone ( ) {
38+ Some ( v) => v,
39+ None => "" . into ( ) ,
40+ }
41+ }
42+ }
43+
1044pub struct Function {
1145 pub data : Vec < ( f64 , f64 ) > ,
46+ style : Style ,
1247}
1348
1449impl Function {
@@ -19,9 +54,19 @@ impl Function {
1954 let values = samples. map ( |s| ( s, f ( s) ) ) . collect ( ) ;
2055 Function {
2156 data : values,
57+ style : Style :: new ( ) ,
2258 }
2359 }
2460
61+ pub fn style ( mut self , style : Style ) -> Self {
62+ self . style . overlay ( style) ;
63+ self
64+ }
65+
66+ pub fn get_style ( & self ) -> & Style {
67+ & self . style
68+ }
69+
2570 fn x_range ( & self ) -> ( f64 , f64 ) {
2671 let mut min = f64:: INFINITY ;
2772 let mut max = f64:: NEG_INFINITY ;
@@ -58,7 +103,7 @@ impl Representation for Function {
58103 face_width : f64 ,
59104 face_height : f64 )
60105 -> svg:: node:: element:: Group {
61- svg_render:: draw_face_line ( self , x_axis, y_axis, face_width, face_height)
106+ svg_render:: draw_face_line ( self , x_axis, y_axis, face_width, face_height, & self . style )
62107 }
63108
64109 fn to_text ( & self ,
0 commit comments