#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlotPropertyType {
String,
Number,
PositiveNumber,
Bool,
}
impl PlotPropertyType {
#[must_use]
pub const fn describe(self) -> &'static str {
match self {
Self::String => "a string literal",
Self::Number => "a dimensionless number",
Self::PositiveNumber => "a positive dimensionless number",
Self::Bool => "a boolean",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MarkProperty {
StrokeWidth,
Opacity,
Size,
Color,
Filled,
Interpolate,
}
impl MarkProperty {
pub const ALL: [Self; 6] = [
Self::StrokeWidth,
Self::Opacity,
Self::Size,
Self::Color,
Self::Filled,
Self::Interpolate,
];
#[must_use]
pub fn from_name(s: &str) -> Option<Self> {
Self::ALL.into_iter().find(|p| p.name() == s)
}
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::StrokeWidth => "stroke_width",
Self::Opacity => "opacity",
Self::Size => "size",
Self::Color => "color",
Self::Filled => "filled",
Self::Interpolate => "interpolate",
}
}
#[must_use]
pub const fn vega_name(self) -> &'static str {
match self {
Self::StrokeWidth => "strokeWidth",
Self::Opacity => "opacity",
Self::Size => "size",
Self::Color => "color",
Self::Filled => "filled",
Self::Interpolate => "interpolate",
}
}
#[must_use]
pub const fn value_type(self) -> PlotPropertyType {
match self {
Self::StrokeWidth | Self::Opacity | Self::Size => PlotPropertyType::Number,
Self::Color | Self::Interpolate => PlotPropertyType::String,
Self::Filled => PlotPropertyType::Bool,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PlotProperty {
Title,
Width,
Height,
XLabel,
YLabel,
}
impl PlotProperty {
pub const ALL: [Self; 5] = [
Self::Title,
Self::Width,
Self::Height,
Self::XLabel,
Self::YLabel,
];
#[must_use]
pub fn from_name(s: &str) -> Option<Self> {
Self::ALL.into_iter().find(|p| p.name() == s)
}
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Title => "title",
Self::Width => "width",
Self::Height => "height",
Self::XLabel => "x_label",
Self::YLabel => "y_label",
}
}
#[must_use]
pub const fn value_type(self) -> PlotPropertyType {
match self {
Self::Title | Self::XLabel | Self::YLabel => PlotPropertyType::String,
Self::Width | Self::Height => PlotPropertyType::PositiveNumber,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CompositionProperty {
Title,
Width,
Height,
}
impl CompositionProperty {
pub const ALL: [Self; 3] = [Self::Title, Self::Width, Self::Height];
#[must_use]
pub fn from_name(s: &str) -> Option<Self> {
Self::ALL.into_iter().find(|p| p.name() == s)
}
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Title => "title",
Self::Width => "width",
Self::Height => "height",
}
}
#[must_use]
pub const fn value_type(self) -> PlotPropertyType {
match self {
Self::Title => PlotPropertyType::String,
Self::Width | Self::Height => PlotPropertyType::PositiveNumber,
}
}
#[must_use]
pub const fn applies_to_figure(self) -> bool {
matches!(self, Self::Title)
}
}