Skip to main content

Crate kuva

Crate kuva 

Source
Expand description

Scientific plotting library for bioinformatics, targeting SVG output with optional PNG and PDF backends.

§Pipeline

plot definition  →  Layout  →  Scene (primitives)  →  backend output
  1. Build a plot struct using its builder API (e.g. plot::scatter::ScatterPlot).
  2. Collect plots into a Vec<render::plots::Plot> — use .into() on any plot struct.
  3. Build a render::layout::Layout with render::layout::Layout::auto_from_plots and customise it.
  4. Call render_to_svg (or render_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

FeatureDescription
pngEnables PngBackend for rasterising SVG scenes via resvg.
pdfEnables PdfBackend for vector PDF output via svg2pdf.
cliEnables the kuva CLI binary (pulls in clap).
fullEnables 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§

backend
plot
prelude
Convenience re-exports for the most commonly used types.
render

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 feature png).
render_to_svg
Render a collection of plots to an SVG string in one call.