render_to_svg
- Build plot structs using their builder APIs
- Collect plots into a
Vec<Plot> - Build a
LayoutwithLayout::auto_from_plotsand customize it - Call
render_to_svgto get the output
A vector of plot objects to render. Use
.into() on any plot struct to convert it to the Plot enum.The layout configuration defining the plot dimensions, axes, ranges, and styling. Use
Layout::auto_from_plots(&plots) to generate a reasonable default, then customize as needed.An SVG string containing the complete rendered visualization.
Example
Advanced Usage
For fine-grained control (custom layout, twin axes, special-case plot types), userender::render::render_multiple and backend::svg::SvgBackend directly.
render_to_png
png feature flag.
A vector of plot objects to render.
The layout configuration defining the plot dimensions, axes, ranges, and styling.
The pixel density multiplier.
1.0 matches the SVG logical size, 2.0 (the PngBackend default) gives retina/HiDPI quality. Higher values produce larger, higher-resolution images.On success, returns a
Vec<u8> containing the PNG image data. On failure, returns an error string if SVG parsing or rasterization fails.Example
Feature Flag
This function requires thepng feature to be enabled in your Cargo.toml:
Advanced Usage
For fine-grained control, userender::render::render_multiple and backend::png::PngBackend directly.
render_to_pdf
pdf feature flag.
A vector of plot objects to render.
The layout configuration defining the plot dimensions, axes, ranges, and styling.
On success, returns a
Vec<u8> containing the PDF document data. On failure, returns an error string if SVG parsing or PDF conversion fails.Example
Feature Flag
This function requires thepdf feature to be enabled in your Cargo.toml:
Advanced Usage
For fine-grained control, userender::render::render_multiple and backend::pdf::PdfBackend directly.
Feature Flags Summary
| Feature | Description |
|---|---|
png | Enables render_to_png and PngBackend for rasterizing SVG scenes via resvg. |
pdf | Enables render_to_pdf and PdfBackend for vector PDF output via svg2pdf. |
full | Enables both png and pdf features. |
Pipeline Overview
All three render functions follow this internal pipeline:- Plot Definition: Build plot structs using their builder APIs (e.g.,
ScatterPlot::new()) - Layout: Define dimensions, axes, and styling with
Layout - Scene: Internal representation using geometric primitives
- Backend Output: Final rendering to SVG, PNG, or PDF