Skip to main content

ggplot_rs/render/
mod.rs

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