Skip to content

Commit 870ac3e

Browse files
committed
Update docs
1 parent 4bc70f1 commit 870ac3e

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

src/chart/axes3d.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::drawing::DrawingAreaErrorKind;
1313

1414
use plotters_backend::DrawingBackend;
1515

16+
/// The configurations about the 3D plot's axes
1617
pub struct Axes3dStyle<'a, 'b, X: Ranged, Y: Ranged, Z: Ranged, DB: DrawingBackend> {
1718
pub(super) parent_size: (u32, u32),
1819
pub(super) target: Option<&'b mut ChartContext<'a, DB, Cartesian3d<X, Y, Z>>>,
@@ -36,22 +37,26 @@ where
3637
Z: Ranged<ValueType = ZT> + ValueFormatter<ZT>,
3738
DB: DrawingBackend,
3839
{
40+
/// Set the size of the tick mark
3941
pub fn tick_size<Size: SizeDesc>(&mut self, size: Size) -> &mut Self {
4042
let actual_size = size.in_pixels(&self.parent_size);
4143
self.tick_size = actual_size;
4244
self
4345
}
4446

47+
/// Set the number of labels on the X axes
4548
pub fn x_labels(&mut self, n: usize) -> &mut Self {
4649
self.n_labels[0] = n;
4750
self
4851
}
4952

53+
/// Set the number of labels on the Y axes
5054
pub fn y_labels(&mut self, n: usize) -> &mut Self {
5155
self.n_labels[1] = n;
5256
self
5357
}
5458

59+
/// Set the number of labels on the Z axes
5560
pub fn z_labels(&mut self, n: usize) -> &mut Self {
5661
self.n_labels[2] = n;
5762
self

src/chart/builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
307307
})
308308
}
309309

310+
/// Build a 3 dimensional cartesian chart. The function will returns a chart
311+
/// context, where data series can be rendered on.
312+
/// - `x_spec`: The specification of X axis
313+
/// - `y_spec`: The specification of Y axis
314+
/// - `z_sepc`: The specification of Z axis
315+
/// - Returns: A chart context
310316
pub fn build_cartesian_3d<X: AsRangedCoord, Y: AsRangedCoord, Z: AsRangedCoord>(
311317
&mut self,
312318
x_spec: X,

src/chart/context.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ impl<'a, DB, X: Ranged, Y: Ranged, Z: Ranged> ChartContext<'a, DB, Cartesian3d<X
588588
where
589589
DB: DrawingBackend,
590590
{
591+
/// Override the 3D projection matrix. This function allows to override the default projection
592+
/// matrix.
593+
/// - `pf`: A function that takes the default projection matrix configuration and returns the
594+
/// projection matrix. This function will allow you to adjust the pitch, yaw angle and the
595+
/// centeral point of the projection, etc. You can also build a projection matrix which is not
596+
/// relies on the default configuration as well.
591597
pub fn with_projection<P: FnOnce(ProjectionMatrixBuilder) -> ProjectionMatrix>(
592598
&mut self,
593599
pf: P,
@@ -921,7 +927,6 @@ mod test {
921927
.expect("Drawing error");
922928
}
923929

924-
925930
#[test]
926931
fn test_chart_context_3d() {
927932
let drawing_area = create_mocked_drawing_area(200, 200, |_| {});
@@ -936,7 +941,7 @@ mod test {
936941
.set_label_area_size(LabelAreaPosition::Right, 20)
937942
.build_cartesian_3d(0..10, 0..10, 0..10)
938943
.expect("Create chart");
939-
944+
940945
chart.with_projection(|mut pb| {
941946
pb.yaw = 0.5;
942947
pb.pitch = 0.5;
@@ -946,7 +951,6 @@ mod test {
946951

947952
chart.configure_axes().draw().expect("Drawing axes");
948953

949-
950954
chart
951955
.draw_series(std::iter::once(Circle::new((5, 5, 5), 5, &RED)))
952956
.expect("Drawing error");

src/coord/ranged3d/cartesian3d.rs

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use plotters_backend::BackendCoord;
55

66
use std::ops::Range;
77

8+
/// A 3D cartesian coordinate system
89
pub struct Cartesian3d<X: Ranged, Y: Ranged, Z: Ranged> {
910
pub(crate) logic_x: X,
1011
pub(crate) logic_y: Y,
@@ -53,6 +54,7 @@ impl<X: Ranged, Y: Ranged, Z: Ranged> Cartesian3d<X, Y, Z> {
5354
projection: Self::create_projection(actual_x, actual_y, build_projection_matrix),
5455
}
5556
}
57+
/// Set the projection matrix
5658
pub fn set_projection<F: FnOnce(ProjectionMatrixBuilder) -> ProjectionMatrix>(
5759
&mut self,
5860
actual_x: Range<i32>,
@@ -63,6 +65,7 @@ impl<X: Ranged, Y: Ranged, Z: Ranged> Cartesian3d<X, Y, Z> {
6365
self
6466
}
6567

68+
/// Create a new coordinate
6669
pub fn new<SX: Into<X>, SY: Into<Y>, SZ: Into<Z>>(
6770
logic_x: SX,
6871
logic_y: SY,
@@ -73,10 +76,12 @@ impl<X: Ranged, Y: Ranged, Z: Ranged> Cartesian3d<X, Y, Z> {
7376
pb.into_matrix()
7477
})
7578
}
79+
/// Get the projection matrix
7680
pub fn projection(&self) -> &ProjectionMatrix {
7781
&self.projection
7882
}
7983

84+
/// Do not project, only transform the guest coordinate system
8085
pub fn map_3d(&self, x: &X::ValueType, y: &Y::ValueType, z: &Z::ValueType) -> (i32, i32, i32) {
8186
(
8287
self.logic_x.map(x, (0, self.coord_size.0)),
@@ -85,6 +90,7 @@ impl<X: Ranged, Y: Ranged, Z: Ranged> Cartesian3d<X, Y, Z> {
8590
)
8691
}
8792

93+
/// Get the depth of the projection
8894
pub fn projected_depth(&self, x: &X::ValueType, y: &Y::ValueType, z: &Z::ValueType) -> i32 {
8995
self.projection.projected_depth(self.map_3d(x, y, z))
9096
}

src/coord/ranged3d/projection.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::f64::consts::PI;
22
use std::ops::Mul;
33

4+
/// The projection matrix which is used to project the 3D space to the 2D display panel
45
#[derive(Clone, Debug, Copy)]
56
pub struct ProjectionMatrix([[f64; 4]; 4]);
67

@@ -68,6 +69,7 @@ impl Mul<(f64, f64, f64)> for ProjectionMatrix {
6869
}
6970

7071
impl ProjectionMatrix {
72+
/// Returns the identity matrix
7173
pub fn one() -> Self {
7274
ProjectionMatrix([
7375
[1.0, 0.0, 0.0, 0.0],
@@ -76,9 +78,11 @@ impl ProjectionMatrix {
7678
[0.0, 0.0, 0.0, 1.0],
7779
])
7880
}
81+
/// Returns the zero maxtrix
7982
pub fn zero() -> Self {
8083
ProjectionMatrix([[0.0; 4]; 4])
8184
}
85+
/// Returns the matrix which shift the coordinate
8286
pub fn shift(x: f64, y: f64, z: f64) -> Self {
8387
ProjectionMatrix([
8488
[1.0, 0.0, 0.0, x],
@@ -87,6 +91,7 @@ impl ProjectionMatrix {
8791
[0.0, 0.0, 0.0, 1.0],
8892
])
8993
}
94+
/// Returns the matrix which rotates the coordinate
9095
pub fn rotate(x: f64, y: f64, z: f64) -> Self {
9196
let (c, b, a) = (x, y, z);
9297
ProjectionMatrix([
@@ -106,6 +111,7 @@ impl ProjectionMatrix {
106111
[0.0, 0.0, 0.0, 1.0],
107112
])
108113
}
114+
/// Returns the matrix that applies a scale factor
109115
pub fn scale(factor: f64) -> Self {
110116
ProjectionMatrix([
111117
[1.0, 0.0, 0.0, 0.0],
@@ -114,6 +120,7 @@ impl ProjectionMatrix {
114120
[0.0, 0.0, 0.0, 1.0 / factor],
115121
])
116122
}
123+
/// Normalize the matrix, this will make the metric unit to 1
117124
pub fn normalize(&mut self) {
118125
if self.0[3][3] > 1e-20 {
119126
for r in 0..4 {
@@ -124,12 +131,14 @@ impl ProjectionMatrix {
124131
}
125132
}
126133

134+
/// Get the distance of the point in guest coordinate from the screen in pixels
127135
pub fn projected_depth(&self, (x, y, z): (i32, i32, i32)) -> i32 {
128136
let r = &self.0[2];
129137
(r[0] * x as f64 + r[1] * y as f64 + r[2] * z as f64 + r[3]) as i32
130138
}
131139
}
132140

141+
/// The helper struct to build a projection matrix
133142
#[derive(Copy, Clone)]
134143
pub struct ProjectionMatrixBuilder {
135144
pub yaw: f64,
@@ -150,12 +159,15 @@ impl ProjectionMatrixBuilder {
150159
}
151160
}
152161

162+
/// Set the pivot point, which means the 3D coordinate "before" should be mapped into
163+
/// the 2D coordinatet "after"
153164
pub fn set_pivot(&mut self, before: (i32, i32, i32), after: (i32, i32)) -> &mut Self {
154165
self.pivot_before = before;
155166
self.pivot_after = after;
156167
self
157168
}
158169

170+
/// Build the matrix based on the configuration
159171
pub fn into_matrix(self) -> ProjectionMatrix {
160172
let mut ret = if self.pivot_before == (0, 0, 0) {
161173
ProjectionMatrix::default()

src/series/surface.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
use crate::element::Polygon;
22
use crate::style::ShapeStyle;
3+
/// The surface series.
4+
///
5+
/// Currently the surface is representing any surface in form
6+
/// y = f(x,z)
7+
///
8+
/// TODO: make this more general
39
pub struct SurfaceSeries<X, Y, Z> {
410
x_data: Vec<X>,
511
y_data: Vec<Y>,

0 commit comments

Comments
 (0)