pub struct PlotGrid { /* private fields */ }Expand description
A patchwork-style arrangement of plots rendered into one SVG on the plotters-free native path.
- cells fill row-major (or column-major with
byrow(false)) acrossncol/nrow(default: a near-square grid;a | bis one row,a / bone column); widths/heightsset relative column widths / row heights;title/subtitle/captionannotate the whole grid;tag_levelstags panelsa, b, …(A,1, roman, custom) in reading order, through nested grids;collect_legendsremoves the sub-plots’ legends and draws each distinct legend once beside the grid (identical legends are de-duplicated).
Nested grids keep their own layout and annotations; tagging and legend collection are controlled by the outermost grid.
Implementations§
Source§impl PlotGrid
impl PlotGrid
pub fn new() -> Self
Sourcepub fn add(self, cell: impl Into<GridCell>) -> Self
pub fn add(self, cell: impl Into<GridCell>) -> Self
Append a plot (or a nested grid) as the next cell.
Sourcepub fn add_all(self, plots: impl IntoIterator<Item = GGPlot>) -> Self
pub fn add_all(self, plots: impl IntoIterator<Item = GGPlot>) -> Self
Append several plots.
Sourcepub fn add_spacer(self) -> Self
pub fn add_spacer(self) -> Self
Append an empty cell (patchwork’s plot_spacer()).
Sourcepub fn widths(self, widths: &[f64]) -> Self
pub fn widths(self, widths: &[f64]) -> Self
Relative column widths (recycled; non-positive / non-finite = 1).
Sourcepub fn heights(self, heights: &[f64]) -> Self
pub fn heights(self, heights: &[f64]) -> Self
Relative row heights (recycled; non-positive / non-finite = 1).
Sourcepub fn tag_levels(self, levels: TagLevels) -> Self
pub fn tag_levels(self, levels: TagLevels) -> Self
Tag the panels (labs(tag) of each sub-plot is replaced).
Sourcepub fn tag_affixes(self, prefix: &str, suffix: &str) -> Self
pub fn tag_affixes(self, prefix: &str, suffix: &str) -> Self
Text around each tag, e.g. ("(", ")") for (a).
Sourcepub fn collect_legends(self, collect: bool) -> Self
pub fn collect_legends(self, collect: bool) -> Self
Collect the sub-plots’ legends into one strip (identical legends are drawn once). Sub-plots with an inside or hidden legend keep it.
Sourcepub fn legend_position(self, pos: GridLegendPosition) -> Self
pub fn legend_position(self, pos: GridLegendPosition) -> Self
Where collected legends go.
Sourcepub fn legend_bottom_when_narrow(self, share: f64) -> Self
pub fn legend_bottom_when_narrow(self, share: f64) -> Self
Move a Right collected-legend column
to a row below the grid when it would take more than share (0..1)
of the grid’s width at render time — the grid counterpart of
GGPlot::legend_bottom_when_narrow (#363). The column is roughly
fixed in size, so on a phone-width render it squeezes the rightmost
cells; a render wide enough keeps Right, unchanged. Off by
default; no effect on Bottom.
Sourcepub fn axis_collect(self, mode: AxisCollect) -> Self
pub fn axis_collect(self, mode: AxisCollect) -> Self
Align this grid’s own direct cells’ plot areas and/or x scale,
one column at a time — see AxisCollect (sipemu/ggplot-rs#175).
Default AxisCollect::Keep (no change, byte-identical output).
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
Theme for the grid’s own title/subtitle/caption and the collected legends’ text.
Sourcepub fn svg_attr(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn svg_attr(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add one extra attribute to the root <svg> element — see
GGPlot::svg_attr, same allow-list
(data-*, aria-*, role, id, class, lang) and the same
“ignored with a warning” rule for anything else or a collision with
what ggplot-rs already writes (data-grid, or data-warnings when
svg_warnings_attr is also on).
Sourcepub fn svg_attrs(
self,
attrs: impl IntoIterator<Item = (String, String)>,
) -> Self
pub fn svg_attrs( self, attrs: impl IntoIterator<Item = (String, String)>, ) -> Self
svg_attr for several attributes at once.
Sourcepub fn svg_warnings_attr(self, on: bool) -> Self
pub fn svg_warnings_attr(self, on: bool) -> Self
Emit a data-warnings attribute on the root <svg> — a JSON array
of every panel’s combined build warnings, [] when there are none.
Default off, and omitted entirely when off.
Sourcepub fn render_svg_native(self) -> Result<String, GGError>
pub fn render_svg_native(self) -> Result<String, GGError>
Render at 800×600.
Sourcepub fn render_svg_native_with_size(
self,
w: u32,
h: u32,
) -> Result<String, GGError>
pub fn render_svg_native_with_size( self, w: u32, h: u32, ) -> Result<String, GGError>
Render the grid to one standalone SVG document of w×h px. The root
carries data-grid="<rows> <cols>" (and no data-plot: each sub-<svg>
has its own).
Sourcepub fn render_svg_native_with_warnings(
self,
w: u32,
h: u32,
) -> Result<(String, Vec<String>), GGError>
pub fn render_svg_native_with_warnings( self, w: u32, h: u32, ) -> Result<(String, Vec<String>), GGError>
Like render_svg_native_with_size,
also returning every sub-plot’s warnings, prefixed panel <tag>: .
Sourcepub fn render_svg_native_at(
self,
x: f64,
y: f64,
w: u32,
h: u32,
) -> Result<String, GGError>
pub fn render_svg_native_at( self, x: f64, y: f64, w: u32, h: u32, ) -> Result<String, GGError>
Render as a nested <svg> fragment positioned at (x, y) — for
composing the grid into a larger SVG (cf. GGPlot::render_svg_native_at).
Trait Implementations§
Source§impl BitOr<GridElement> for PlotGrid
a | b: place side by side (patchwork).
impl BitOr<GridElement> for PlotGrid
a | b: place side by side (patchwork).
Source§impl BitOr<PlotGrid> for GridElement
a | b: place side by side (patchwork).
impl BitOr<PlotGrid> for GridElement
a | b: place side by side (patchwork).
Source§impl Div<GridElement> for PlotGrid
a / b: stack vertically (patchwork).
impl Div<GridElement> for PlotGrid
a / b: stack vertically (patchwork).
Source§impl Div<PlotGrid> for GridElement
a / b: stack vertically (patchwork).
impl Div<PlotGrid> for GridElement
a / b: stack vertically (patchwork).
Auto Trait Implementations§
impl !RefUnwindSafe for PlotGrid
impl !UnwindSafe for PlotGrid
impl Forget for PlotGrid
impl Freeze for PlotGridwhere
*const u8 is !null: Freeze,
PhantomData<GridCell>: Freeze,
PhantomData<f64>: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
PhantomData<(f64, f64)>: Freeze,
PhantomData<(String, String)>: Freeze,
impl Move for PlotGrid
impl Send for PlotGrid
impl Sync for PlotGrid
impl Unpin for PlotGrid
impl UnsafeUnpin for PlotGridwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<GridCell>: UnsafeUnpin,
PhantomData<f64>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<(f64, f64)>: UnsafeUnpin,
PhantomData<(String, String)>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more