Skip to main content

ggplot_rs/render/
mod.rs

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