Skip to main content

Module compose

Module compose 

Source
Expand description

Plot composition for the native SVG path — a patchwork-style PlotGrid.

use ggplot_rs::prelude::*;
use ggplot_rs::data::Value;
let data = || vec![
    ("x".to_string(), (0..10).map(|i| Value::Float(i as f64)).collect::<Vec<_>>()),
    ("y".to_string(), (0..10).map(|i| Value::Float((i * i) as f64)).collect::<Vec<_>>()),
];
let p = || GGPlot::new(data()).aes(Aes::new().x("x").y("y"));
// a | b puts plots side by side, a / b stacks them; `/` binds tighter.
let svg = ((p().geom_point() | p().geom_line()) / p().geom_col())
    .title("Diagnostics")
    .tag_levels(TagLevels::Lower)
    .render_svg_native_with_size(900, 700)
    .unwrap();
assert!(svg.contains("data-panel=\"a\"") && svg.contains("data-panel=\"c\""));

Every sub-plot is rendered as a positioned nested <svg> fragment (see GGPlot::render_svg_native_at) that keeps all of its host attributes (data-plot, data-domain, marks’ data-x/data-series/data-value) and additionally carries data-panel="<tag or index>". A host maps a pointer to data coordinates by first finding the enclosing sub-<svg>.

Structs§

PlotGrid
A patchwork-style arrangement of plots rendered into one SVG on the plotters-free native path.

Enums§

GridCell
One grid cell.
GridLegendPosition
Where a PlotGrid puts its collected legends.
TagLevels
Panel-tag sequence (patchwork’s tag_levels).