1use crate::{Error, NumericValues};
4
5#[derive(Debug, Clone)]
7pub struct Bounds {
8 lower: NumericValues,
9 upper: NumericValues,
10}
11
12impl Bounds {
13 #[must_use]
15 pub fn new(lower: NumericValues, upper: NumericValues) -> Self {
16 Self { lower, upper }
17 }
18
19 #[must_use]
21 pub const fn lower(&self) -> &NumericValues {
22 &self.lower
23 }
24
25 #[must_use]
27 pub const fn upper(&self) -> &NumericValues {
28 &self.upper
29 }
30}
31
32#[derive(Debug, Clone)]
34pub struct CoefficientInput {
35 values: NumericValues,
36 bounds: Option<Bounds>,
37}
38
39impl CoefficientInput {
40 #[must_use]
42 pub fn estimates(values: NumericValues) -> Self {
43 Self {
44 values,
45 bounds: None,
46 }
47 }
48
49 #[must_use]
51 pub fn estimates_with_intervals(values: NumericValues, bounds: Bounds) -> Self {
52 Self {
53 values,
54 bounds: Some(bounds),
55 }
56 }
57
58 pub(crate) const fn values(&self) -> &NumericValues {
59 &self.values
60 }
61
62 pub(crate) const fn bounds(&self) -> Option<&Bounds> {
63 self.bounds.as_ref()
64 }
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
69pub enum TextWeight {
70 #[default]
72 Normal,
73 Semibold,
75 Bold,
77}
78
79impl TextWeight {
80 pub(crate) const fn svg_value(self) -> u16 {
81 match self {
82 Self::Normal => 400,
83 Self::Semibold => 600,
84 Self::Bold => 700,
85 }
86 }
87}
88
89#[derive(Debug, Clone, Copy, PartialEq)]
110pub struct SignificanceMarkStyle {
111 font_size: f64,
112 weight: TextWeight,
113 gap: f64,
114}
115
116impl SignificanceMarkStyle {
117 pub(crate) const DEFAULT: Self = Self {
119 font_size: 16.0,
120 weight: TextWeight::Normal,
121 gap: 8.0,
122 };
123
124 pub fn new(font_size: f64, weight: TextWeight, gap: f64) -> Result<Self, Error> {
126 Self {
127 font_size,
128 weight,
129 gap,
130 }
131 .validate()
132 }
133
134 pub fn font_size(mut self, font_size: f64) -> Result<Self, Error> {
136 self.font_size = font_size;
137 self.validate()
138 }
139
140 pub fn weight(mut self, weight: TextWeight) -> Result<Self, Error> {
142 self.weight = weight;
143 self.validate()
144 }
145
146 pub fn gap(mut self, gap: f64) -> Result<Self, Error> {
148 self.gap = gap;
149 self.validate()
150 }
151
152 fn validate(mut self) -> Result<Self, Error> {
153 if !self.font_size.is_finite()
154 || self.font_size <= 0.0
155 || !self.gap.is_finite()
156 || self.gap < 0.0
157 {
158 return Err(Error::Data(
159 "significance mark style requires positive font size and finite nonnegative gap"
160 .into(),
161 ));
162 }
163 if self.gap == 0.0 {
164 self.gap = 0.0;
165 }
166 Ok(self)
167 }
168
169 pub const fn get_font_size(&self) -> f64 {
171 self.font_size
172 }
173
174 pub const fn get_weight(&self) -> TextWeight {
176 self.weight
177 }
178
179 pub const fn get_gap(&self) -> f64 {
181 self.gap
182 }
183}
184
185impl Default for SignificanceMarkStyle {
186 fn default() -> Self {
187 Self::DEFAULT
188 }
189}
190
191#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
193pub enum RegressionBand {
194 #[default]
196 PointwiseMean95,
197 Hidden,
199}
200
201impl RegressionBand {
202 pub(crate) const fn legend_label(self) -> &'static str {
203 match self {
204 Self::PointwiseMean95 => "Pointwise 95% Student-t mean band",
205 Self::Hidden => "Descriptive OLS fit (no band)",
206 }
207 }
208}
209
210#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
212pub enum QqLine {
213 #[default]
215 Quartiles,
216 Identity,
218 Hidden,
220}
221
222#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
224pub enum LinePathStyle {
225 #[default]
227 Neutral,
228 Hue,
230}
231
232#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
234pub enum PointShape {
235 #[default]
237 Circle,
238 TriangleUp,
240}
241
242#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
244pub enum LinePattern {
245 #[default]
247 Solid,
248 Dashed,
250}
251
252impl LinePattern {
253 pub(crate) const fn stroke_pattern(self) -> crate::render::backend::StrokePattern {
255 match self {
256 Self::Solid => crate::render::backend::StrokePattern::Solid,
257 Self::Dashed => crate::render::backend::StrokePattern::LongDash,
258 }
259 }
260}
261
262#[derive(Debug, Clone, PartialEq, Eq)]
278pub struct InteractionStyle {
279 group: String,
280 shape: PointShape,
281 pattern: LinePattern,
282}
283
284impl InteractionStyle {
285 pub fn new(group: impl Into<String>) -> Result<Self, Error> {
290 Self {
291 group: group.into(),
292 shape: PointShape::default(),
293 pattern: LinePattern::default(),
294 }
295 .validate()
296 }
297
298 pub fn point_shape(mut self, shape: PointShape) -> Result<Self, Error> {
300 self.shape = shape;
301 self.validate()
302 }
303
304 pub fn line_pattern(mut self, pattern: LinePattern) -> Result<Self, Error> {
306 self.pattern = pattern;
307 self.validate()
308 }
309
310 fn validate(self) -> Result<Self, Error> {
311 if self.group.is_empty()
312 || self.group.trim() != self.group
313 || self.group.chars().any(char::is_control)
314 {
315 return Err(Error::Data(
316 "interaction style group must be nonempty, already trimmed, and contain no control characters".into(),
317 ));
318 }
319 Ok(self)
320 }
321
322 #[must_use]
324 pub fn group(&self) -> &str {
325 &self.group
326 }
327
328 #[must_use]
330 pub const fn get_point_shape(&self) -> PointShape {
331 self.shape
332 }
333
334 #[must_use]
336 pub const fn get_line_pattern(&self) -> LinePattern {
337 self.pattern
338 }
339}
340
341#[derive(Debug, Clone, Copy, PartialEq, Eq)]
343pub enum EstimateStatus {
344 Estimated,
346 NotEstimable,
348}
349
350#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
352pub enum AxisScale {
353 #[default]
355 Linear,
356 Log10,
358}