Skip to content

feat: add "auto" mark that infers the mark type from encodings#9853

Open
essandhu wants to merge 4 commits into
vega:mainfrom
essandhu:essandhu/auto-mark
Open

feat: add "auto" mark that infers the mark type from encodings#9853
essandhu wants to merge 4 commits into
vega:mainfrom
essandhu:essandhu/auto-mark

Conversation

@essandhu

@essandhu essandhu commented May 23, 2026

Copy link
Copy Markdown

PR Description

Closes #8749.

Introduces an "auto" mark that, during normalization, resolves to the primitive mark best fitting the encodings and their declared (or inferred) data types. Inspired by Observable Plot's auto mark and CompassQL.

Because Vega-Lite compiles without access to the data, the decision uses only declared/inferred types. Although this is narrower than Plot/CompassQL, it is still predictable and fully documented. The full decision table lives in site/docs/mark/auto.md.

Highlights

  • New "auto" mark, accepted as a string or a mark def with optional prefer: "point" | "line" | "area" | "bar" | "rule" to constrain the family. "area" is opt-in only via prefer
  • 1D positional specs inject bin: true + aggregate: "count" → histogram / count bar
  • Resolves to a primitive mark during normalization; compiled Vega is identical to the equivalent explicit-mark spec, preserving the "generate generic Vega" principle
  • Six example specs (examples/specs/auto_*.vl.json), a new doc page, mark-overview update, and docs TOC entry

Intentional design choices, open for discussion

  • no monotonicity detection from data; line requires a temporal axis or prefer: "line"
  • no default-sum injection
  • no order soft signals; explicit prefer only

Checklist

  • This PR is atomic (i.e., it fixes one issue at a time).
  • The title is a concise semantic commit message (e.g. "fix: correctly handle undefined properties").
  • npm test runs successfully
  • For new features:
    • Has unit tests.
    • Has documentation under site/docs/ + examples.

Tips:

essandhu added 4 commits May 22, 2026 17:42
Introduce an "auto" mark that, during normalization, resolves to the primitive
mark best matching the encodings and their declared/inferred data types.
Inspired by Observable Plot's auto mark and CompassQL, but the decision is made
purely from declared types since Vega-Lite compiles without access to the data.

- Add `prefer` to constrain the mark family (point/line/area/bar/rule); `area`
  is only ever produced when explicitly requested via `prefer`.
- 1D specs (a single positional field) become a histogram/count bar via bin and
  count injection.

Ref vega#8749
Add the auto mark reference page (site/docs/mark/auto.md) with the
decision table, the `prefer` property, and runnable examples; mention
auto in the mark overview; add an Auto entry to the docs TOC between
Area and Bar.

Adds six focused example specs that reuse data and field names from
existing examples (cars.json, stocks.csv, movies.json):

- auto_scatterplot  (Q x Q -> point)
- auto_line         (T x Q -> line)
- auto_histogram    (1D Q  -> bar + injected bin/count)
- auto_bar          (1D N  -> bar + injected count)
- auto_heatmap      (N x O + color measure -> rect)
- auto_prefer_area  (T x Q with prefer="area" -> area)

Compiled output under examples/compiled/ is intentionally left to CI
to regenerate, per CONTRIBUTING.md.

Ref vega#8749
Address a handful of small conventions surfaced by an audit against
CONTRIBUTING.md:

- Add `__Default value:__` line to the `prefer` JSDoc per the docs guide;
  regenerate the schema.
- Add `AutoMark` and `AutoPreferredMark` entries to `site/_data/link.yml`
  so the `prefer` property table renders type links cleanly.
- Rewrite the six example specs descriptions as plain prose
  (the `description` field is used as accessibility text; other examples
  in the repo use plain English).
- Rename the auto.md "How the Mark Is Chosen" anchor from
  `selection` to `decision` to avoid conceptual overlap with the
  Vega-Lite "selection" feature; update the TOC link.
- Add a defensive test that a `mark: "auto"` spec with no encoding
  still normalizes (gradual specification, design principle 3).

Ref vega#8749
Match `src/normalize/pathoverlay.ts` style: no JSDoc on classes,
helper functions, or type aliases in `src/normalize/automark.ts`;
keep only inline comments that explain non-obvious decisions.

Match `src/compositemark/boxplot.ts` for the top-level types file:
drop JSDoc on `AUTO` and `AUTO_PREFERRED_MARKS` constants; keep the
required `__Default value:__` JSDoc on the `AutoMarkDef.prefer`
property.

Match existing test files: remove JSDoc on the `resolvedMark`
helper and compress the gradual-specification block comment to a
single inline line.
@essandhu essandhu marked this pull request as ready for review May 23, 2026 18:57
@essandhu essandhu requested a review from a team as a code owner May 23, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto mark

1 participant