1+ #![ deny( missing_docs) ]
2+
3+ //! Configure a grid on a plot.
4+ //!
5+ //! Grids allow for easier estimating of data values. This module allows the configuration of grids
6+ //! on plots.
7+ //!
8+ //! Grids are created by creating a `Grid` definition, and adding it to a plot:
9+ //!
10+ //! The grid lines for `plotlib` are rendered
11+ //! _underneath_ the data so as to not detract from the data.
12+ //!
13+ //! # Examples
14+ //!
15+ //! ```rust
16+ //! # use plotlib::view::ContinuousView;
17+ //! use plotlib::grid::Grid;
18+ //! # use plotlib::style::Line;
19+ //! # use plotlib::view::View;
20+ //!
21+ //! # let l1 = plotlib::line::Line::new(&[(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)])
22+ //! # .style(plotlib::line::Style::new().colour("burlywood"));
23+ //! // let l1 = Line::new() ...
24+ //! let mut v = ContinuousView::new().add(&l1);
25+ //!
26+ //! // 3 vertical lines and 8 horizontal lines
27+ //! v.add_grid(Grid::new(3, 8));
28+ //!
29+ //! // Render plot
30+ //! ```
31+
32+ // Internal type representing the logic of when do we render only horizontal lines, and when do we
33+ // render a full grid
134pub ( crate ) enum GridType < ' a > {
235 HorizontalOnly ( & ' a Grid ) ,
336 Both ( & ' a Grid ) ,
437}
538
39+ /// Configuration for the grid on a plot
40+ ///
41+ /// Supports changing the number of grid lines for the x and y dimensions.
42+ /// **Note:** for categorical plots, only horizontal lines will be shown.
643pub struct Grid {
44+ /// Number of vertical grid lines (defaults to 3)
745 pub nx : u32 ,
46+ /// Number of horizontal grid lines (defaults to 3)
847 pub ny : u32 ,
48+ /// Color of the grid lines (defaults to "darkgrey")
949 pub color : String ,
1050}
1151
@@ -16,6 +56,9 @@ impl Default for Grid {
1656}
1757
1858impl Grid {
59+ /// Create a new grid with `nx` vertical and `ny` horizontal grid lines
60+ ///
61+ /// The default colour is "darkgrey".
1962 pub fn new ( nx : u32 , ny : u32 ) -> Grid {
2063 Grid {
2164 nx,
0 commit comments