ggplot_rs/coord/mod.rs
1pub mod cartesian;
2pub mod fixed;
3pub mod flip;
4pub mod polar;
5pub mod trans;
6
7use crate::render::Rect;
8
9/// A trained axis domain together with the normalized panel positions of its
10/// endpoints. `pmin`/`pmax` are `scale.map(min)`/`scale.map(max)`, so a coord can
11/// invert the (linear, expanded) scale mapping exactly: given a normalized
12/// position `n`, the data value is `min + (n - pmin)/(pmax - pmin) * (max - min)`.
13#[derive(Clone, Copy, Debug)]
14pub struct AxisSpan {
15 pub min: f64,
16 pub max: f64,
17 pub pmin: f64,
18 pub pmax: f64,
19}
20
21/// Trait for coordinate systems.
22pub trait Coord: Send + Sync {
23 /// Transform normalized (0..1, 0..1) coordinates to pixel coordinates.
24 fn transform(&self, point: (f64, f64), plot_area: &Rect) -> (f64, f64);
25
26 /// Whether to draw grid lines.
27 fn gridlines(&self) -> bool {
28 true
29 }
30
31 /// Whether this coordinate system flips X and Y.
32 fn is_flipped(&self) -> bool {
33 false
34 }
35
36 /// Zoom limits for x-axis (data coordinates). Clips viewport without filtering data.
37 fn zoom_x(&self) -> Option<(f64, f64)> {
38 None
39 }
40
41 /// Zoom limits for y-axis (data coordinates). Clips viewport without filtering data.
42 fn zoom_y(&self) -> Option<(f64, f64)> {
43 None
44 }
45
46 /// Supply the trained x/y axis spans after scale training. Coordinate systems
47 /// that warp the axis (e.g. `coord_trans`) need this to map a normalized
48 /// position back to a data value. Default is a no-op.
49 fn set_domains(&mut self, _x: Option<AxisSpan>, _y: Option<AxisSpan>) {}
50}