Fix pie/donut chart label overlap with post-processing#1767
Conversation
Add _fix_arc_labels post-processing step that repositions text labels outside the pie using theta encoding with a radius offset. For charts with >8 categories, labels are dropped in favor of legend + tooltip.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1767 +/- ##
==========================================
+ Coverage 68.18% 68.31% +0.13%
==========================================
Files 170 170
Lines 28535 28651 +116
==========================================
+ Hits 19456 19574 +118
+ Misses 9079 9077 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
philippjfr
left a comment
There was a problem hiding this comment.
I'm not necessarily against this but my general feeling is that this starts us down an path of maintaining an endless list of post-processing optimizations for vega charts. I know we already do something like this for geographic plots so I get why you went down this path. I'll let @ahuang11 chime in with his opinion.
|
Thanks, Philip!! That's a fair concern. I went with post-processing because Vega-Lite has no collision avoidance for text on arc marks, so prompt-only fixes are unreliable for small slices. I tried several prompt-only approaches first, but they kept failing depending on data distribution. The post-processing is intentionally narrow - it only fires when an arc layer exists and only touches the text layer. Happy to hear what he thinks and adjust if needed. |
|
Few thoughts: I'm okay with plot patches in the code. However, here, I think a minor prompt or example might be sufficient? Alternatively, I think the better solution is ingesting vega lite docs as embeddings (right now I think we ingested examples, but not plot pages) https://vega.github.io/vega-lite/docs/arc.html
Also, it might make sense to implement code patches as a separate class mixin(?) and a method that detects these patches, rather than having patching logic directly in the VegaLiteAgent. |
|
Thanks Andrew! Good points. Here's what I'm thinking:
Will start with prompt-only testing and update here. |

Description
Pie chart labels overlap on small slices because Vega-Lite doesn't do collision avoidance on arc text marks. No matter what the LLM generates, adjacent small slices will have labels piled on top of each other.
I added a
_fix_arc_labelspost-processing step that repositions labels outside the pie using theta encoding with a radius offset. For charts with many categories (>8), labels are dropped entirely in favor of the legend + tooltip.MRVE
Upload any CSV with a category column, ask "plot as pie chart".
Before
After
How Has This Been Tested?
test_agents.pyAI Disclosure
I identified the issue while testing pie charts, designed the approach (post-processing hook after
validate_spec), and verified through tests + manual testing. AI helped scaffold the implementation.Checklist