use std::collections::BTreeMap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::artist::{ContourPlacement, Grid, Levels, QuiverScale, ScatterColor, ScatterSize};
use crate::axes::{
Axis, Cell, ColormapName, Legend, LegendLocation, Limits, Projection, Scale, View3d,
};
use crate::figure::{FigureSize, FontSetId, Parameter, TileLayout};
use crate::ids::DataId;
use crate::link::AxisLink;
use crate::style::{Color, ColorSpec, DashStyle, LineStyle, MarkerShape, MarkerStyle};
use crate::text::{Interpreter, Text};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum Value {
Unset,
Bool(bool),
#[serde(rename = "uint32")]
UInt32(u32),
Double(f64),
Float(f32),
String(String),
DataId(DataId),
Doubles(Vec<f64>),
Text(Text),
Interpreter(Interpreter),
FigureSize(FigureSize),
FontSetId(FontSetId),
Color(Color),
TileLayout(TileLayout),
Links(Vec<AxisLink>),
Parameters(BTreeMap<String, Parameter>),
Cell(Cell),
Projection(Projection),
View3d(View3d),
Axis(Axis),
Scale(Scale),
Limits(Limits),
ColormapName(ColormapName),
Legend(Legend),
LegendLocation(LegendLocation),
ColorSpec(ColorSpec),
LineStyle(LineStyle),
DashStyle(DashStyle),
MarkerStyle(MarkerStyle),
MarkerShape(MarkerShape),
ScatterSize(ScatterSize),
ScatterColor(ScatterColor),
Grid(Grid),
Levels(Levels),
ContourPlacement(ContourPlacement),
QuiverScale(QuiverScale),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum ValueType {
Bool,
UInt32,
Double,
Float,
String,
DataId,
Doubles,
Text,
Interpreter,
FigureSize,
FontSetId,
Color,
TileLayout,
Links,
Parameters,
Cell,
Projection,
View3d,
Axis,
Scale,
Limits,
ColormapName,
Legend,
LegendLocation,
ColorSpec,
LineStyle,
DashStyle,
MarkerStyle,
MarkerShape,
ScatterSize,
ScatterColor,
Grid,
Levels,
ContourPlacement,
QuiverScale,
}
impl Value {
pub fn value_type(&self) -> Option<ValueType> {
Some(match self {
Value::Unset => return None,
Value::Bool(_) => ValueType::Bool,
Value::UInt32(_) => ValueType::UInt32,
Value::Double(_) => ValueType::Double,
Value::Float(_) => ValueType::Float,
Value::String(_) => ValueType::String,
Value::DataId(_) => ValueType::DataId,
Value::Doubles(_) => ValueType::Doubles,
Value::Text(_) => ValueType::Text,
Value::Interpreter(_) => ValueType::Interpreter,
Value::FigureSize(_) => ValueType::FigureSize,
Value::FontSetId(_) => ValueType::FontSetId,
Value::Color(_) => ValueType::Color,
Value::TileLayout(_) => ValueType::TileLayout,
Value::Links(_) => ValueType::Links,
Value::Parameters(_) => ValueType::Parameters,
Value::Cell(_) => ValueType::Cell,
Value::Projection(_) => ValueType::Projection,
Value::View3d(_) => ValueType::View3d,
Value::Axis(_) => ValueType::Axis,
Value::Scale(_) => ValueType::Scale,
Value::Limits(_) => ValueType::Limits,
Value::ColormapName(_) => ValueType::ColormapName,
Value::Legend(_) => ValueType::Legend,
Value::LegendLocation(_) => ValueType::LegendLocation,
Value::ColorSpec(_) => ValueType::ColorSpec,
Value::LineStyle(_) => ValueType::LineStyle,
Value::DashStyle(_) => ValueType::DashStyle,
Value::MarkerStyle(_) => ValueType::MarkerStyle,
Value::MarkerShape(_) => ValueType::MarkerShape,
Value::ScatterSize(_) => ValueType::ScatterSize,
Value::ScatterColor(_) => ValueType::ScatterColor,
Value::Grid(_) => ValueType::Grid,
Value::Levels(_) => ValueType::Levels,
Value::ContourPlacement(_) => ValueType::ContourPlacement,
Value::QuiverScale(_) => ValueType::QuiverScale,
})
}
}