Skip to main content

ggplot_rs/render/
mod.rs

1pub mod backend;
2pub mod corner_layout;
3pub mod layout;
4pub(crate) mod probe;
5#[cfg(feature = "png")]
6pub(crate) mod raster;
7// Self-contained RGBA raster backend for large-N (feature `canvas`); wasm-ok.
8#[cfg(feature = "canvas")]
9pub mod pixel_backend;
10// The plotters backend (PNG/bitmap + SVG via plotters) isn't available on wasm
11// (no bitmap/font-registration API there); the browser uses `svg_backend`.
12#[cfg(all(feature = "plotters", not(target_arch = "wasm32")))]
13pub mod plotters_backend;
14pub mod renderer;
15pub mod svg_backend;
16pub mod text;
17
18/// A rectangle in pixel coordinates.
19#[derive(Clone, Debug)]
20pub struct Rect {
21    pub x: f64,
22    pub y: f64,
23    pub width: f64,
24    pub height: f64,
25}
26
27/// Rendering error type.
28#[derive(Debug)]
29#[non_exhaustive]
30pub enum RenderError {
31    MissingAesthetic(String),
32    BackendError(String),
33    IoError(std::io::Error),
34}
35
36impl std::fmt::Display for RenderError {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        match self {
39            RenderError::MissingAesthetic(a) => write!(f, "Missing required aesthetic: {a}"),
40            RenderError::BackendError(e) => write!(f, "Backend error: {e}"),
41            RenderError::IoError(e) => write!(f, "IO error: {e}"),
42        }
43    }
44}
45
46impl std::error::Error for RenderError {}
47
48impl From<std::io::Error> for RenderError {
49    fn from(e: std::io::Error) -> Self {
50        RenderError::IoError(e)
51    }
52}