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§

AxisCollect
How a PlotGrid aligns its own direct cells’ plot areas and x scale within each column (patchwork’s plot_layout(axes = ...), applied to the x axis and plot-area alignment specifically — sipemu/ ggplot-rs#175, tracked from DataZooDE/anofox-visualization#318). Only a column of GridCell::Plot cells participates; a GridCell::Spacer or a nested PlotGrid cell keeps its own layout, and a column with fewer than two plot cells is a no-op. Set via PlotGrid::axis_collect.
GridCell
One grid cell.
GridLegendPosition
Where a PlotGrid puts its collected legends.
TagLevels
Panel-tag sequence (patchwork’s tag_levels).