ggplot_rs/coord/
cartesian.rs1use crate::render::Rect;
2
3use super::Coord;
4
5pub struct CoordCartesian {
11 xlim: Option<(f64, f64)>,
12 ylim: Option<(f64, f64)>,
13}
14
15impl CoordCartesian {
16 pub fn new() -> Self {
17 CoordCartesian {
18 xlim: None,
19 ylim: None,
20 }
21 }
22
23 pub fn xlim(mut self, min: f64, max: f64) -> Self {
25 self.xlim = Some((min, max));
26 self
27 }
28
29 pub fn ylim(mut self, min: f64, max: f64) -> Self {
31 self.ylim = Some((min, max));
32 self
33 }
34
35 pub fn get_xlim(&self) -> Option<(f64, f64)> {
37 self.xlim
38 }
39
40 pub fn get_ylim(&self) -> Option<(f64, f64)> {
42 self.ylim
43 }
44}
45
46impl Default for CoordCartesian {
47 fn default() -> Self {
48 Self::new()
49 }
50}
51
52impl Coord for CoordCartesian {
53 fn transform(&self, point: (f64, f64), plot_area: &Rect) -> (f64, f64) {
54 let (nx, ny) = point;
55 let px = plot_area.x + nx * plot_area.width;
56 let py = plot_area.y + (1.0 - ny) * plot_area.height;
58 (px, py)
59 }
60
61 fn zoom_x(&self) -> Option<(f64, f64)> {
62 self.xlim
63 }
64
65 fn zoom_y(&self) -> Option<(f64, f64)> {
66 self.ylim
67 }
68}