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