11//! Density geom implementation
22
3+ use super :: types:: POSITION_VALUES ;
34use super :: { DefaultAesthetics , GeomTrait , GeomType } ;
45use crate :: {
56 naming,
67 plot:: {
78 geom:: types:: get_column_name, DefaultAestheticValue , DefaultParam , DefaultParamValue ,
8- ParameterValue , StatResult ,
9+ ParamConstraint , ParameterValue , StatResult ,
910 } ,
1011 reader:: SqlDialect ,
1112 GgsqlError , Mappings , Result ,
@@ -16,6 +17,18 @@ use std::collections::HashMap;
1617/// Precomputed at compile time to avoid repeated SQRT and PI() calls in SQL
1718const GAUSSIAN_NORM : f64 = 0.3989422804014327 ; // 1.0 / (2.0 * std::f64::consts::PI).sqrt()
1819
20+ /// Valid kernel types for density estimation
21+ const KERNEL_VALUES : & [ & str ] = & [
22+ "gaussian" ,
23+ "epanechnikov" ,
24+ "triangular" ,
25+ "rectangular" ,
26+ "uniform" ,
27+ "biweight" ,
28+ "quartic" ,
29+ "cosine" ,
30+ ] ;
31+
1932/// Density geom - kernel density estimation
2033#[ derive( Debug , Clone , Copy ) ]
2134pub struct Density ;
@@ -45,24 +58,29 @@ impl GeomTrait for Density {
4558 }
4659
4760 fn default_params ( & self ) -> & ' static [ DefaultParam ] {
48- & [
61+ const PARAMS : & [ DefaultParam ] = & [
4962 DefaultParam {
5063 name : "position" ,
5164 default : DefaultParamValue :: String ( "identity" ) ,
65+ constraint : ParamConstraint :: string_enum ( POSITION_VALUES ) ,
5266 } ,
5367 DefaultParam {
5468 name : "bandwidth" ,
5569 default : DefaultParamValue :: Null ,
70+ constraint : ParamConstraint :: number_min_exclusive ( 0.0 ) ,
5671 } ,
5772 DefaultParam {
5873 name : "adjust" ,
5974 default : DefaultParamValue :: Number ( 1.0 ) ,
75+ constraint : ParamConstraint :: number_min_exclusive ( 0.0 ) ,
6076 } ,
6177 DefaultParam {
6278 name : "kernel" ,
6379 default : DefaultParamValue :: String ( "gaussian" ) ,
80+ constraint : ParamConstraint :: string_enum ( KERNEL_VALUES ) ,
6481 } ,
65- ]
82+ ] ;
83+ PARAMS
6684 }
6785
6886 fn default_remappings ( & self ) -> & ' static [ ( & ' static str , DefaultAestheticValue ) ] {
0 commit comments