Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ff12429
feat(vega): theme Vega charts from the charts package
AKnassa Jul 26, 2026
3bbd262
Merge upstream/main into ak-977-vega-charts-theming
AKnassa Aug 7, 2026
b846f95
Merge remote-tracking branch 'origin/main' into review-4411-5pm
cixzhang Aug 28, 2026
bf81326
Merge upstream/main into ak-977-vega-charts-theming
AKnassa Sep 26, 2026
74f380c
fix(vega): keep native Vega views across theme changes
AKnassa Sep 26, 2026
73b4e15
fix(vega): align the core peer with the version charts requires
AKnassa Sep 26, 2026
88c1dcf
fix(vega): catch in-place compileOptions edits on Vega-Lite charts
AKnassa Sep 26, 2026
89b933b
fix(vega): declare charts as a peer so the consumer install resolves
AKnassa Sep 26, 2026
0eead76
Merge main into ak-977-vega-charts-theming; theme from the charts pal…
cixzhang Nov 13, 2026
731ad95
fix(vega): a caller's generic axis key outranks the theme's per-axis …
cixzhang Nov 13, 2026
8410123
fix(vega): a caller's or spec's axis key in any earlier axis block ou…
cixzhang Nov 13, 2026
296afab
fix(vega): an orient block counts only for an orient the chart draws
cixzhang Nov 13, 2026
3f53ef0
fix(vega): a key in one orient block keeps the other orients themed; …
cixzhang Nov 13, 2026
1eee702
fix(vega): a caller's axisX or axisY key keeps every axis of that cha…
cixzhang Nov 13, 2026
9237958
Merge main into ak-977-vega-charts-theming
cixzhang Nov 23, 2026
a1c0214
chore(vega): pin @astryxdesign/core to the workspace version
cixzhang Nov 23, 2026
d09431f
Merge main into ak-977-vega-charts-theming
cixzhang Dec 3, 2026
840c760
Merge main into ak-977-vega-charts-theming
cixzhang Dec 3, 2026
9fecbb4
test(ci): a Charts change now also typechecks vega, which peers on ch…
cixzhang Dec 3, 2026
eeeaab2
fix(vega): count the axes Vega-Lite places itself when moving theme a…
cixzhang Dec 3, 2026
19b5619
fix(vega): the caller's mark and per-mark band padding keys, and inhe…
cixzhang Dec 3, 2026
e3d7c92
docs(VegaChart): record named-style precedence as a known FR1 gap
cixzhang Dec 3, 2026
cdc97a6
fix(vega): a filled point keeps its color under the theme; docs name …
cixzhang Dec 3, 2026
680530d
fix(vega): dots a line, area or trail config or a shape encoding turn…
cixzhang Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/scripts/typecheck-scope.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ describe('the typecheck scope', () => {
it('narrows a Charts change to Charts and the packages that use it', () => {
const choice = scope(['packages/charts/src/Bar/Bar.tsx']);
expect(choice.mode).toBe('some');
expect(short(choice.packages)).toEqual(['charts', 'cli', 'storybook']);
expect(short(choice.packages)).toEqual([
'charts',
'cli',
'storybook',
'vega',
]);
});

it('keeps a Core change wide: everything that builds from Core', () => {
Expand Down
120 changes: 120 additions & 0 deletions docs/specs/components/VegaChart/VegaChart.spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
schema_version: 3
template_version: 7
kind: component
id: component:VegaChart
authority: current
archive_reason: null
superseded_by: null
approved_by: cixzhang
approved_at: 2026-11-12
owners: [cixzhang]
review_triggers: [behavior, theming, public-api]
verified_by:
[
packages/vega/src/VegaChart.test.tsx,
packages/vega/src/vegaLiteConfig.test.ts,
]
modules: []
families: []
design_specs: []
architecture: []
contributing: []
system_specs: []
---

# VegaChart component contract

## Contract at a glance

| Area | Contract |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Public contract | The props in Public concepts, as built. |
| Behavior | A Vega-Lite spec compiles with the Astryx theme config as its base, the caller's `compileOptions.config` on top, and the spec's own inline config last. A native Vega spec is not themed. |
| End-user impact | A chart matches the active theme's axes, legends, marks and categorical palette without extra setup. |
| Builder impact | A builder overrides any theme key through `compileOptions.config` or the spec's own `config`; a native Vega spec takes its config through `parseConfig`. |
| Compatibility/readiness | Canary-only package. |
| Review checks | Reject a Vega-Lite spec that renders without the theme config, a caller config that the theme overrides, or a native Vega spec that the theme changes. |
| Governing rules | None recorded. |

This table is a review projection; the body below is authoritative.

## Intent

VegaChart renders a Vega or Vega-Lite specification inside a container that
follows the active Astryx theme. This record states how the theme config
reaches a chart. Consumer usage lives in `VegaChart.doc.mjs` and the package
README.

## Compatibility and migration

- Released default preserved: `no` for a Vega-Lite spec, which compiles with the theme config as its base (FR1).
- Compatibility class: behavioral, canary-only.
- Controlled/uncontrolled behavior: not applicable.
- Migration decision: none. A builder who wants a key without the theme sets it in `compileOptions.config` or in the spec.

## Ownership boundary

**Owns**

- The order in which the theme config, the caller's compile config and the spec's own config apply (FR1).

**Does not own / non-goals**

- The categorical palette, which comes from `@astryxdesign/charts`.
- The Vega and Vega-Lite runtimes and their own config semantics.

## Public concepts

| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
| ---------------- | ----------------------------------------- | --------------------------------------------------------------------------- | ----------------------------------------- | ------- | --------------------- | ------------ | ------------------------------- |
| `spec` | A Vega or Vega-Lite spec with a `$schema` | The chart to render; `$schema` selects Vega or Vega-Lite | Always | None | `component:VegaChart` | experimental | `onError` with the schema error |
| `data` | Named dataset values | Initial values for named datasets, read once when the View is built | Always | None | `component:VegaChart` | experimental | Not applicable |
| `compileOptions` | Vega-Lite `compile()` options | Options for Vega-Lite compilation; its `config` applies over the theme | Vega-Lite specs only | None | `component:VegaChart` | experimental | Ignored for a native Vega spec |
| `parseConfig` | A Vega config | Config passed to `vega.parse()` | Always | None | `component:VegaChart` | experimental | Not applicable |
| `parseOptions` | Vega parse options | Options passed to `vega.parse()` | Always | None | `component:VegaChart` | experimental | Not applicable |
| `viewOptions` | Vega View options without `container` | Options passed to the Vega View; the component sets `container` | Always | None | `component:VegaChart` | experimental | `container` is overridden |
| `onReady` | Callback with the live View | Called once the chart has rendered | Always | None | `component:VegaChart` | experimental | Not applicable |
| `onError` | Callback with an error | Called when the schema is invalid, compilation fails, or the runtime throws | Always | None | `component:VegaChart` | experimental | Not applicable |
| `ref` | A ref to the root `div` | Ref forwarded to the root container | Always | None | `component:VegaChart` | experimental | Not applicable |

## Behavioral and layout contract

| ID | Invariant | Basis |
| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| FR1 | A Vega-Lite spec MUST compile with the Astryx theme config as its base, the caller's `compileOptions.config` on top, and the spec's own inline config last. A native Vega spec MUST pass through untouched. | The package README's themed-by-default promise |

## Accessibility contract

None recorded.

## Design relationships

| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
| ---------------- | ------------------ | ------------------------ | -------------- | ------------------ |
| Chart | None recorded | Not applicable | primary | FR1 |

The component implements design requirements without copying their rationale.

## Family and system relationships

None recorded.

## Verification map

| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
| -------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------- |
| FR1 | `VegaChart.test.tsx` theming cases; `vegaLiteConfig.test.ts` merge and range cases | Vega-Lite with no config, with a caller config, with an inline config; native Vega | A themeless Vega-Lite chart, a caller config the theme overrides, or a themed native Vega spec fails it | None |

## Decision log

None.

## Open questions

None.

## Content boundary

This file does not duplicate consumer prop tables/examples, current audit
results, implementation steps, or family/system rules. It links to their owners.
80 changes: 64 additions & 16 deletions packages/vega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,34 @@ Renders [Vega](https://vega.github.io/vega/) and [Vega-Lite](https://vega.github

## File Manifest

| File | Role | Purpose |
| ------------------- | --------- | ------------------------------------------------------------ |
| `package.json` | Config | Package metadata, deps, build scripts |
| `tsconfig.json` | Config | TypeScript compiler config (extends root) |
| `tsup.config.ts` | Config | Build config: CJS + ESM + `.d.ts` outputs |
| `src/index.ts` | Barrel | Public API surface |
| `src/VegaChart.tsx` | Component | Inspects `$schema`, compiles or renders, owns View lifecycle |
| `src/viewInputs.ts` | Utility | Detects value changes in the props that own the View |
| `src/schema.ts` | Utility | Parses and validates Vega/Vega-Lite `$schema` URLs |
| `src/types.ts` | Types | Shared TypeScript types for this package |
| File | Role | Purpose |
| ----------------------- | --------- | ------------------------------------------------------------ |
| `package.json` | Config | Package metadata, deps, build scripts |
| `tsconfig.json` | Config | TypeScript compiler config (extends root) |
| `tsconfig.build.json` | Config | Declaration-emit config; excludes tests from `dist` |
| `tsup.config.ts` | Config | Build config: CJS + ESM + `.d.ts` outputs |
| `src/index.ts` | Barrel | Public API surface |
| `src/VegaChart.tsx` | Component | Inspects `$schema`, compiles or renders, owns View lifecycle |
| `src/viewInputs.ts` | Utility | Detects value changes in the props that own the View |
| `src/schema.ts` | Utility | Parses and validates Vega/Vega-Lite `$schema` URLs |
| `src/vegaLiteConfig.ts` | Utility | Astryx-themed Vega-Lite config + compile-option merge |
| `src/types.ts` | Types | Shared TypeScript types for this package |

## Installation

Vega is published **only** under the `@canary` dist-tag, so you must request that tag explicitly. There is no `latest` version to install yet.

```bash
npm install @astryxdesign/vega@canary vega vega-lite
npm install @astryxdesign/vega@canary @astryxdesign/charts@canary @astryxdesign/core@canary vega vega-lite
```

`@astryxdesign/charts` and `@astryxdesign/core` are peer dependencies, so your
app shares one copy of each: charts owns the shared data-visualization palette
that keeps Vega charts and the compositional charts looking identical, and the
wrapper reads the active `<Theme>` from core to resolve tokens to concrete
values. A canary pins both peers to its own build, so install them from the
same `@canary` tag.

> Canary builds follow `main`'s tip, published at most once an hour and on demand (`0.x.y-canary.g<sha>`). They can break between any two versions — pin an exact version if you need stability.

## Usage
Expand Down Expand Up @@ -122,11 +131,11 @@ import {VegaChart} from '@astryxdesign/vega';

`compileOptions` fields (Vega-Lite specs only, ignored otherwise):

| `compileOptions` field | Type | Description |
| ---------------------- | ------------------------------ | --------------------------------------------------- |
| `config` | `VegaLiteConfig` | Vega-Lite config merged on top of the spec's config |
| `logger` | `LoggerInterface` | Custom logger used during compilation |
| `fieldTitle` | `(fieldDef, config) => string` | Custom field title formatter |
| `compileOptions` field | Type | Description |
| ---------------------- | ------------------------------ | --------------------------------------------------------- |
| `config` | `VegaLiteConfig` | Vega-Lite config merged on top of the Astryx theme config |
| `logger` | `LoggerInterface` | Custom logger used during compilation |
| `fieldTitle` | `(fieldDef, config) => string` | Custom field title formatter |

`parseOptions` fields:

Expand Down Expand Up @@ -173,6 +182,11 @@ What that costs differs between the two:
Everything the copy did reach is compared by value either way, so a mutation
elsewhere in the spec is picked up even when part of it is opaque.

A theme or color-mode change rebuilds a **Vega-Lite** View, dropping its zoom,
hover, and signal state, because the [theme config](#theming) is compiled into
the spec. It never rebuilds a **native Vega** View, which does not use that
config.

Everything else is inert to the lifecycle: `data`, `className`, `style`,
`onReady`, and `onError` never rebuild the View.

Expand All @@ -199,6 +213,40 @@ To update data dynamically after render, use `onReady` to get the live View and
/>
```

### Theming

Vega-Lite specs are themed out of the box. `VegaChart` reads the active
`<Theme>` and compiles the spec with the Astryx config from
`buildVegaLiteConfig` as its base — axis, legend, line/point, title and view
chrome, plus the scale ranges. The categorical range comes from the
`@astryxdesign/charts` palette, so a series colored blue in a `<Chart>` is the
same blue here.

Precedence, weakest first:

1. The derived Astryx theme config
2. `compileOptions.config` you pass to `<VegaChart>`
3. The spec's own inline `config`
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

Merging is recursive, so a partial override like
`compileOptions={{config: {axis: {grid: true}}}}` replaces only `axis.grid` and
leaves the rest of the themed `axis` block intact.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

Native Vega specs are **not** themed — they bypass Vega-Lite compilation
entirely. Pass `parseConfig` for those.

To build the config yourself (custom compile pipeline, SSR, a `vega-embed`
host):

```tsx
import {useTheme} from '@astryxdesign/core/theme';
import {buildVegaLiteConfig} from '@astryxdesign/vega';

const {token} = useTheme();

buildVegaLiteConfig(token); // the themed VegaLiteConfig
```

### Untrusted specs

A Vega/Vega-Lite spec is a program, not just data: Vega evaluates the
Expand Down
4 changes: 3 additions & 1 deletion packages/vega/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@
"README.md"
],
"scripts": {
"build": "tsup && tsc --project tsconfig.json --emitDeclarationOnly --declaration --noEmit false --outDir dist",
"build": "tsup && tsc --project tsconfig.build.json --emitDeclarationOnly --declaration --noEmit false --outDir dist",
"dev": "tsup --watch",
"test": "vitest run --root ../..",
"test:watch": "vitest --root ../..",
"typecheck:docs": "tsc --project tsconfig.docs.json",
"typecheck": "tsc --noEmit && pnpm typecheck:docs"
},
"peerDependencies": {
"@astryxdesign/charts": "0.1.9",
"@astryxdesign/core": "0.7.18",
"react": ">=19.2.0",
"react-dom": ">=19.2.0",
"vega": ">=6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/vega/src/VegaChart.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const docs = {
name: 'compileOptions',
type: 'CompileOptions',
description:
'Options passed to Vega-Lite compilation. Ignored for native Vega specs.',
'Options passed to Vega-Lite compilation. Its config is merged over the Astryx theme config applied by default. Ignored for native Vega specs.',
},
{
name: 'parseConfig',
Expand Down
Loading