Skip to main content

Module chart

Module chart 

Source
Expand description

GridCraft charts (layer L3, toolkit-free).

  • resolve pulls series names, categories and values out of a workbook,
  • render lays a chart out into a list of drawing primitives (Prim) that any UI toolkit (or the built-in rasterize) can paint,
  • render_sparkline draws in-cell sparklines,
  • rasterize turns primitives into RGBA pixels for PNG export and tests.

The look (palette, greys, spacing) is GridCraft’s own design.

Re-exports§

pub use crate::model::Chart;
pub use crate::model::ChartKind;
pub use crate::model::LegendPos;
pub use crate::model::SparklineKind;
pub use crate::model::Trendline;
pub use crate::model::TrendlineKind;

Structs§

ApproxMeasure
Fixed-width approximation: 0.55 × size per character (bold 10% wider).
ChartData
Resolved data: series names, categories and values pulled from the workbook.
Scale
A linear axis scale: min..=max with gridlines every step.
SeriesData
TrendlineData
A trendline to draw: the model settings with the line colour resolved against the theme.

Enums§

HAlign
Prim
A drawing primitive in chart coordinates (origin top-left, y down, units = points/pixels).
Swatch
How a legend entry’s swatch is drawn.
VAlign

Traits§

Measure
Measures text width (the UI passes real font metrics; tests use a fixed-width approximation).

Functions§

default_palette
The first n series colours for theme.
format_number
Formats a number with a format code (General shows up to the precision implied by step).
legend_entries
Legend entries (text, colour, swatch) render draws for this chart; empty when hidden.
nice_scale
Picks a “nice” scale (steps of 1, 2 or 5 × 10ⁿ, 4–9 gridlines) covering lo..=hi.
rasterize
Rasterises primitives to straight RGBA8 (w*h*4 bytes) over background. Empty for a zero or oversized image. Text primitives are skipped.
render
Lays out and draws a chart into a w×h box at the origin. Empty for a degenerate box.
render_sparkline
Draws a sparkline into a w×h box at the origin. Gaps (None) break lines; column and win/loss sparklines draw negatives in our “down” red.
resolve
Evaluates a chart’s series formulas: names, values, categories (default “1”, “2”, …), X values (scatter/bubble), bubble sizes, number formats and colours (explicit, else the default palette derived from the workbook theme accents).
series_color
Colour of the i-th series: theme accents 1–6, then tinted variations of them.
series_plot_kind
The kind series i of chart is drawn as: its own kind in a combo chart, else the chart’s.
supports_trendline
Whether series drawn as k show trendlines (Excel offers them on 2-D unstacked column, bar, line, area, scatter and bubble charts).

Type Aliases§

Rgba
Straight (non-premultiplied) RGBA colour.