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 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/// Fixed (non-mapped) visual parameters for a geom.
54#[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
62/// Trait for geometric objects that draw data on the plot.
63pub trait Geom: Send + Sync {
64    /// Draw this geometry.
65    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    /// Required aesthetics.
75    fn required_aes(&self) -> Vec<Aesthetic>;
76
77    /// Default stat for this geom.
78    fn default_stat(&self) -> Box<dyn Stat>;
79
80    /// Default position adjustment.
81    fn default_position(&self) -> Box<dyn Position>;
82
83    /// Non-mapped visual defaults.
84    fn default_params(&self) -> GeomParams;
85
86    /// Name for debug/display.
87    fn name(&self) -> &str;
88
89    /// Apply a brand/primary color to this geom's single-series default (its
90    /// `color` or `fill`). The build pipeline calls this only when the layer has
91    /// no color/fill aesthetic mapped, so an explicit mapping always wins. The
92    /// default is a no-op; series geoms override it.
93    fn set_series_color(&mut self, _color: (u8, u8, u8)) {}
94}