Skip to content

feat(echarts): chart_spec.echarts, a native option escape hatch - #134

Closed
windylcx wants to merge 1 commit into
microsoft:mainfrom
windylcx:feat/native-echarts-option
Closed

windylcx wants to merge 1 commit into
microsoft:mainfrom
windylcx:feat/native-echarts-option

Conversation

@windylcx

@windylcx windylcx commented Sep 29, 2026 •

Copy link
Copy Markdown

What

chart_spec.echarts — a native ECharts option patch that is merged onto the compiled option, plus column binding for series added through it.

This closes the gap where a chart needs something the semantic layer does not model. A second value axis, a bar and a line in one chart, markLine / markArea, dataZoom, axis or tooltip formatters, per-series areaStyle, custom grids — today a caller who needs one of those has to leave Flint and hand-write the option, losing the layer they came for.

{
  "chartType": "Line Chart",
  "encodings": { "x": { "field": "month" }, "y": { "field": "revenue" } },
  "echarts": {
    "legend": { "show": true, "top": 6 },
    "yAxis": [{ "name": "Revenue" }, { "name": "Margin", "position": "right" }],
    "series": [
      { "name": "Revenue", "lineStyle": { "width": 2 } },
      { "type": "line", "field": "margin", "name": "Margin rate", "axis": "right" }
    ]
  }
}

Applied last, so it is authoritative over what Flint decided above it: objects merge recursively, arrays of plain objects (series, xAxis, yAxis) merge element-wise by index with entries past the end appended, any other array replaces, and _-prefixed keys are dropped with an info warning. A series entry that binds a column is added (and axis: "right" puts it on a right-hand value axis that Flint creates if missing); one that does not patches the series at its own index. Backend-scoped: the other assemblers ignore the key, as Vega-Lite ignores theme_spec. No template change and no new channel.

Guide: docs/native-echarts-options.md (+ zh-CN); docs/api-reference.md and the CHANGELOG updated. The MCP tool input schema declares the field too, since zod drops unknown keys in chart_spec.

Verified: 18 new flint-chart tests pinning the merge contract, 3 flint-mcp tests rendering a column-bound dual-axis chart end to end, plus a compile_chart passthrough case; typecheck, lint, test, build and site:build all clean.

The semantic layer covers the common cases; ECharts is larger than any
channel set. Until now a chart needing a second value axis, a mixed mark
type, markLine/dataZoom, a formatter, or per-series styling had to leave
Flint and hand-write the option — losing the layer it came for.

chart_spec.echarts patches the compiled option, applied last so it wins
over the layout pass:

- objects merge recursively; arrays of plain objects (series, xAxis,
  yAxis) merge element-wise by index, appending past the end, so
  series[1] is addressable without restating series[0]; other arrays
  replace; an empty array says nothing; "_" keys are dropped with a
  warning.
- series entries may bind columns instead of carrying data: field /
  fields add series read from the chart's rows (categoryField picks the
  pairing column, defaulting to the chart's x field), and axis: "right"
  puts one on a right-hand value axis that Flint creates when missing.
  Bound entries are added, unbound entries patch by index.
- backend-scoped: the other assemblers ignore the key, as Vega-Lite
  ignores theme_spec.

The MCP tool declares it too: chart_spec there is a zod object, which
strips unknown keys, so without the declaration a native patch never
reached the assembler.

Verified: 18 new flint-chart unit tests pinning the merge contract;
3 flint-mcp tests rendering a column-bound dual-axis chart end to end
(SSR → SVG) plus a compile_chart passthrough case; full flint-chart
1671 + flint-mcp 90 tests, typecheck, lint, build and site:build clean;
a real PNG rendered from a spec that binds a second metric to a right
axis. Guide: docs/native-echarts-options.md (+ zh-CN).
@windylcx

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@windylcx windylcx closed this Sep 29, 2026
@windylcx
windylcx deleted the feat/native-echarts-option branch September 29, 2026 10:36
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.

1 participant