graphcal_compiler/syntax/ast/
plot_props.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum PlotPropertyType {
12 String,
14 Number,
16 PositiveNumber,
20 Bool,
22}
23
24impl PlotPropertyType {
25 #[must_use]
27 pub const fn describe(self) -> &'static str {
28 match self {
29 Self::String => "a string literal",
30 Self::Number => "a dimensionless number",
31 Self::PositiveNumber => "a positive dimensionless number",
32 Self::Bool => "a boolean",
33 }
34 }
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
39pub enum MarkProperty {
40 StrokeWidth,
41 Opacity,
42 Size,
43 Color,
44 Filled,
45 Interpolate,
46}
47
48impl MarkProperty {
49 pub const ALL: [Self; 6] = [
51 Self::StrokeWidth,
52 Self::Opacity,
53 Self::Size,
54 Self::Color,
55 Self::Filled,
56 Self::Interpolate,
57 ];
58
59 #[must_use]
61 pub fn from_name(s: &str) -> Option<Self> {
62 Self::ALL.into_iter().find(|p| p.name() == s)
63 }
64
65 #[must_use]
67 pub const fn name(self) -> &'static str {
68 match self {
69 Self::StrokeWidth => "stroke_width",
70 Self::Opacity => "opacity",
71 Self::Size => "size",
72 Self::Color => "color",
73 Self::Filled => "filled",
74 Self::Interpolate => "interpolate",
75 }
76 }
77
78 #[must_use]
80 pub const fn vega_name(self) -> &'static str {
81 match self {
82 Self::StrokeWidth => "strokeWidth",
83 Self::Opacity => "opacity",
84 Self::Size => "size",
85 Self::Color => "color",
86 Self::Filled => "filled",
87 Self::Interpolate => "interpolate",
88 }
89 }
90
91 #[must_use]
93 pub const fn value_type(self) -> PlotPropertyType {
94 match self {
95 Self::StrokeWidth | Self::Opacity | Self::Size => PlotPropertyType::Number,
96 Self::Color | Self::Interpolate => PlotPropertyType::String,
97 Self::Filled => PlotPropertyType::Bool,
98 }
99 }
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
104pub enum PlotProperty {
105 Title,
106 Width,
107 Height,
108 XLabel,
109 YLabel,
110}
111
112impl PlotProperty {
113 pub const ALL: [Self; 5] = [
115 Self::Title,
116 Self::Width,
117 Self::Height,
118 Self::XLabel,
119 Self::YLabel,
120 ];
121
122 #[must_use]
124 pub fn from_name(s: &str) -> Option<Self> {
125 Self::ALL.into_iter().find(|p| p.name() == s)
126 }
127
128 #[must_use]
130 pub const fn name(self) -> &'static str {
131 match self {
132 Self::Title => "title",
133 Self::Width => "width",
134 Self::Height => "height",
135 Self::XLabel => "x_label",
136 Self::YLabel => "y_label",
137 }
138 }
139
140 #[must_use]
142 pub const fn value_type(self) -> PlotPropertyType {
143 match self {
144 Self::Title | Self::XLabel | Self::YLabel => PlotPropertyType::String,
145 Self::Width | Self::Height => PlotPropertyType::PositiveNumber,
146 }
147 }
148}
149
150#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
152pub enum CompositionProperty {
153 Title,
154 Width,
155 Height,
156}
157
158impl CompositionProperty {
159 pub const ALL: [Self; 3] = [Self::Title, Self::Width, Self::Height];
161
162 #[must_use]
164 pub fn from_name(s: &str) -> Option<Self> {
165 Self::ALL.into_iter().find(|p| p.name() == s)
166 }
167
168 #[must_use]
170 pub const fn name(self) -> &'static str {
171 match self {
172 Self::Title => "title",
173 Self::Width => "width",
174 Self::Height => "height",
175 }
176 }
177
178 #[must_use]
180 pub const fn value_type(self) -> PlotPropertyType {
181 match self {
182 Self::Title => PlotPropertyType::String,
183 Self::Width | Self::Height => PlotPropertyType::PositiveNumber,
184 }
185 }
186
187 #[must_use]
193 pub const fn applies_to_figure(self) -> bool {
194 matches!(self, Self::Title)
195 }
196}