Skip to main content

Crate facett_plotters

Crate facett_plotters 

Source
Expand description

facett-plotters — the chart types egui_plot (→ facett-plot) lacks, painted in immediate mode directly on an egui::Painter. egui_plot already covers line/scatter/bar/histogram with zoom/pan; this crate fills the analytics long-tail Plotly defines:

§Why hand-rolled, not the plotters crate

The plotters crate is retained + raster/SVG-backend driven: its egui integration renders to a bitmap and blits a texture every frame, with no immediate-mode hit-testing, no live theming, and no hover model. facett’s charts must read [facett_core::theme] live (re-skin on theme switch), expose cheap hover-readouts, and implement the Facet contract (caps() + copy() → CSV). Hand-painting on the egui Painter (the same path facett-core/facett-map use) is the lighter, better-fitting choice — so plotters is not a dependency.

§Theme-derived colour ramps

No palette is hardcoded. ramp::Ramp builds a sequential (bg→accent→glow) or diverging (accent→text_dim→glow) ramp purely from the active Theme, so heatmaps/treemaps follow whatever theme is set.

Each view is a Facet: it declares caps().themeable().copyable().resizable(), paints itself, and copy() emits the underlying data as CSV. The data→geometry math (quartiles, KDE bins, OHLC mapping, heatmap cell layout, treemap squarify) lives in pure, tested functions that need no GPU.

Re-exports§

pub use boxplot::BoxPlotView;
pub use boxplot::Quartiles;
pub use candlestick::CandlestickView;
pub use candlestick::Ohlc;
pub use candlestick::OhlcLayout;
pub use heatmap::HeatmapView;
pub use ramp::Ramp;
pub use treemap::Tile;
pub use treemap::TreemapView;
pub use violin::Density;
pub use violin::ViolinView;

Modules§

boxplot
Box plot — quartiles + whiskers + outliers, one box per named group. The data→geometry math (Quartiles::from_sorted / Quartiles::compute) is a pure function with its own tests; BoxPlotView is the themeable Facet that paints it and emits the underlying data as CSV/JSON.
candlestick
Candlestick (OHLC) chart. Each bar is an open/high/low/close tuple drawn as a wick (high→low) + a body (open↔close), coloured up/down from theme colours. The price→pixel mapping (OhlcLayout) is a pure function with tests so the geometry is verifiable headlessly.
heatmap
Heatmap — a rows × cols matrix painted as a colour grid using a theme-derived Ramp, with a gradient legend. The cell-layout math (cell_rect) is a pure function with tests so the grid geometry can be verified headlessly.
ramp
Theme-derived colour ramps. No hardcoded palette: a sequential ramp is built from the theme’s bg → accent → glow, and a diverging ramp from accent (low) through a neutral midpoint to glow (high). Charts call Ramp::at with a normalised t ∈ 0..=1 to map a scalar to a colour.
treemap
Treemap — weighted rectangles, area ∝ value, laid out by a deterministic slice-and-dice algorithm that alternates split direction by depth-of-cut so the tiling stays readable. The layout (squarify) is a pure function returning (index, Rect) pairs, tested independently of any painter. Tile fills come from a theme-derived sequential Ramp.
violin
Violin plot — a mirrored kernel-density silhouette per group. The KDE (kde) is a pure function (Gaussian kernel, Silverman bandwidth) sampled on an evenly-spaced grid; ViolinView paints the mirrored density as a filled polygon and overlays the median line.