Skip to content
13 changes: 9 additions & 4 deletions src/plot/layer/geom/area.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Area geom implementation

use crate::plot::layer::orientation::ALIGNED;
use crate::plot::{types::DefaultAestheticValue, DefaultParam, DefaultParamValue};
use crate::plot::layer::orientation::{ALIGNED, ORIENTATION_VALUES};
use crate::plot::types::DefaultAestheticValue;
use crate::plot::{DefaultParam, DefaultParamValue};
use crate::{naming, Mappings};

use super::types::{ParamConstraint, POSITION_VALUES};
use super::{DefaultAesthetics, GeomTrait, GeomType, StatResult};

/// Area geom - filled area charts
Expand Down Expand Up @@ -34,16 +36,19 @@ impl GeomTrait for Area {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[
const PARAMS: &[DefaultParam] = &[
DefaultParam {
name: "position",
default: DefaultParamValue::String("stack"),
constraint: ParamConstraint::string_enum(POSITION_VALUES),
},
DefaultParam {
name: "orientation",
default: DefaultParamValue::String(ALIGNED),
constraint: ParamConstraint::string_enum(ORIENTATION_VALUES),
},
]
];
PARAMS
}

fn needs_stat_transform(&self, _aesthetics: &Mappings) -> bool {
Expand Down
11 changes: 8 additions & 3 deletions src/plot/layer/geom/arrow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Arrow geom implementation

use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType};
use super::types::POSITION_VALUES;
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
};
use crate::plot::types::DefaultAestheticValue;

/// Arrow geom - line segments with arrowheads
Expand Down Expand Up @@ -29,10 +32,12 @@ impl GeomTrait for Arrow {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[DefaultParam {
const PARAMS: &[DefaultParam] = &[DefaultParam {
name: "position",
default: DefaultParamValue::String("identity"),
}]
constraint: ParamConstraint::string_enum(POSITION_VALUES),
}];
PARAMS
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/plot/layer/geom/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
use std::collections::HashMap;
use std::collections::HashSet;

use super::types::get_column_name;
use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, StatResult};
use super::types::{get_column_name, POSITION_VALUES};
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
StatResult,
};
use crate::naming;
use crate::plot::types::{DefaultAestheticValue, ParameterValue};
use crate::reader::SqlDialect;
Expand Down Expand Up @@ -54,16 +57,19 @@ impl GeomTrait for Bar {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[
const PARAMS: &[DefaultParam] = &[
DefaultParam {
name: "width",
default: DefaultParamValue::Number(0.9),
constraint: ParamConstraint::number_range(0.0, 1.0),
},
DefaultParam {
name: "position",
default: DefaultParamValue::String("stack"),
constraint: ParamConstraint::string_enum(POSITION_VALUES),
},
]
];
PARAMS
}

fn stat_consumed_aesthetics(&self) -> &'static [&'static str] {
Expand Down
14 changes: 10 additions & 4 deletions src/plot/layer/geom/boxplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

use std::collections::HashMap;

use super::types::POSITION_VALUES;
use super::{DefaultAesthetics, GeomTrait, GeomType};
use crate::{
naming,
plot::{
geom::types::get_column_name, DefaultAestheticValue, DefaultParam, DefaultParamValue,
ParameterValue, StatResult,
ParamConstraint, ParameterValue, StatResult,
},
reader::SqlDialect,
DataFrame, GgsqlError, Mappings, Result,
Expand Down Expand Up @@ -50,24 +51,29 @@ impl GeomTrait for Boxplot {
}

fn default_params(&self) -> &'static [super::DefaultParam] {
&[
const PARAMS: &[DefaultParam] = &[
DefaultParam {
name: "outliers",
default: super::DefaultParamValue::Boolean(true),
default: DefaultParamValue::Boolean(true),
constraint: ParamConstraint::boolean(),
},
DefaultParam {
name: "coef",
default: DefaultParamValue::Number(1.5),
constraint: ParamConstraint::number_min(0.0),
},
DefaultParam {
name: "width",
default: DefaultParamValue::Number(0.9),
constraint: ParamConstraint::number_range(0.0, 1.0),
},
DefaultParam {
name: "position",
default: DefaultParamValue::String("dodge"),
constraint: ParamConstraint::string_enum(POSITION_VALUES),
},
]
];
PARAMS
}

fn default_remappings(&self) -> &'static [(&'static str, DefaultAestheticValue)] {
Expand Down
24 changes: 21 additions & 3 deletions src/plot/layer/geom/density.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Density geom implementation

use super::types::POSITION_VALUES;
use super::{DefaultAesthetics, GeomTrait, GeomType};
use crate::{
naming,
plot::{
geom::types::get_column_name, DefaultAestheticValue, DefaultParam, DefaultParamValue,
ParameterValue, StatResult,
ParamConstraint, ParameterValue, StatResult,
},
reader::SqlDialect,
GgsqlError, Mappings, Result,
Expand All @@ -16,6 +17,18 @@ use std::collections::HashMap;
/// Precomputed at compile time to avoid repeated SQRT and PI() calls in SQL
const GAUSSIAN_NORM: f64 = 0.3989422804014327; // 1.0 / (2.0 * std::f64::consts::PI).sqrt()

/// Valid kernel types for density estimation
const KERNEL_VALUES: &[&str] = &[
"gaussian",
"epanechnikov",
"triangular",
"rectangular",
"uniform",
"biweight",
"quartic",
"cosine",
];

/// Density geom - kernel density estimation
#[derive(Debug, Clone, Copy)]
pub struct Density;
Expand Down Expand Up @@ -45,24 +58,29 @@ impl GeomTrait for Density {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[
const PARAMS: &[DefaultParam] = &[
DefaultParam {
name: "position",
default: DefaultParamValue::String("identity"),
constraint: ParamConstraint::string_enum(POSITION_VALUES),
},
DefaultParam {
name: "bandwidth",
default: DefaultParamValue::Null,
constraint: ParamConstraint::number_min_exclusive(0.0),
},
DefaultParam {
name: "adjust",
default: DefaultParamValue::Number(1.0),
constraint: ParamConstraint::number_min_exclusive(0.0),
},
DefaultParam {
name: "kernel",
default: DefaultParamValue::String("gaussian"),
constraint: ParamConstraint::string_enum(KERNEL_VALUES),
},
]
];
PARAMS
}

fn default_remappings(&self) -> &'static [(&'static str, DefaultAestheticValue)] {
Expand Down
12 changes: 9 additions & 3 deletions src/plot/layer/geom/errorbar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! ErrorBar geom implementation

use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType};
use super::types::POSITION_VALUES;
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
};
use crate::plot::types::DefaultAestheticValue;

/// ErrorBar geom - error bars (confidence intervals)
Expand Down Expand Up @@ -30,16 +33,19 @@ impl GeomTrait for ErrorBar {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[
const PARAMS: &[DefaultParam] = &[
DefaultParam {
name: "position",
default: DefaultParamValue::String("identity"),
constraint: ParamConstraint::string_enum(POSITION_VALUES),
},
DefaultParam {
name: "width",
default: DefaultParamValue::Number(10.0),
constraint: ParamConstraint::number_min(0.0),
},
]
];
PARAMS
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/plot/layer/geom/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

use std::collections::HashMap;

use super::types::get_column_name;
use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, StatResult};
use super::types::{get_column_name, CLOSED_VALUES, POSITION_VALUES};
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
StatResult,
};
use crate::naming;
use crate::plot::types::{DefaultAestheticValue, ParameterValue};
use crate::reader::SqlDialect;
Expand Down Expand Up @@ -49,24 +52,29 @@ impl GeomTrait for Histogram {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[
const PARAMS: &[DefaultParam] = &[
DefaultParam {
name: "bins",
default: DefaultParamValue::Number(30.0),
constraint: ParamConstraint::number_min(1.0),
},
DefaultParam {
name: "closed",
default: DefaultParamValue::String("right"),
constraint: ParamConstraint::string_enum(CLOSED_VALUES),
},
DefaultParam {
name: "binwidth",
default: DefaultParamValue::Null,
constraint: ParamConstraint::number_min_exclusive(0.0),
},
DefaultParam {
name: "position",
default: DefaultParamValue::String("stack"),
constraint: ParamConstraint::string_enum(POSITION_VALUES),
},
]
];
PARAMS
}

fn stat_consumed_aesthetics(&self) -> &'static [&'static str] {
Expand Down
11 changes: 8 additions & 3 deletions src/plot/layer/geom/label.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Label geom implementation

use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType};
use super::types::POSITION_VALUES;
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
};
use crate::plot::types::DefaultAestheticValue;

/// Label geom - text labels with background
Expand Down Expand Up @@ -31,10 +34,12 @@ impl GeomTrait for Label {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[DefaultParam {
const PARAMS: &[DefaultParam] = &[DefaultParam {
name: "position",
default: DefaultParamValue::String("identity"),
}]
constraint: ParamConstraint::string_enum(POSITION_VALUES),
}];
PARAMS
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/plot/layer/geom/line.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Line geom implementation

use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, StatResult};
use crate::plot::layer::orientation::ALIGNED;
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
StatResult,
};
use crate::plot::layer::orientation::{ALIGNED, ORIENTATION_VALUES};
use crate::plot::types::DefaultAestheticValue;
use crate::{naming, Mappings};

Expand All @@ -28,10 +31,12 @@ impl GeomTrait for Line {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[DefaultParam {
const PARAMS: &[DefaultParam] = &[DefaultParam {
name: "orientation",
default: DefaultParamValue::String(ALIGNED),
}]
constraint: ParamConstraint::string_enum(ORIENTATION_VALUES),
}];
PARAMS
}

fn needs_stat_transform(&self, _aesthetics: &Mappings) -> bool {
Expand Down
12 changes: 8 additions & 4 deletions src/plot/layer/geom/linear.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Linear geom implementation

use super::{DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType};
use crate::plot::layer::orientation::ALIGNED;
use super::{
DefaultAesthetics, DefaultParam, DefaultParamValue, GeomTrait, GeomType, ParamConstraint,
};
use crate::plot::layer::orientation::{ALIGNED, ORIENTATION_VALUES};
use crate::plot::types::DefaultAestheticValue;

/// Linear geom - lines with coefficient and intercept
Expand All @@ -27,10 +29,12 @@ impl GeomTrait for Linear {
}

fn default_params(&self) -> &'static [DefaultParam] {
&[DefaultParam {
const PARAMS: &[DefaultParam] = &[DefaultParam {
name: "orientation",
default: DefaultParamValue::String(ALIGNED),
}]
constraint: ParamConstraint::string_enum(ORIENTATION_VALUES),
}];
PARAMS
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/plot/layer/geom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tile;
mod violin;

// Re-export types
pub use types::{DefaultAesthetics, DefaultParam, DefaultParamValue, StatResult};
pub use types::{DefaultAesthetics, DefaultParam, DefaultParamValue, ParamConstraint, StatResult};

// Re-export geom structs for direct access if needed
pub use area::Area;
Expand Down
Loading
Loading