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 adds a self-contained, theme-categorical ChartView (line/bar/scatter with a derived legend/axes/tooltip, no egui_plot dep) plus 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::BoxPlotEffect;
pub use boxplot::BoxPlotMsg;
pub use boxplot::BoxPlotState;
pub use boxplot::BoxPlotView;
pub use boxplot::Quartiles;
pub use chart::ChartEffect;
pub use chart::ChartKind;
pub use chart::ChartMsg;
pub use chart::ChartState;
pub use chart::ChartView;
pub use chart::Series;
pub use palette::series_color;
pub use palette::series_palette;
pub use candlestick::CandlestickEffect;
pub use candlestick::CandlestickMsg;
pub use candlestick::CandlestickState;
pub use candlestick::CandlestickView;
pub use candlestick::Ohlc;
pub use candlestick::OhlcLayout;
pub use heatmap::HeatmapEffect;
pub use heatmap::HeatmapMsg;
pub use heatmap::HeatmapState;
pub use heatmap::HeatmapView;
pub use ramp::Ramp;
pub use treemap::Tile;
pub use treemap::TreemapEffect;
pub use treemap::TreemapMsg;
pub use treemap::TreemapState;
pub use treemap::TreemapView;
pub use violin::Density;
pub use violin::ViolinEffect;
pub use violin::ViolinMsg;
pub use violin::ViolinState;
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.
chart
Line · bar · scatter — the everyday XY chart, one themeable Elm [Facet]. Data goes in as the simplest possible model — a Vec of named series, each a Vec<(x, y)> — and everything else (axis bounds, gridlines, the legend, the hover tooltip) is derived. The chart kind is a single field in the model, so flipping line↔bar↔scatter is one Msg and is fully observable 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.
palette
Categorical series palette — a small, validated set of hues assigned to chart series in a fixed order, never a random per-string hash. Line/bar/scatter series are identity-coded (which series is which), so this is the categorical job from the dataviz method: a fixed order maximising the minimum adjacent colour-vision-deficiency separation, with a light-surface and a dark-surface step of the same eight hues (not two unrelated palettes).
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.