theta_chart/coord/
pview.rs1use crate::{
2 coord::{Point, Rec, Vector},
3 utils::cal_step::min_vec,
4};
5
6use super::Circle;
7const RADIUS: f64 = 0.9;
8
9#[derive(Debug, Clone, Default)]
10
11pub struct PView {
13 vector: Vector,
15 region_chart: Circle,
17 region_label: Rec,
18 position_label: usize,
20 margin: f64,
22}
23impl PView {
24 pub fn new(
25 width: u64,
26 height: u64,
27 position_label: usize,
28 len_label: u64,
29 margin: u64,
30 ) -> Self {
31 let vector = Vector::new(width as f64, height as f64);
32 let margin = margin as f64;
33 let width = width as f64 - 2. * margin;
34 let height = height as f64 - 2. * margin;
35 let len_label = len_label as f64;
36
37 let mut origin_label = Point::default();
38 let mut vector_label = Vector::default();
39 let mut origin_chart = Point::default();
40 let mut radius = 0.;
41
42 match position_label {
43 0 => {
45 origin_label = Point::new(0., 0.);
46 vector_label = Vector::new(width, len_label);
47 let width_chart = width;
48 let height_chart = height - len_label;
49 radius = min_vec(&vec![width_chart, height_chart]) / 2. * RADIUS;
50 origin_chart = Point::new(width / 2., height_chart / 2. + len_label);
51 }
52 1 => {
54 origin_label = Point::new(width - len_label, 0.);
55 vector_label = Vector::new(len_label, height);
56 let width_chart = width - len_label;
57 let height_chart = height;
58 radius = min_vec(&vec![width_chart, height_chart]) / 2. * RADIUS;
59 origin_chart = Point::new((width - len_label) / 2., height / 2.);
60 }
61 2 => {
63 origin_label = Point::new(0., height - len_label);
64 vector_label = Vector::new(width, len_label);
65 let width_chart = width;
66 let height_chart = height - len_label;
67 radius = min_vec(&vec![width_chart, height_chart]) / 2. * RADIUS;
68 origin_chart = Point::new(width / 2., height_chart / 2.);
69 }
70 3 => {
72 origin_label = Point::new(0., 0.);
74 vector_label = Vector::new(len_label, height);
75 let width_chart = width - len_label;
76 let height_chart = height;
77 radius = min_vec(&vec![width, height_chart]) / 2. * RADIUS;
78 origin_chart = Point::new((width_chart) / 2. + len_label, height / 2.);
79 }
80 _ => (),
81 }
82
83 Self {
84 vector,
85 region_chart: Circle::new(origin_chart, radius),
86 region_label: Rec::new(origin_label, vector_label),
87 position_label,
88 margin,
89 }
90 }
91
92 pub fn get_position_label(&self) -> usize {
93 self.position_label
94 }
95
96 pub fn get_circle_chart(&self) -> Circle {
97 self.region_chart.clone()
98 }
99
100 pub fn get_rec_label(&self) -> Rec {
101 self.region_label.clone()
102 }
103
104 pub fn get_vector(&self) -> Vector {
105 self.vector.clone()
106 }
107
108 pub fn get_margin(&self) -> f64 {
113 self.margin
114 }
115}