1pub mod area;
2pub mod bar;
3pub mod bin2d;
4pub mod blank;
5pub mod boxplot;
6pub mod bracket;
7pub mod col;
8pub mod contour;
9pub mod count;
10pub mod crossbar;
11pub mod curve;
12pub mod density;
13pub mod density2d;
14pub mod dotplot;
15pub mod errorbar;
16pub mod freqpoly;
17pub mod hex;
18pub mod histogram;
19pub mod jitter;
20pub mod line;
21pub mod linerange;
22pub mod path;
23pub mod point;
24pub mod pointrange;
25pub mod polygon;
26pub mod qq;
27pub mod raster;
28pub mod rect;
29pub mod refline;
30pub mod ribbon;
31pub mod rug;
32pub mod segment;
33#[cfg(feature = "sf")]
34pub mod sf;
35pub mod smooth;
36pub mod spoke;
37pub mod step;
38pub mod text;
39pub mod tile;
40pub mod violin;
41
42use std::collections::HashMap;
43
44use crate::aes::Aesthetic;
45use crate::coord::Coord;
46use crate::data::DataFrame;
47use crate::position::Position;
48use crate::render::backend::DrawBackend;
49use crate::render::RenderError;
50use crate::scale::ScaleSet;
51use crate::stat::Stat;
52use crate::theme::Theme;
53
54#[derive(Clone, Debug, Default)]
56pub struct GeomParams {
57 pub values: HashMap<String, f64>,
58 pub color: Option<(u8, u8, u8)>,
59 pub fill: Option<(u8, u8, u8)>,
60 pub alpha: Option<f64>,
61}
62
63pub trait Geom: Send + Sync {
65 fn draw(
67 &self,
68 data: &DataFrame,
69 coord: &dyn Coord,
70 scales: &ScaleSet,
71 theme: &Theme,
72 backend: &mut dyn DrawBackend,
73 ) -> Result<(), RenderError>;
74
75 fn required_aes(&self) -> Vec<Aesthetic>;
77
78 fn default_stat(&self) -> Box<dyn Stat>;
80
81 fn default_position(&self) -> Box<dyn Position>;
83
84 fn default_params(&self) -> GeomParams;
86
87 fn name(&self) -> &str;
89
90 fn set_series_color(&mut self, _color: (u8, u8, u8)) {}
95
96 fn include_zero_baseline(&self) -> bool {
100 false
101 }
102}
103
104pub(crate) fn tip_value(v: &crate::data::Value) -> String {
107 use crate::data::Value;
108 match v {
109 Value::Str(s) => s.clone(),
110 Value::Bool(b) => b.to_string(),
111 Value::Na => String::new(),
112 Value::DateTime(secs) => crate::data::format_epoch_secs(*secs),
114 _ => v
115 .as_f64()
116 .map(|f| format!("{}", (f * 1000.0).round() / 1000.0))
117 .unwrap_or_default(),
118 }
119}