File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed
Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ fn main() {
88 let f2 = plotlib:: function:: Function :: new ( |x| x. powi ( 2 ) , 0. , 10. )
99 . style ( plotlib:: function:: Style :: new ( ) . colour ( "darkolivegreen" ) ) ;
1010 let f3 = plotlib:: function:: Function :: new ( |x| x. sqrt ( ) * 20. , 0. , 10. )
11- . style ( plotlib:: function:: Style :: new ( ) . colour ( "brown" ) ) ;
11+ . style ( plotlib:: function:: Style :: new ( ) . colour ( "brown" ) . width ( 1 ) ) ;
1212 let v = plotlib:: view:: View :: new ( ) . add ( & f1) . add ( & f2) . add ( & f3) ;
1313 plotlib:: page:: Page :: single ( & v) . save ( "function.svg" ) ;
1414}
Original file line number Diff line number Diff line change @@ -25,18 +25,27 @@ use style;
2525#[ derive( Debug , Default ) ]
2626pub struct Style {
2727 colour : Option < String > ,
28+ width : Option < u8 > ,
2829}
2930
3031impl Style {
3132 pub fn new ( ) -> Self {
32- Style { colour : None }
33+ Style {
34+ colour : None ,
35+ width : None ,
36+ }
3337 }
3438
3539 pub fn overlay ( & mut self , other : & Self ) {
3640 match other. colour {
3741 Some ( ref v) => self . colour = Some ( v. clone ( ) ) ,
3842 None => { }
3943 }
44+
45+ match other. width {
46+ Some ( ref v) => self . width = Some ( v. clone ( ) ) ,
47+ None => { }
48+ }
4049 }
4150}
4251
@@ -52,6 +61,18 @@ impl style::Line for Style {
5261 fn get_colour ( & self ) -> & Option < String > {
5362 & self . colour
5463 }
64+
65+ fn width < T > ( & mut self , value : T ) -> & mut Self
66+ where
67+ T : Into < u8 > ,
68+ {
69+ self . width = Some ( value. into ( ) ) ;
70+ self
71+ }
72+
73+ fn get_width ( & self ) -> & Option < u8 > {
74+ & self . width
75+ }
5576}
5677
5778pub struct Function {
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ pub trait Line {
1010 T : Into < String > ;
1111
1212 fn get_colour ( & self ) -> & Option < String > ;
13+
14+ fn width < T > ( & mut self , value : T ) -> & mut Self
15+ where
16+ T : Into < u8 > ;
17+
18+ fn get_width ( & self ) -> & Option < u8 > ;
1319}
1420
1521/**
Original file line number Diff line number Diff line change @@ -231,7 +231,7 @@ where
231231 node:: element:: Path :: new ( )
232232 . set ( "fill" , "none" )
233233 . set ( "stroke" , style. get_colour ( ) . clone ( ) . unwrap_or ( "" . into ( ) ) )
234- . set ( "stroke-width" , 2 )
234+ . set ( "stroke-width" , style . get_width ( ) . clone ( ) . unwrap_or ( 2 ) )
235235 . set ( "d" , path) ,
236236 ) ;
237237
You can’t perform that action at this time.
0 commit comments