use crate::{style::LinePattern, Error, NumericValues};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Bounds {
lower: NumericValues,
upper: NumericValues,
}
impl Bounds {
#[must_use]
pub fn new(lower: NumericValues, upper: NumericValues) -> Self {
Self { lower, upper }
}
#[must_use]
pub const fn lower(&self) -> &NumericValues {
&self.lower
}
#[must_use]
pub const fn upper(&self) -> &NumericValues {
&self.upper
}
}
#[derive(Debug, Clone)]
pub struct CoefficientInput {
values: NumericValues,
bounds: Option<Bounds>,
}
impl CoefficientInput {
#[must_use]
pub fn estimates(values: NumericValues) -> Self {
Self {
values,
bounds: None,
}
}
#[must_use]
pub fn estimates_with_intervals(values: NumericValues, bounds: Bounds) -> Self {
Self {
values,
bounds: Some(bounds),
}
}
pub(crate) const fn values(&self) -> &NumericValues {
&self.values
}
pub(crate) const fn bounds(&self) -> Option<&Bounds> {
self.bounds.as_ref()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TextWeight {
#[default]
Normal,
Semibold,
Bold,
}
impl TextWeight {
pub(crate) const fn svg_value(self) -> u16 {
match self {
Self::Normal => 400,
Self::Semibold => 600,
Self::Bold => 700,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SignificanceMarkStyle {
font_size: f64,
weight: TextWeight,
gap: f64,
}
impl SignificanceMarkStyle {
pub(crate) const DEFAULT: Self = Self {
font_size: 16.0,
weight: TextWeight::Normal,
gap: 8.0,
};
pub fn new(font_size: f64, weight: TextWeight, gap: f64) -> Result<Self, Error> {
Self {
font_size,
weight,
gap,
}
.validate()
}
pub fn font_size(mut self, font_size: f64) -> Result<Self, Error> {
self.font_size = font_size;
self.validate()
}
pub fn weight(mut self, weight: TextWeight) -> Result<Self, Error> {
self.weight = weight;
self.validate()
}
pub fn gap(mut self, gap: f64) -> Result<Self, Error> {
self.gap = gap;
self.validate()
}
fn validate(mut self) -> Result<Self, Error> {
if !self.font_size.is_finite()
|| self.font_size <= 0.0
|| !self.gap.is_finite()
|| self.gap < 0.0
{
return Err(Error::Data(
"significance mark style requires positive font size and finite nonnegative gap"
.into(),
));
}
if self.gap == 0.0 {
self.gap = 0.0;
}
Ok(self)
}
pub const fn get_font_size(&self) -> f64 {
self.font_size
}
pub const fn get_weight(&self) -> TextWeight {
self.weight
}
pub const fn get_gap(&self) -> f64 {
self.gap
}
}
impl Default for SignificanceMarkStyle {
fn default() -> Self {
Self::DEFAULT
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum RegressionBand {
#[default]
PointwiseMean95,
Hidden,
}
impl RegressionBand {
pub(crate) const fn legend_label(self) -> &'static str {
match self {
Self::PointwiseMean95 => "Pointwise 95% Student-t mean band",
Self::Hidden => "Descriptive OLS fit (no band)",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum QqLine {
#[default]
Quartiles,
Identity,
Hidden,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LinePathStyle {
#[default]
Neutral,
Hue,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum PointShape {
#[default]
Circle,
TriangleUp,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InteractionStyle {
group: String,
shape: PointShape,
pattern: LinePattern,
}
impl InteractionStyle {
pub fn new(group: impl Into<String>) -> Result<Self, Error> {
Self {
group: group.into(),
shape: PointShape::default(),
pattern: LinePattern::default(),
}
.validate()
}
pub fn point_shape(mut self, shape: PointShape) -> Result<Self, Error> {
self.shape = shape;
self.validate()
}
pub fn line_pattern(mut self, pattern: LinePattern) -> Result<Self, Error> {
self.pattern = pattern;
self.validate()
}
fn validate(self) -> Result<Self, Error> {
if self.group.is_empty()
|| self.group.trim() != self.group
|| self.group.chars().any(char::is_control)
{
return Err(Error::Data(
"interaction style group must be nonempty, already trimmed, and contain no control characters".into(),
));
}
Ok(self)
}
#[must_use]
pub fn group(&self) -> &str {
&self.group
}
#[must_use]
pub const fn get_point_shape(&self) -> PointShape {
self.shape
}
#[must_use]
pub const fn get_line_pattern(&self) -> LinePattern {
self.pattern
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EstimateStatus {
Estimated,
NotEstimable,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum AxisScale {
#[default]
Linear,
Log10,
}