Skip to main content

ggplot_rs/render/
mod.rs

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