Skip to content

Commit 2a36ad8

Browse files
committed
Add some basic documentation
1 parent c4f5e95 commit 2a36ad8

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

src/plot.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*!
2+
The `plot` module provides structures for laying out and rendering multiple views.
3+
*/
4+
15
use std::path::Path;
26
use std::ffi::OsStr;
37

@@ -7,19 +11,28 @@ use svg::Document;
711

812
use view::View;
913

14+
/**
15+
A single page plot laying out the views in a grid
16+
*/
1017
pub struct Plot<'a> {
11-
pub views: Vec<&'a View<'a>>,
18+
views: Vec<&'a View<'a>>,
1219
num_views: u32,
1320
}
1421

1522
impl<'a> Plot<'a> {
23+
/**
24+
Creates a plot containing a single view
25+
*/
1626
pub fn single(view: &'a View) -> Self {
1727
Plot {
1828
views: vec![view],
1929
num_views: 1,
2030
}
2131
}
2232

33+
/**
34+
Render the plot to an svg document
35+
*/
2336
pub fn to_svg(&self) -> svg::Document {
2437
let mut document = Document::new().set("viewBox", (0, 0, 600, 400));
2538
for &view in self.views.iter() {
@@ -30,12 +43,21 @@ impl<'a> Plot<'a> {
3043
document
3144
}
3245

46+
/**
47+
Render the plot to an `String`
48+
*/
3349
pub fn to_text(&self) -> String {
3450
// TODO compose multiple views into a plot
3551
let view = self.views[0];
3652
view.to_text(90, 30)
3753
}
3854

55+
/**
56+
Save the plot to a file.
57+
58+
The type of file will be based on the file extension.
59+
*/
60+
3961
pub fn save<P>(&self, path: P)
4062
where P: AsRef<Path>
4163
{

src/scatter.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use svg_render;
77
use text_render;
88
use representation::Representation;
99

10+
/**
11+
The marker that should be used for the points of the scatter plot
12+
*/
1013
#[derive(Debug,Clone)]
1114
pub enum Marker {
1215
Circle,
@@ -43,7 +46,9 @@ impl Style {
4346
}
4447
}
4548

46-
pub fn marker<T>(mut self, value: T) -> Self where T: Into<Marker> {
49+
pub fn marker<T>(mut self, value: T) -> Self
50+
where T: Into<Marker>
51+
{
4752
self.marker = Some(value.into());
4853
self
4954
}
@@ -55,7 +60,9 @@ impl Style {
5560
}
5661
}
5762

58-
pub fn colour<T>(mut self, value: T) -> Self where T: Into<String> {
63+
pub fn colour<T>(mut self, value: T) -> Self
64+
where T: Into<String>
65+
{
5966
self.colour = Some(value.into());
6067
self
6168
}

src/view.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*!
2+
The `view` module provides structures for showing data in various ways.
3+
*/
4+
15
use std;
26
use std::f64;
37

@@ -17,6 +21,9 @@ pub struct View<'a> {
1721
}
1822

1923
impl<'a> View<'a> {
24+
/**
25+
Create an empty view
26+
*/
2027
pub fn new() -> View<'a> {
2128
View {
2229
representations: vec![],
@@ -25,16 +32,25 @@ impl<'a> View<'a> {
2532
}
2633
}
2734

35+
/**
36+
Add a representation to the view
37+
*/
2838
pub fn add(mut self, repr: &'a Representation) -> Self {
2939
self.representations.push(repr);
3040
self
3141
}
3242

43+
/**
44+
Set the x range for the view
45+
*/
3346
pub fn x_range(mut self, min: f64, max: f64) -> Self {
3447
self.x_range = Some(axis::Range::new(min, max));
3548
self
3649
}
3750

51+
/**
52+
Set the y range for the view
53+
*/
3854
pub fn y_range(mut self, min: f64, max: f64) -> Self {
3955
self.y_range = Some(axis::Range::new(min, max));
4056
self
@@ -62,6 +78,9 @@ impl<'a> View<'a> {
6278
axis::Range::new(y_min, y_max)
6379
}
6480

81+
/**
82+
Create an SVG rendering of the view
83+
*/
6584
pub fn to_svg(&self, face_width: f64, face_height: f64) -> svg::node::element::Group {
6685
let mut view_group = svg::node::element::Group::new();
6786

@@ -86,6 +105,9 @@ impl<'a> View<'a> {
86105
view_group
87106
}
88107

108+
/**
109+
Create a text rendering of the view
110+
*/
89111
pub fn to_text(&self, face_width: u32, face_height: u32) -> String {
90112
let default_x_range = self.default_x_range();
91113
let x_range = self.x_range.as_ref().unwrap_or(&default_x_range);

0 commit comments

Comments
 (0)