Skip to content

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

Merged
cpsievert merged 1 commit intomainfrom
feat/vegalite-render-chart
Mar 11, 2026
Merged

feat(python): add VegaLiteWriter.render_chart() for Altair output#177
cpsievert merged 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
Copy link
Collaborator

@georgestagg georgestagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

You might want to consider in the future moving some of this to the Rust level, by adding some extra Rust methods to PyVegaLiteWriter in lib.rs. I think that would allow you to avoid a level of indirection introduced by the VegaLiteWriter as _RustVegaLiteWriter import. But this is OK in the meantime!

@cpsievert cpsievert merged commit c3036f4 into main Mar 11, 2026
30 checks passed
@cpsievert cpsievert deleted the feat/vegalite-render-chart branch March 11, 2026 14:39
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.

2 participants