Spec-driven Vega-Lite renderer: Vega-Lite JSON in, backend-neutral scenegraph and SVG out.
let svg = @moon_vegalite.render_svg(spec_json) // SVG document
let c = @moon_vegalite.compile(spec_json) // scenegraph + view metadata
let scene = @moon_vegalite.scene_json(c) // the scenegraph as JSONmoon build --target native cmd/vl2svg
vl2svg spec.vl.json chart.svg # SVG file (stdout without the second argument)
vl2svg --scene spec.vl.json # scenegraph JSON, with the bounds of every item| Area | Supported |
|---|---|
| Marks | bar, line, point, circle, square, area, rule, tick, rect, text |
| Channels | x, y, x2, y2, color (nominal/ordinal fields with the category scheme, quantitative fields with a blues ramp and gradient legend, constant values), size, opacity, shape, text (size, opacity and shape on point, circle, square; quantitative fields give continuous scales, shape is nominal) |
| Field types | quantitative, ordinal, nominal, temporal |
| Aggregates | count, sum, mean, average, min, max, median, distinct, … (vega aggregate ops) |
| Transforms | filter (expression or predicate), calculate (expression subset), aggregate, bin, timeUnit, fold; field bin, timeUnit, aggregate |
| Time units | year, quarter, month, week, date, day, hours, minutes, seconds, milliseconds and combinations (UTC; "local" time is UTC) |
| Scales | linear, log, sqrt, pow, time, utc, band, point, ordinal (domain, range, zero, nice, reverse, clamp, base, exponent) |
| Stacking | default stacking for bar and area; stack: zero / center / normalize / null |
| Sorting | sort on discrete x / y: ascending, descending, a value list, -x / -y, {op, field, order} |
| Guides | axes (grid, ticks, labels with flush / overlap removal, title), symbol legends, chart title |
| Layout | single view, autosize: pad, width / height as numbers or {step} |
| Config | accepted keys are recorded; a subset (view, scale.zero, …) is honoured |
| Layer | Reference | Where |
|---|---|---|
| number formatting, ticks, nice, time formats, scales | d3 / vega-format / vega-scale as bundled in vega 5.33.1 | fixtures/{numfmt,ticks,formatcases,timecases,scalecases} |
| expressions, data transforms | vega-expression, vega-transforms | fixtures/{exprcases,transformcases} |
| scenegraph bounds, SVG | vega-scenegraph | fixtures/scenecases |
| end to end: 60 official Vega-Lite examples, edge cases, MoonFrame specs | vega-lite 5.23.0 compile + vega scenegraph and SVG | fixtures/vlexamples |
cd scripts
npm ci
npm run fixtures # downloads the example specs of the vega-lite tag, regenerates ../fixtures
npm run gallery # regenerates ../gallery (needs: moon build --target native cmd/vl2svg)| Package | Content |
|---|---|
| util, stats, format, time, value | JavaScript-compatible numbers (V8 libm), d3 ticks, d3-format, time intervals / formats, dynamic values |
| scale | continuous, band, point, ordinal and sequential scales, colour schemes |
| expr, transform | the expression subset, aggregate / bin / stack / timeunit / fold / filter / formula |
| scene, svg | scenegraph, mark bounds, path generation, SVG renderer |
| spec | strict reader of Vega-Lite JSON (unsupported features raise errors with paths) |
| vl | the compiler: data pipeline, scales, axes, legends, layout |
| cmd/vl2svg | command line tool (native) |
pub suberror RenderError {
RenderError(String)
}Install
Download zipSpec-driven Vega-Lite renderer: Vega-Lite JSON in, backend-neutral scenegraph and SVG out.