Skip to content

feat(python): add VegaLiteWriter.render_chart() for Altair output#177

Open
cpsievert wants to merge 1 commit intomainfrom
feat/vegalite-render-chart
Open

feat(python): add VegaLiteWriter.render_chart() for Altair output#177
cpsievert wants to merge 1 commit intomainfrom
feat/vegalite-render-chart

Conversation

@cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Mar 9, 2026

Summary

The two-stage API (documented in the README) separates reading from writing, giving users control over each step. However, the writing step currently only produces a raw JSON string — users who want an Altair chart object need to manually dispatch to the right Altair class (Chart, LayerChart, FacetChart, etc.) based on the spec structure.

This PR adds VegaLiteWriter.render_chart() so the two-stage API can produce Altair charts directly, just like render_altair() does for the one-step path:

writer = ggsql.VegaLiteWriter()

# Before: raw JSON only
json_str = writer.render(spec)

# Now: also get an Altair chart object
chart = writer.render_chart(spec)

Implementation details:

  • Wraps the Rust VegaLiteWriter in a Python class that adds render_chart()
  • Extracts the Altair chart-type dispatch logic from render_altair() into a shared _json_to_altair_chart() helper (deduplication, not new logic)
  • No Rust changes required

Test plan

  • 3 new tests in TestVegaLiteWriterRenderChart (basic, layered, faceted)
  • Full test suite passes

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert requested a review from georgestagg March 9, 2026 21:35
@cpsievert cpsievert changed the title feat(python): add VegaLiteWriter.render_chart() for Altair output feat(python): add VegaLiteWriter.render_chart() for Altair output Mar 9, 2026
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