Skip to main content

ggplot_rs/geom/
mod.rs

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 rect;
27pub mod refline;
28pub mod ribbon;
29pub mod rug;
30pub mod segment;
31pub mod smooth;
32pub mod spoke;
33pub mod step;
34pub mod text;
35pub mod tile;
36pub mod violin;
37
38use std::collections::HashMap;
39
40use crate::aes::Aesthetic;
41use crate::coord::Coord;
42use crate::data::DataFrame;
43use crate::position::Position;
44use crate::render::backend::DrawBackend;
45use crate::render::RenderError;
46use crate::scale::ScaleSet;
47use crate::stat::Stat;
48use crate::theme::Theme;
49
50/// Fixed (non-mapped) visual parameters for a geom.
51#[derive(Clone, Debug, Default)]
52pub struct GeomParams {
53    pub values: HashMap<String, f64>,
54    pub color: Option<(u8, u8, u8)>,
55    pub fill: Option<(u8, u8, u8)>,
56    pub alpha: Option<f64>,
57}
58
59/// Trait for geometric objects that draw data on the plot.
60pub trait Geom: Send + Sync {
61    /// Draw this geometry.
62    fn draw(
63        &self,
64        data: &DataFrame,
65        coord: &dyn Coord,
66        scales: &ScaleSet,
67        theme: &Theme,
68        backend: &mut dyn DrawBackend,
69    ) -> Result<(), RenderError>;
70
71    /// Required aesthetics.
72    fn required_aes(&self) -> Vec<Aesthetic>;
73
74    /// Default stat for this geom.
75    fn default_stat(&self) -> Box<dyn Stat>;
76
77    /// Default position adjustment.
78    fn default_position(&self) -> Box<dyn Position>;
79
80    /// Non-mapped visual defaults.
81    fn default_params(&self) -> GeomParams;
82
83    /// Name for debug/display.
84    fn name(&self) -> &str;
85
86    /// Apply a brand/primary color to this geom's single-series default (its
87    /// `color` or `fill`). The build pipeline calls this only when the layer has
88    /// no color/fill aesthetic mapped, so an explicit mapping always wins. The
89    /// default is a no-op; series geoms override it.
90    fn set_series_color(&mut self, _color: (u8, u8, u8)) {}
91}