Skip to content

Conversation

@ObservedObserver
Copy link
Member

Summary

  • allow exporting to svg with export_chart_svg
  • support saving charts as svg
  • document the new API

Testing

  • pytest -q (fails: command not found)

@ObservedObserver ObservedObserver marked this pull request as ready for review June 11, 2025 12:19
@ObservedObserver ObservedObserver merged commit 514c115 into main Jun 11, 2025
8 checks passed
@ObservedObserver ObservedObserver deleted the codex/design-developer-friendly-api-for-pygwalker-image-export branch June 11, 2025 12:19
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: SVG Export Method Returns Incorrect Data Type

The export_chart_svg method is type-hinted to return bytes, but can return non-bytes data. If svg_str (from chart_data.charts[0].data) is neither a string nor bytes, it is returned directly, violating the type contract and causing runtime errors for callers expecting bytes. Additionally, the base64.b64decode call can raise an unhandled binascii.Error if the base64 data is malformed.

pygwalker/api/pygwalker.py#L317-L330

def export_chart_svg(self, chart_name: str) -> bytes:
"""Export the chart as svg bytes."""
chart_data = self._get_chart_by_name(chart_name)
if len(chart_data.charts) == 0:
raise ValueError(f"chart_name: {chart_name} has no svg data")
svg_str = chart_data.charts[0].data
prefix = "data:image/svg+xml;base64,"
if isinstance(svg_str, str) and svg_str.startswith(prefix):
import base64
return base64.b64decode(svg_str[len(prefix):])
if isinstance(svg_str, str):
return svg_str.encode("utf-8")
return svg_str

Fix in Cursor


BugBot free trial expires on June 17, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@ObservedObserver ObservedObserver linked an issue Jun 11, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Query] Any user exposed API to export SVG for Plots?

1 participant