Skip to content

Commit 9fe17bf

Browse files
SiegeLordExSiegeLord
authored andcommitted
Add a code example for the readme.
1 parent abb243b commit 9fe17bf

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
build
22
target
33
Cargo.lock
4-
*.png
5-
*.pdf
6-
*.gnuplot
4+
/*.png
5+
/*.pdf
6+
/*.gnuplot

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,10 @@ path = "examples/lines_points_3d.rs"
7070

7171
[[example]]
7272

73+
name = "readme_example"
74+
path = "examples/readme_example.rs"
75+
76+
[[example]]
77+
7378
name = "time"
7479
path = "examples/time.rs"

Readme.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@ See [here](http://siegelord.github.io/RustGnuplot/doc/gnuplot/index.html)
1111

1212
## Examples
1313

14-
A somewhat involved 2D example:
14+
A simple example:
15+
16+
```rust
17+
let mut fg = Figure::new();
18+
fg.axes2d()
19+
.set_title("A plot", &[])
20+
.set_legend(Graph(0.5), Graph(0.9), &[], &[])
21+
.set_x_label("x", &[])
22+
.set_y_label("y^2", &[])
23+
.lines(
24+
&[-3., -2., -1., 0., 1., 2., 3.],
25+
&[9., 4., 1., 0., 1., 4., 9.],
26+
&[Caption("Parabola")],
27+
);
28+
fg.show();
29+
```
30+
31+
![Simple example plot](doc/fg.readme_example.png)
32+
33+
A somewhat involved 2D example (see `example1.rs` in the `examples` directory):
1534

16-
![2D Example plot](doc/fg1.1.png)
35+
![Complicated example plot](doc/fg1.1.png)
1736

1837
## Features
1938

doc/fg.readme_example.png

18.1 KB
Loading

examples/readme_example.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This file is released into Public Domain.
2+
extern crate gnuplot;
3+
4+
use common::*;
5+
6+
use gnuplot::*;
7+
use std::iter::repeat;
8+
9+
mod common;
10+
11+
fn example(c: Common)
12+
{
13+
let mut fg = Figure::new();
14+
c.set_term(&mut fg);
15+
16+
fg.axes2d()
17+
.set_title("A plot", &[])
18+
.set_legend(Graph(0.5), Graph(0.9), &[], &[])
19+
.set_x_label("x", &[])
20+
.set_y_label("y^2", &[])
21+
.lines(
22+
&[-3., -2., -1., 0., 1., 2., 3.],
23+
&[9., 4., 1., 0., 1., 4., 9.],
24+
&[Caption("Parabola")],
25+
);
26+
27+
c.show(&mut fg, "fg.readme_example.gnuplot");
28+
if !c.no_show
29+
{
30+
fg.set_terminal("pngcairo", "fg.readme_example.png");
31+
fg.show();
32+
}
33+
}
34+
35+
fn main()
36+
{
37+
Common::new().map(|c| example(c));
38+
}

src/options.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pub use self::AlignType::*;
66
pub use self::ArrowheadType::*;
77
pub use self::AutoOption::*;
88
pub use self::BorderLocation2D::*;
9-
pub use self::MarginSide::*;
109
pub use self::ContourStyle::*;
1110
pub use self::DashType::*;
1211
pub use self::FillRegionType::*;
1312
pub use self::LabelOption::*;
1413
pub use self::LegendOption::*;
14+
pub use self::MarginSide::*;
1515
pub use self::PaletteType::*;
1616
pub use self::PlotOption::*;
1717
pub use self::Tick::*;
@@ -302,7 +302,8 @@ pub enum BorderLocation2D
302302

303303
/// Plot margins
304304
#[derive(Copy, Clone)]
305-
pub enum MarginSide {
305+
pub enum MarginSide
306+
{
306307
MarginTop(f32),
307308
MarginBottom(f32),
308309
MarginLeft(f32),

0 commit comments

Comments
 (0)