Repository navigation
fix(pie): center pies in Cartodiagram when the chart size is unknown - #46478
schizophrenicmaniac wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #46478 +/- ##
=======================================
Coverage 86.42% 86.42%
=======================================
Files 3183 3184 +1
Lines 222605 222630 +25
Branches 52996 53010 +14
=======================================
+ Hits 192377 192402 +25
Misses 26758 26758
Partials 3470 3470
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CC @jansule |
…layed # Conflicts: # superset-frontend/plugins/plugin-chart-echarts/test/Pie/transformProps.test.ts
SBIN2010
left a comment
There was a problem hiding this comment.
The null-size path in getPieLayout looks right: a 100×100 rect and a percentage center is what Cartodiagram needs, since it transforms the pie once with width/height set to null and renders it later at a zoom-dependent size. Sized pies are unchanged.
Two things before this can land:
-
Show Total on a partial donut. When the chart size is unknown, totalAnchor is null and the Total graphic is placed at left: 'center' / top: 'middle', which is the center of the container. pieLayout.center is already the correct percentage origin, and the series uses it. For a top half-donut that is ['50%', '67.5%'], so the label should take left / top from pieLayout.center and sit in the hole (or on the flat edge), not in the middle of the box. A full donut stays at 50% / 50%. The new unsized Total test only covers a 360° donut. Please add the same assertion for an unsized half-donut (startAngle 180, sweptAngle 180) expecting { left: '50%', top: '67.5%' }.
-
Screenshots. This changes the UI, and the test plan calls out Cartodiagram zoom, a donut with Show Total, and a half donut. Please add before/after screenshots.
|
@SBIN2010 Agreed. When the size is unknown, the Total is now anchored on the pie origin in percent. The half donut gets it at 50% / 67.5% and a full donut stays at 50% / 50%. Narrow arcs get the same clamping into the arc's box as the sized path. One difference from what you suggested: a text graphic with |
SUMMARY
Since #42151 the Pie chart works out its center in pixels from the chart's width and height (
getPieLayout). The Cartodiagram builds the pie props once withwidth/heightset tonull, on purpose so resizing on zoom doesn't trigger extra updates, and then renders each pie at a zoom-dependent size. With a null size the layout rect collapsed to 1x1 px, so every pie on the map was drawn around the top-left corner of its box.When no size is available,
getPieLayoutnow lays the arc out in a 100x100 square and returns the center as percentages, which ECharts resolves against the real size when rendering. For a full pie this is the usual['50%', '50%']with unscaled radii, as in 6.1. Partial arcs keep their recentering, which is exact for square charts (the Cartodiagram default). The "Total" label also relied on pixel coordinates. In that case its anchor is returned as percentages too, clamped into the arc's box like in the sized path, so on a half donut it sits on the flat edge (50%/67.5%) rather than in the middle of the box. ECharts places a graphic's top-left corner at percentageleft/top, so the text is wrapped in a zero-size group placed there and centered on it. Charts that pass a size are unchanged.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: see the screenshot in #46477 (pies stuck in the top-left corner of each box). After screenshots still to be added.
TESTING INSTRUCTIONS
Unit tests:
npm run test -- plugins/plugin-chart-echarts/test/Pie/transformProps.test.ts plugins/plugin-chart-cartodiagramADDITIONAL INFORMATION