Expand description
Scientific plotting library for bioinformatics, targeting SVG output with optional PNG and PDF backends.
§Pipeline
plot definition → Layout → Scene (primitives) → backend output- Build a plot struct using its builder API (e.g.
plot::scatter::ScatterPlot). - Collect plots into a
Vec<render::plots::Plot>— use.into()on any plot struct. - Build a
render::layout::Layoutwithrender::layout::Layout::auto_from_plotsand customise it. - Call
render_to_svg(orrender_to_png/render_to_pdf) to get the output in one step.
§Example
use kuva::prelude::*;
let scatter = ScatterPlot::new()
.with_data(vec![(1.0_f64, 2.0), (3.0, 4.0)])
.with_color("steelblue");
let plots: Vec<Plot> = vec![scatter.into()];
let svg = kuva::render_to_svg(plots, Layout::auto_from_plots(&[]));
assert!(svg.contains("<svg"));§Feature flags
| Feature | Description |
|---|---|
png | Enables PngBackend for rasterising SVG scenes via resvg. |
pdf | Enables PdfBackend for vector PDF output via svg2pdf. |
cli | Enables the kuva CLI binary (pulls in clap). |
full | Enables png + pdf. |
§Fonts
DejaVu Sans is bundled inside the crate. The PNG and PDF backends always load it before scanning system fonts, so text renders correctly even in minimal environments (containers, CI pipelines) with no installed fonts.
SVG output references fonts by name and relies on the viewer to resolve them.
For self-contained SVGs that work anywhere, use
backend::svg::SvgBackend::with_embedded_font or the --embed-font CLI flag.
This bakes DejaVu Sans as a base64 @font-face block into the SVG at the cost
of roughly 1 MB of added file size.
Re-exports§
pub use backend::terminal::TerminalBackend;pub use backend::png::PngBackend;pub use backend::raster::RasterBackend;pub use backend::pdf::PdfBackend;pub use render::datetime::ymd;pub use render::datetime::ymd_hms;pub use render::datetime::DateTimeAxis;pub use render::datetime::DateUnit;pub use render::render_utils::silverman_bandwidth;pub use render::render_utils::simple_kde;pub use render::layout::TickFormat;pub use render::palette::Palette;pub use render::render::render_calendar;pub use render::render::render_phylo_tree;pub use render::render::render_sankey;pub use render::render::render_synteny;pub use render::render::render_twin_y;pub use render::render_utils::simple_kde_reflect;pub use render::theme::Theme;
Modules§
Functions§
- render_
to_ pdf - Render a collection of plots to a PDF byte vector in one call (requires feature
pdf). - render_
to_ png - Render a collection of plots to a PNG byte vector in one call (requires feature
png). - render_
to_ raster - Render a collection of plots directly to a PNG byte vector via
tiny_skia, bypassing SVG serialization and re-parsing (requires featurepng). - render_
to_ svg - Render a collection of plots to an SVG string in one call.