theta_chart/coord/
cartesian.rs1use super::CView;
2use crate::series::Series;
3
4#[derive(Debug, Clone)]
5pub struct Cartesian {
7 ax: Series,
8 ay: Series,
9 view: CView,
10 error: String,
11}
12
13impl Cartesian {
14 pub fn new(ax: Series, ay: Series) -> Self {
15 let len_ax = ax.get_count();
16 let len_ay = ay.get_count();
17 let mut err = String::default();
18
19 if len_ax != len_ay {
20 err = "The lengths of the series are not equal".to_string()
21 }
22
23 Self {
24 ax,
25 ay,
26 view: CView::default(),
27 error: err,
28 }
29 }
30
31 pub fn set_ax(self, ax: Series) -> Self {
32 let len_ax = ax.get_count();
33 let len_ay = self.ay.get_count();
34 let mut err = String::default();
35 if len_ax != len_ay {
36 err = "The lengths of the series are not equal".to_string();
37 }
38 Self {
39 ax: ax,
40 ay: self.ay.clone(),
41 view: self.view.clone(),
42 error: err,
43 }
44 }
45
46 pub fn set_ay(&self, ay: Series) -> Self {
47 let len_ax = self.ax.get_count();
48 let len_ay = ay.get_count();
49 let mut err = String::default();
50 if len_ax != len_ay {
51 err = "The lengths of the series are not equal".to_string();
52 }
53
54 Self {
55 ax: self.ax.clone(),
56 ay: ay,
57 view: self.view.clone(),
58 error: err,
59 }
60 }
61
62 pub fn get_error(&self) -> String {
63 self.error.clone()
64 }
65
66 pub fn set_view(
67 &self,
68 width: u64,
69 height: u64,
70 position_axes: usize,
71 height_x_axis: u64,
72 width_y_axis: u64,
73 margin: u64,
74 ) -> Self {
75 let view = CView::new(
76 width,
77 height,
78 position_axes,
79 height_x_axis,
80 width_y_axis,
81 margin,
82 );
83 Self {
84 ax: self.ax.clone(),
85 ay: self.ay.clone(),
86 view: view,
87 error: self.error.clone(),
88 }
89 }
90
91 pub fn get_view(&self) -> CView {
92 self.view.clone()
93 }
94
95 pub fn get_ax(&self) -> Series {
96 self.ax.clone()
97 }
98
99 pub fn get_ay(&self) -> Series {
100 self.ay.clone()
101 }
102}