pub struct MosaicPlot {
pub cells: Vec<MosaicCell>,
pub col_order: Vec<String>,
pub row_order: Vec<String>,
pub group_colors: Option<Vec<String>>,
pub gap: f64,
pub show_percents: bool,
pub show_values: bool,
pub min_label_height: f64,
pub min_label_width: f64,
pub normalize: bool,
pub legend_label: Option<String>,
}Expand description
A mosaic / Marimekko chart.
Encodes two categorical variables simultaneously: column widths are proportional to column totals, and segment heights within each column represent the row breakdown of that column’s total. Each cell’s area is proportional to its joint frequency.
§Example
use kuva::plot::mosaic::MosaicPlot;
use kuva::render::plots::Plot;
use kuva::render::layout::Layout;
use kuva::render::render::render_multiple;
use kuva::backend::svg::SvgBackend;
let plot = MosaicPlot::new()
.with_cell("Control", "Positive", 30.0)
.with_cell("Control", "Negative", 70.0)
.with_cell("Treated", "Positive", 60.0)
.with_cell("Treated", "Negative", 40.0)
.with_legend("Response");
let plots = vec![Plot::Mosaic(plot)];
let layout = Layout::auto_from_plots(&plots).with_title("Treatment vs Response");
let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write("mosaic.svg", svg).unwrap();Fields§
§cells: Vec<MosaicCell>§col_order: Vec<String>Explicit column ordering. Empty = first-seen order from cells.
row_order: Vec<String>Explicit row/segment ordering. Empty = first-seen order from cells.
group_colors: Option<Vec<String>>Per-row-category colors. Falls back to category10 palette.
gap: f64Pixel gap between columns and between segments (default: 2.0).
show_percents: boolShow percentage labels inside cells (default: true).
show_values: boolShow raw value labels inside cells (default: false).
min_label_height: f64Suppress labels when cell height is below this many pixels (default: 18.0).
min_label_width: f64Suppress labels when cell width is below this many pixels (default: 30.0).
normalize: boolNormalize each column to full plot height (default: true).
When false, column heights are proportional to their share of the grand total.
legend_label: Option<String>Legend group title.
Implementations§
Source§impl MosaicPlot
impl MosaicPlot
pub fn new() -> Self
Sourcepub fn with_cell(
self,
col: impl Into<String>,
row: impl Into<String>,
value: impl Into<f64>,
) -> Self
pub fn with_cell( self, col: impl Into<String>, row: impl Into<String>, value: impl Into<f64>, ) -> Self
Add a single cell (col × row = value).
Sourcepub fn with_cells<C, R, V, I>(self, cells: I) -> Self
pub fn with_cells<C, R, V, I>(self, cells: I) -> Self
Add multiple cells at once.
Sourcepub fn with_col_order(
self,
order: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_col_order( self, order: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set explicit column ordering.
Sourcepub fn with_row_order(
self,
order: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_row_order( self, order: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set explicit row/segment ordering.
Sourcepub fn with_group_colors(
self,
colors: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_group_colors( self, colors: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set per-row-category colors (indexed by row order).
Sourcepub fn with_gap(self, px: f64) -> Self
pub fn with_gap(self, px: f64) -> Self
Set the pixel gap between columns and between segments (default: 2.0).
Sourcepub fn with_percents(self, v: bool) -> Self
pub fn with_percents(self, v: bool) -> Self
Show percentage labels inside cells (default: true).
Sourcepub fn with_values(self, v: bool) -> Self
pub fn with_values(self, v: bool) -> Self
Show raw value labels inside cells (default: false).
Sourcepub fn with_min_label_height(self, px: f64) -> Self
pub fn with_min_label_height(self, px: f64) -> Self
Minimum cell height in pixels before labels are suppressed (default: 18.0).
Sourcepub fn with_normalize(self, v: bool) -> Self
pub fn with_normalize(self, v: bool) -> Self
Normalize each column to full plot height (default: true).
Sourcepub fn with_legend(self, label: impl Into<String>) -> Self
pub fn with_legend(self, label: impl Into<String>) -> Self
Attach a legend with the given title (one entry per row category).
Trait Implementations§
Source§impl Clone for MosaicPlot
impl Clone for MosaicPlot
Source§fn clone(&self) -> MosaicPlot
fn clone(&self) -> MosaicPlot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MosaicPlot
impl Debug for MosaicPlot
Source§impl Default for MosaicPlot
impl Default for MosaicPlot
Source§impl From<MosaicPlot> for Plot
impl From<MosaicPlot> for Plot
Source§fn from(p: MosaicPlot) -> Self
fn from(p: MosaicPlot) -> Self
Auto Trait Implementations§
impl Freeze for MosaicPlot
impl RefUnwindSafe for MosaicPlot
impl Send for MosaicPlot
impl Sync for MosaicPlot
impl Unpin for MosaicPlot
impl UnsafeUnpin for MosaicPlot
impl UnwindSafe for MosaicPlot
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.