@@ -4,7 +4,7 @@ use svg::node;
44use svg:: Node ;
55
66use crate :: axis;
7- use crate :: grid:: Grid ;
7+ use crate :: grid:: GridType ;
88use crate :: histogram;
99use crate :: style;
1010use crate :: utils;
@@ -448,28 +448,45 @@ where
448448 group
449449}
450450
451- pub ( crate ) fn draw_grid ( grid : & Grid , face_width : f64 , face_height : f64 ) -> node:: element:: Group {
452- let ( xmin, xmax) = ( 0f64 , face_width) ;
453- let ( ymin, ymax) = ( 0f64 , face_height) ;
451+ pub ( crate ) fn draw_grid ( grid : GridType , face_width : f64 , face_height : f64 ) -> node:: element:: Group {
452+ match grid {
453+ GridType :: HorizontalOnly ( grid) => {
454+ let ( ymin, ymax) = ( 0f64 , face_height) ;
455+ let y_step = ( ymax - ymin) / f64:: from ( grid. ny ) ;
456+ let mut lines = node:: element:: Group :: new ( ) ;
457+
458+ for iy in 0 ..=grid. ny {
459+ let y = f64:: from ( iy) * y_step + ymin;
460+ let line = horizontal_line ( -y, 0.0 , face_width, grid. color . as_str ( ) ) ;
461+ lines = lines. add ( line) ;
462+ }
454463
455- let x_step = ( xmax - xmin) / f64:: from ( grid. nx ) ;
456- let y_step = ( ymax - ymin) / f64:: from ( grid. ny ) ;
464+ lines
465+ }
466+ GridType :: Both ( grid) => {
467+ let ( xmin, xmax) = ( 0f64 , face_width) ;
468+ let ( ymin, ymax) = ( 0f64 , face_height) ;
457469
458- let mut lines = node:: element:: Group :: new ( ) ;
470+ let x_step = ( xmax - xmin) / f64:: from ( grid. nx ) ;
471+ let y_step = ( ymax - ymin) / f64:: from ( grid. ny ) ;
459472
460- for iy in 0 ..=grid. ny {
461- let y = f64:: from ( iy) * y_step + ymin;
462- let line = horizontal_line ( -y, 0.0 , face_width, grid. color . as_str ( ) ) ;
463- lines = lines. add ( line) ;
464- }
473+ let mut lines = node:: element:: Group :: new ( ) ;
465474
466- for ix in 0 ..=grid. nx {
467- let x = f64:: from ( ix ) * x_step + xmin ;
468- let line = vertical_line ( x , 0.0 , -face_height , grid. color . as_str ( ) ) ;
469- lines = lines. add ( line) ;
470- }
475+ for iy in 0 ..=grid. ny {
476+ let y = f64:: from ( iy ) * y_step + ymin ;
477+ let line = horizontal_line ( -y , 0.0 , face_width , grid. color . as_str ( ) ) ;
478+ lines = lines. add ( line) ;
479+ }
471480
472- lines
481+ for ix in 0 ..=grid. nx {
482+ let x = f64:: from ( ix) * x_step + xmin;
483+ let line = vertical_line ( x, 0.0 , -face_height, grid. color . as_str ( ) ) ;
484+ lines = lines. add ( line) ;
485+ }
486+
487+ lines
488+ }
489+ }
473490}
474491
475492#[ cfg( test) ]
0 commit comments