@@ -13,10 +13,15 @@ pub enum Marker {
1313 Square ,
1414}
1515
16- #[ derive( Debug , Clone ) ]
16+ /// `Style` follows the 'optional builder' pattern
17+ /// Each field is a `Option` which start as `None`
18+ /// Each can be set with setter methods and instances
19+ /// of `Style` can be overlaid to set many at once.
20+ /// Settings will be cloned in and out of it.
21+ #[ derive( Debug ) ]
1722pub struct Style {
18- pub marker : Option < Marker > ,
19- pub colour : Option < String > ,
23+ marker : Option < Marker > ,
24+ colour : Option < String > ,
2025}
2126
2227impl Style {
@@ -27,16 +32,38 @@ impl Style {
2732 }
2833 }
2934
30- pub fn fill_defaults ( & self ) -> Self {
31- Style {
32- marker : match self . marker {
33- Some ( ref m) => Some ( m. clone ( ) ) ,
34- None => Some ( Marker :: Circle ) ,
35- } ,
36- colour : match self . colour {
37- Some ( ref c) => Some ( c. clone ( ) ) ,
38- None => Some ( "" . into ( ) ) ,
39- }
35+ pub fn overlay ( & mut self , other : Self ) {
36+ match other. marker {
37+ Some ( v) => self . marker = Some ( v) ,
38+ None => { }
39+ }
40+ match other. colour {
41+ Some ( v) => self . colour = Some ( v) ,
42+ None => { }
43+ }
44+ }
45+
46+ pub fn marker ( mut self , value : Marker ) -> Self {
47+ self . marker = Some ( value) ;
48+ self
49+ }
50+
51+ pub fn get_marker ( & self ) -> Marker {
52+ match self . marker . clone ( ) {
53+ Some ( v) => v,
54+ None => Marker :: Circle ,
55+ }
56+ }
57+
58+ pub fn colour ( mut self , value : String ) -> Self {
59+ self . colour = Some ( value) ;
60+ self
61+ }
62+
63+ pub fn get_colour ( & self ) -> String {
64+ match self . colour . clone ( ) {
65+ Some ( v) => v,
66+ None => "" . into ( ) ,
4067 }
4168 }
4269}
@@ -63,12 +90,12 @@ impl Scatter {
6390 }
6491
6592 pub fn style ( mut self , style : Style ) -> Self {
66- self . style = style;
93+ self . style . overlay ( style) ;
6794 self
6895 }
6996
70- pub fn get_style ( & self ) -> Style {
71- self . style . clone ( )
97+ pub fn get_style ( & self ) -> & Style {
98+ & self . style
7299 }
73100
74101 fn x_range ( & self ) -> ( f64 , f64 ) {
@@ -97,7 +124,7 @@ impl Representation for Scatter {
97124 match dim {
98125 0 => self . x_range ( ) ,
99126 1 => self . y_range ( ) ,
100- _ => panic ! ( "Axis out of range" )
127+ _ => panic ! ( "Axis out of range" ) ,
101128 }
102129 }
103130
@@ -107,7 +134,7 @@ impl Representation for Scatter {
107134 face_width : f64 ,
108135 face_height : f64 )
109136 -> svg:: node:: element:: Group {
110- svg_render:: draw_face_points ( self , & x_axis, & y_axis, face_width, face_height, & self . style . fill_defaults ( ) )
137+ svg_render:: draw_face_points ( self , & x_axis, & y_axis, face_width, face_height, & self . style )
111138 }
112139
113140 fn to_text ( & self ,
@@ -116,6 +143,11 @@ impl Representation for Scatter {
116143 face_width : u32 ,
117144 face_height : u32 )
118145 -> String {
119- text_render:: render_face_points ( self , & x_axis, & y_axis, face_width, face_height, & self . style . fill_defaults ( ) )
146+ text_render:: render_face_points ( self ,
147+ & x_axis,
148+ & y_axis,
149+ face_width,
150+ face_height,
151+ & self . style )
120152 }
121153}
0 commit comments