Skip to content

Commit d800af0

Browse files
committed
Add documentation for defining a new coordinate
1 parent 4021179 commit d800af0

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/coord/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ easily.
1212
Another important trait is [ReverseCoordTranslate](trait.ReverseCoordTranslate.html). This trait allows some coordinate
1313
retrieve the logic value based on the pixel-based backend coordinate. This is particularly interesting for interactive plots.
1414
15+
Plotters contains a set of pre-defined coordinate specifications that fulfills the most common use. See documentation for
16+
module [types](types/index.html) for details about the basic 1D types.
17+
18+
The coordinate system also can be tweaked by the coordinate combinators, such as logarithmic coordinate, nested coordinate, etc.
19+
See documentation for module [combinators](combinators/index.html) for details.
20+
21+
Currently we support the following 2D coordinate system:
22+
23+
- 2-dimensional Cartesian Coordinate: This is done by the combinator [Cartesian2d](cartesian/struct.Cartesian2d.html).
24+
1525
*/
1626

1727
use plotters_backend::BackendCoord;

src/coord/ranged1d/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
/*!
2+
The one-dimensional coordinate system abstraction.
3+
4+
Plotters build complex coordinate system with a combinator pattern and all the coordinate system is
5+
built from the one dimensional coordinate system. This module defines the fundamental types used by
6+
the one-dimensional coordinate system.
7+
8+
The key trait for a one dimensional coordinate is [Ranged](trait.Ranged.html). This trait describes a
9+
set of values which served as the 1D coordinate system in Plotters. In order to extend the coordinate system,
10+
the new coordinate spec must implement this trait.
11+
12+
The following example demonstrate how to make a customized coordinate specification
13+
```
14+
use plotters::coord::ranged1d::{Ranged, DefaultFormatting, KeyPointHint};
15+
use std::ops::Range;
16+
17+
struct ZeroToOne;
18+
19+
impl Ranged for ZeroToOne {
20+
type ValueType = f64;
21+
type FormatOption = DefaultFormatting;
22+
23+
fn map(&self, &v: &f64, pixel_range: (i32, i32)) -> i32 {
24+
let size = pixel_range.1 - pixel_range.0;
25+
let v = v.min(1.0).max(0.0);
26+
((size as f64) * v).round() as i32
27+
}
28+
29+
fn key_points<Hint:KeyPointHint>(&self, hint: Hint) -> Vec<f64> {
30+
if hint.max_num_points() < 3 {
31+
vec![]
32+
} else {
33+
vec![0.0, 0.5, 1.0]
34+
}
35+
}
36+
37+
fn range(&self) -> Range<f64> {
38+
0.0..1.0
39+
}
40+
}
41+
42+
use plotters::prelude::*;
43+
44+
let mut buffer = vec![0; 1024 * 768 * 3];
45+
let root = BitMapBackend::with_buffer(&mut buffer, (1024, 768)).into_drawing_area();
46+
47+
let chart = ChartBuilder::on(&root)
48+
.build_cartesian_2d(ZeroToOne, ZeroToOne)
49+
.unwrap();
50+
51+
```
52+
*/
153
use std::fmt::Debug;
254
use std::ops::Range;
355

0 commit comments

Comments
 (0)