Skip to main content

MosaicPlot

Struct MosaicPlot 

Source
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: f64

Pixel gap between columns and between segments (default: 2.0).

§show_percents: bool

Show percentage labels inside cells (default: true).

§show_values: bool

Show raw value labels inside cells (default: false).

§min_label_height: f64

Suppress labels when cell height is below this many pixels (default: 18.0).

§min_label_width: f64

Suppress labels when cell width is below this many pixels (default: 30.0).

§normalize: bool

Normalize 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

Source

pub fn new() -> Self

Source

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).

Source

pub fn with_cells<C, R, V, I>(self, cells: I) -> Self
where C: Into<String>, R: Into<String>, V: Into<f64>, I: IntoIterator<Item = (C, R, V)>,

Add multiple cells at once.

Source

pub fn with_col_order( self, order: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set explicit column ordering.

Source

pub fn with_row_order( self, order: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set explicit row/segment ordering.

Source

pub fn with_group_colors( self, colors: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set per-row-category colors (indexed by row order).

Source

pub fn with_gap(self, px: f64) -> Self

Set the pixel gap between columns and between segments (default: 2.0).

Source

pub fn with_percents(self, v: bool) -> Self

Show percentage labels inside cells (default: true).

Source

pub fn with_values(self, v: bool) -> Self

Show raw value labels inside cells (default: false).

Source

pub fn with_min_label_height(self, px: f64) -> Self

Minimum cell height in pixels before labels are suppressed (default: 18.0).

Source

pub fn with_normalize(self, v: bool) -> Self

Normalize each column to full plot height (default: true).

Source

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

Source§

fn clone(&self) -> MosaicPlot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MosaicPlot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MosaicPlot

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<MosaicPlot> for Plot

Source§

fn from(p: MosaicPlot) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.