Skip to main content

ggplot_rs/render/
mod.rs

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