use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::artist::Artist;
use crate::ids::NodeId;
use crate::text::Text;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Axes {
pub id: NodeId,
pub cell: Cell,
pub projection: Projection,
pub title: Option<Text>,
pub x: Axis,
pub y: Axis,
pub z: Axis,
#[serde(rename = "box")]
pub box_: bool,
pub colormap: ColormapName,
pub clim: Limits,
pub legend: Option<Legend>,
pub artists: Vec<Artist>,
}
impl Default for Axes {
fn default() -> Self {
Self {
id: NodeId::default(),
cell: Cell::default(),
projection: Projection::TwoD,
title: None,
x: Axis::default(),
y: Axis::default(),
z: Axis::default(),
box_: true,
colormap: ColormapName::Viridis,
clim: Limits::Auto,
legend: None,
artists: Vec::new(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct Cell {
pub row: u32,
pub col: u32,
pub row_span: u32,
pub col_span: u32,
}
impl Default for Cell {
fn default() -> Self {
Self {
row: 0,
col: 0,
row_span: 1,
col_span: 1,
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Projection {
#[default]
TwoD,
ThreeD {
view3d: View3d,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct View3d {
pub azimuth_deg: f64,
pub elevation_deg: f64,
pub zoom: f64,
pub pan_x: f64,
pub pan_y: f64,
}
impl Default for View3d {
fn default() -> Self {
Self {
azimuth_deg: -37.5,
elevation_deg: 30.0,
zoom: 1.0,
pan_x: 0.0,
pan_y: 0.0,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Axis {
pub label: Option<Text>,
pub scale: Scale,
pub limits: Limits,
pub grid: bool,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Scale {
#[default]
Linear,
Log,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Limits {
#[default]
Auto,
Manual {
min: f64,
max: f64,
},
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ColormapName {
#[default]
Viridis,
Cividis,
Magma,
Inferno,
Plasma,
Coolwarm,
Gray,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct Legend {
pub location: LegendLocation,
pub boxed: bool,
}
impl Default for Legend {
fn default() -> Self {
Self {
location: LegendLocation::NorthEast,
boxed: true,
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum LegendLocation {
#[default]
NorthEast,
NorthWest,
SouthEast,
SouthWest,
North,
South,
East,
West,
Best,
}