Skip to main content

Crate model

Crate model 

Source
Expand description

§figgy-model

Chart settings and data definitions for figgy: Cartesian axes and series, interaction policies, and the bounded radial, categorical and boxplot models. This crate has no GPU or windowing dependency. The optional serde feature adds serialization and deserialization.

Applications using the renderer normally only need figgy-renderer, which re-exports these model types. Use this package directly when working with chart definitions without a renderer. Rust 1.99 is the declared support floor; lower versions have not been validated.

§Install

The Cargo package is figgy-model; its Rust import is model. Version 0.10.0 has not yet been published to crates.io. Until publication:

[dependencies]
model = { package = "figgy-model", git = "https://github.com/shim9610/figgy", rev = "0ae96fcb2d6c0ad5bd6167cc32f0e54b231162e0" }

For a local checkout, replace git/rev with path = "../figgy/crates/model". After publication and verification, use model = { package = "figgy-model", version = "0.10.0" }. Add features = ["serde"] only when serialization is needed. No feature is required for creating, editing or validating models.

§Create and edit a chart model

This example runs without a GPU. It creates a donut model, changes one value and validates it. A renderer consumes this same model to prepare pixels and hit maps.

use model::{Color, RadialChart, RadialKind, RadialSlice};

let mut chart = RadialChart {
    kind: RadialKind::Donut { inner_radius: 0.55 },
    slices: vec![
        RadialSlice::new("Control", 30.0, Color::from_rgb8(40, 140, 200)),
        RadialSlice::new("Treatment", 50.0, Color::from_rgb8(220, 160, 60)),
    ],
    ..Default::default()
};
chart.slices[1].value = 70.0;
assert!(chart.validate().is_ok());
assert_eq!(chart.slices.iter().map(|slice| slice.value).sum::<f64>(), 100.0);

§Find the relevant types

DataTypes
Cartesian axes, ticks, legends and stylesConfig, default::default_config, SeriesConfig
Numeric input columnsColumn, DataCell
Pie/donut slice values and presentationRadialChart, RadialSlice
Category/series barsCategoricalChart, BarSeries
Supplied statistical summariesBoxPlotChart, BoxPlotSeries
Selection, dragging and area handlesSelectable, Draggable, Resizable, DecorationLayout

Bounded charts have explicit validation and small-data limits. They do not require stream sources, and boxplots do not calculate statistics from raw samples. The renderer owns GPU resources, frame caches and its ColumnSource upload adapter; those are not part of this model crate. See the renderer interaction guide for applying model edits to displayed frames.

§Serialization and documentation

Serialization represents model state, not a versioned application file format. Validate externally supplied state before rendering. File storage, migrations and the meaning of supplied statistical summaries belong to the consuming application.

docs.rs includes the optional serde implementations. Build the same feature set locally with cargo doc --locked -p figgy-model --features serde --no-deps --open. Documentation and model tests need no GPU or windowing libraries.

Code is licensed under MIT OR Apache-2.0.

Run cargo test --features serde to check the model contracts and optional serialization. These tests require neither a GPU nor other source checkouts.

Re-exports§

pub use decoration::DecorationId;
pub use decoration::DecorationLayout;
pub use decoration::DecorationOffset;
pub use decoration::DecorationElement;
pub use color::Color;
pub use colormap::ColorMap;
pub use colormap::LUT_LEN;
pub use config::BarAlign;
pub use config::ColorBarOptions;
pub use config::Config;
pub use config::DataSelectionsConfig;
pub use config::PickedDataRef;
pub use config::PickedPointRef;
pub use config::PickedPointsConfig;
pub use data::Column;
pub use data::ColumnId;
pub use data::DataCell;
pub use data_config::DataBarBinStyleConfig;
pub use data_config::DataBarStyleOverride;
pub use data_config::DataErrorBarPointStyleConfig;
pub use data_config::DataErrorBarPointStyleOverride;
pub use data_config::DataErrorBarStyleConfig;
pub use data_config::DataLineStyleConfig;
pub use data_config::DataRenderType;
pub use data_config::DataScatterPointStyleConfig;
pub use data_config::DataScatterPointStyleOverride;
pub use data_config::DataScatterStyleConfig;
pub use data_config::ErrorRef;
pub use data_config::MAX_CONTOUR_LEVELS;
pub use data_config::ScatterShape;
pub use data_config::SeriesConfig;
pub use drag::Draggable;
pub use preset::AxisPreset;
pub use preset::ColorCycle;
pub use resize::Resizable;
pub use resize::ResizeHandle;
pub use select::AxisElement;
pub use select::AxisLabelElement;
pub use select::AxisTitleElement;
pub use select::ChartTitleElement;
pub use select::ColorBarAxisElement;
pub use select::ColorBarElement;
pub use select::ColorBarLabelElement;
pub use select::ColorBarTitleElement;
pub use select::DataAreaElement;
pub use select::HitId;
pub use select::HitMap;
pub use select::LegendElement;
pub use select::Selectable;
pub use select::SelectionBox;
pub use text::MeasureText;
pub use text::TextExtents;
pub use radial::RadialChart;
pub use radial::RadialInteraction;
pub use radial::RadialKind;
pub use radial::RadialLabelFormat;
pub use radial::RadialLabels;
pub use radial::RadialMaterial;
pub use radial::RadialOutline;
pub use radial::RadialSlice;
pub use radial::RadialSplit;
pub use radial::RadialStyle;
pub use radial::RadialTarget;
pub use categorical::*;
pub use boxplot::*;

Modules§

boxplot
Small, precomputed box plots. Statistical policy belongs to the host.
categorical
Bounded categorical bars. Values are model-owned, not ColumnSource payloads. Stable category/series IDs identify edits and selection; values follow category order.
color
colormap
Continuous colour ramps — the single source for every z→colour mapping.
config
data
Data containers — role-agnostic column storage definitions.
data_config
Declarative series configuration types.
decoration
Editable decoration positions for bounded charts. The same HitMap, Selectable, Draggable and SelectionBox policy as Cartesian charts applies.
default
Reasonable default builders for a figgy chart.
drag
Drag policy — Draggable, position adjustment for selected elements.
format
layout
legend
Legend model — the whole legend is one rich inline document (Legend::content).
line
preset
Selectable style presets — axis frame styles and series color cycles.
radial
Small categorical charts. Values and appearance are independent of Cartesian axes and column streams. The renderer consumes a complete validated snapshot.
resize
Resize policy — Resizable, PPT-style 8-handle resizing for selected elements.
select
Selection policy — Selectable and the chart elements that implement it.
text
tick