mosaic-spec

Declarative specification of Mosaic-powered applications as JSON or YAML files. This package provides a parser and code generation framework for reading specifications in a JSON format and generating live Mosaic visualizations and dashboards using the vgplot API.
Usage
To parse a specification and generate round-trip JSON output (.toJSON()), JavaScript module code (astToESM), or a live web application (astToDOM):
import { parseSpec, astToDOM, astToESM } from '@uwdata/mosaic-spec';
const spec = {
plot: [
{
mark: 'lineY',
data: { from: 'table' },
x: 'date',
y: 'value'
}
],
width: 640,
height: 200
};
const ast = parseSpec(spec);
const json = ast.toJSON();
const code = astToESM(ast);
const {
element,
params
} = await astToDOM(ast);
document.body.appendChild(element);
To parse specifications in YAML format, import the yaml library and use it to parse input specification files:
import { parseSpec } from '@uwdata/mosaic-spec';
import { parse } from 'yaml';
const yaml = ;
const spec = parse(yaml);
const ast = parseSpec(spec);
Visual Tests
Visual tests use Playwright to render each JSON spec and compare screenshots against stored snapshots. Snapshots must be generated inside a Docker container that matches CI so they are pixel-identical across machines.
Run tests (compare against existing snapshots):
bin/visual-test.sh
Update snapshots:
bin/visual-test.sh --update
The script uses Docker by default. On macOS you can use the lightweight Container runtime instead:
brew install --cask container
container system start
CONTAINER_RUNTIME=container bin/visual-test.sh --update
container system stop
Alternatively, you can download updated snapshots from the playwright-test-results artifact uploaded by the browser CI job.