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