crisol_plot/plot/three/
builder.rs1use egui::Id;
4
5use super::super::axis::Scale;
6use super::super::{DirectionArrowConfig, LegendAnimation, LegendHoverConfig, LegendPosition};
7use super::{Bounds3D, Plot3D, Plot3DConfig, Projection, Series3D, Surface3DConfig};
8
9impl<'a> Plot3D<'a> {
10 pub fn new(id: impl std::hash::Hash + std::fmt::Debug) -> Self {
12 Self {
13 id: Id::unique(("workbench_plot3d", id)),
14 series: Vec::new(),
15 config: Plot3DConfig::default(),
16 width: None,
17 height: None,
18 include: Bounds3D::NOTHING,
19 settings_button: false,
20 export_button: false,
21 }
22 }
23
24 pub fn renderer(mut self, renderer: super::super::Renderer) -> Self {
26 self.config.renderer = renderer;
27 self
28 }
29
30 pub fn config(mut self, config: Plot3DConfig) -> Self {
32 self.config = config;
33 self
34 }
35
36 pub fn current_config(&self) -> &Plot3DConfig {
38 &self.config
39 }
40
41 pub fn series_names(&self) -> Vec<String> {
43 self.series.iter().map(|series| series.name.clone()).collect()
44 }
45
46 pub fn series(mut self, series: Series3D<'a>) -> Self {
48 self.series.push(series);
49 self
50 }
51
52 pub fn title(mut self, title: impl Into<String>) -> Self {
54 self.config.title = Some(title.into());
55 self
56 }
57
58 pub fn x_label(mut self, label: impl Into<String>) -> Self {
60 self.config.x.label = Some(label.into());
61 self
62 }
63
64 pub fn y_label(mut self, label: impl Into<String>) -> Self {
66 self.config.y.label = Some(label.into());
67 self
68 }
69
70 pub fn z_label(mut self, label: impl Into<String>) -> Self {
72 self.config.z.label = Some(label.into());
73 self
74 }
75
76 pub fn x_limits(mut self, min: Option<f64>, max: Option<f64>) -> Self {
78 (self.config.x.min, self.config.x.max) = (min, max);
79 self
80 }
81
82 pub fn y_limits(mut self, min: Option<f64>, max: Option<f64>) -> Self {
84 (self.config.y.min, self.config.y.max) = (min, max);
85 self
86 }
87
88 pub fn z_limits(mut self, min: Option<f64>, max: Option<f64>) -> Self {
90 (self.config.z.min, self.config.z.max) = (min, max);
91 self
92 }
93
94 pub fn x_scale(mut self, scale: Scale) -> Self {
96 self.config.x.scale = scale;
97 self
98 }
99
100 pub fn y_scale(mut self, scale: Scale) -> Self {
102 self.config.y.scale = scale;
103 self
104 }
105
106 pub fn z_scale(mut self, scale: Scale) -> Self {
108 self.config.z.scale = scale;
109 self
110 }
111
112 pub fn width(mut self, width: f32) -> Self {
114 self.width = Some(width);
115 self
116 }
117
118 pub fn height(mut self, height: f32) -> Self {
120 self.height = Some(height);
121 self
122 }
123
124 pub fn legend(mut self, legend: LegendPosition) -> Self {
126 self.config.legend = legend;
127 self
128 }
129
130 pub fn legend_hover(mut self, config: LegendHoverConfig) -> Self {
132 self.config.legend_hover = config;
133 self
134 }
135
136 pub fn legend_animation(mut self, animation: LegendAnimation) -> Self {
138 self.config.legend_hover.animation = animation;
139 self
140 }
141
142 pub fn direction(mut self, config: DirectionArrowConfig) -> Self {
144 self.config.direction = config;
145 self
146 }
147
148 pub fn direction_arrow(mut self, show: bool) -> Self {
150 self.config.direction.enabled = show;
151 self
152 }
153
154 pub fn direction_points(mut self, points: usize) -> Self {
156 self.config.direction.points = points.max(2);
157 self
158 }
159
160 pub fn projection(mut self, projection: Projection) -> Self {
162 self.config.projection = projection;
163 self
164 }
165
166 pub fn camera_angles(mut self, yaw: f32, pitch: f32) -> Self {
168 (self.config.yaw, self.config.pitch) = (yaw, pitch);
169 self
170 }
171
172 pub fn fov(mut self, fov: f32) -> Self {
174 self.config.fov = fov;
175 self
176 }
177
178 pub fn surface(mut self, config: Surface3DConfig) -> Self {
180 self.config.surface = config;
181 self
182 }
183
184 pub fn grid(mut self, grid: bool) -> Self {
186 for axis in [&mut self.config.x, &mut self.config.y, &mut self.config.z] {
187 axis.grid_major = grid;
188 axis.grid_minor = grid;
189 }
190 self
191 }
192
193 pub fn toolbar(mut self, toolbar: bool) -> Self {
195 self.config.toolbar = toolbar;
196 self
197 }
198
199 pub fn include(mut self, point: [f64; 3]) -> Self {
201 self.include.extend(point);
202 self
203 }
204
205 pub fn settings_button(mut self, show: bool) -> Self {
207 self.settings_button = show;
208 self
209 }
210
211 pub fn export_button(mut self, show: bool) -> Self {
213 self.export_button = show;
214 self
215 }
216}