use egui::Id;
use super::super::axis::Scale;
use super::super::{DirectionArrowConfig, LegendAnimation, LegendHoverConfig, LegendPosition};
use super::{Bounds3D, Plot3D, Plot3DConfig, Projection, Series3D, Surface3DConfig};
impl<'a> Plot3D<'a> {
pub fn new(id: impl std::hash::Hash + std::fmt::Debug) -> Self {
Self {
id: Id::unique(("workbench_plot3d", id)),
series: Vec::new(),
config: Plot3DConfig::default(),
width: None,
height: None,
include: Bounds3D::NOTHING,
settings_button: false,
export_button: false,
}
}
pub fn renderer(mut self, renderer: super::super::Renderer) -> Self {
self.config.renderer = renderer;
self
}
pub fn config(mut self, config: Plot3DConfig) -> Self {
self.config = config;
self
}
pub fn current_config(&self) -> &Plot3DConfig {
&self.config
}
pub fn series_names(&self) -> Vec<String> {
self.series.iter().map(|series| series.name.clone()).collect()
}
pub fn series(mut self, series: Series3D<'a>) -> Self {
self.series.push(series);
self
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.config.title = Some(title.into());
self
}
pub fn x_label(mut self, label: impl Into<String>) -> Self {
self.config.x.label = Some(label.into());
self
}
pub fn y_label(mut self, label: impl Into<String>) -> Self {
self.config.y.label = Some(label.into());
self
}
pub fn z_label(mut self, label: impl Into<String>) -> Self {
self.config.z.label = Some(label.into());
self
}
pub fn x_limits(mut self, min: Option<f64>, max: Option<f64>) -> Self {
(self.config.x.min, self.config.x.max) = (min, max);
self
}
pub fn y_limits(mut self, min: Option<f64>, max: Option<f64>) -> Self {
(self.config.y.min, self.config.y.max) = (min, max);
self
}
pub fn z_limits(mut self, min: Option<f64>, max: Option<f64>) -> Self {
(self.config.z.min, self.config.z.max) = (min, max);
self
}
pub fn x_scale(mut self, scale: Scale) -> Self {
self.config.x.scale = scale;
self
}
pub fn y_scale(mut self, scale: Scale) -> Self {
self.config.y.scale = scale;
self
}
pub fn z_scale(mut self, scale: Scale) -> Self {
self.config.z.scale = scale;
self
}
pub fn width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
pub fn height(mut self, height: f32) -> Self {
self.height = Some(height);
self
}
pub fn legend(mut self, legend: LegendPosition) -> Self {
self.config.legend = legend;
self
}
pub fn legend_hover(mut self, config: LegendHoverConfig) -> Self {
self.config.legend_hover = config;
self
}
pub fn legend_animation(mut self, animation: LegendAnimation) -> Self {
self.config.legend_hover.animation = animation;
self
}
pub fn direction(mut self, config: DirectionArrowConfig) -> Self {
self.config.direction = config;
self
}
pub fn direction_arrow(mut self, show: bool) -> Self {
self.config.direction.enabled = show;
self
}
pub fn direction_points(mut self, points: usize) -> Self {
self.config.direction.points = points.max(2);
self
}
pub fn projection(mut self, projection: Projection) -> Self {
self.config.projection = projection;
self
}
pub fn camera_angles(mut self, yaw: f32, pitch: f32) -> Self {
(self.config.yaw, self.config.pitch) = (yaw, pitch);
self
}
pub fn fov(mut self, fov: f32) -> Self {
self.config.fov = fov;
self
}
pub fn surface(mut self, config: Surface3DConfig) -> Self {
self.config.surface = config;
self
}
pub fn grid(mut self, grid: bool) -> Self {
for axis in [&mut self.config.x, &mut self.config.y, &mut self.config.z] {
axis.grid_major = grid;
axis.grid_minor = grid;
}
self
}
pub fn toolbar(mut self, toolbar: bool) -> Self {
self.config.toolbar = toolbar;
self
}
pub fn include(mut self, point: [f64; 3]) -> Self {
self.include.extend(point);
self
}
pub fn settings_button(mut self, show: bool) -> Self {
self.settings_button = show;
self
}
pub fn export_button(mut self, show: bool) -> Self {
self.export_button = show;
self
}
}