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 /// Whether this is a non-linear polar system (bars become radial sectors,
37 /// so geoms that draw rectangles must tessellate their edges into an arc).
38 fn is_polar(&self) -> bool {
39 false
40 }
41
42 /// Zoom limits for x-axis (data coordinates). Clips viewport without filtering data.
43 fn zoom_x(&self) -> Option<(f64, f64)> {
44 None
45 }
46
47 /// Zoom limits for y-axis (data coordinates). Clips viewport without filtering data.
48 fn zoom_y(&self) -> Option<(f64, f64)> {
49 None
50 }
51
52 /// Supply the trained x/y axis spans after scale training. Coordinate systems
53 /// that warp the axis (e.g. `coord_trans`) need this to map a normalized
54 /// position back to a data value. Default is a no-op.
55 fn set_domains(&mut self, _x: Option<AxisSpan>, _y: Option<AxisSpan>) {}
56}