Skip to content

fix(pie): center pies in Cartodiagram when the chart size is unknown - #46478

Open
schizophrenicmaniac wants to merge 4 commits into
apache:masterfrom
schizophrenicmaniac:fix/46477-pie-chart-are-not-correctly-displayed
Open

schizophrenicmaniac wants to merge 4 commits into
apache:masterfrom
schizophrenicmaniac:fix/46477-pie-chart-are-not-correctly-displayed

Conversation

@schizophrenicmaniac

@schizophrenicmaniac schizophrenicmaniac commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 with width/height set to null, 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, getPieLayout now 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 percentage left/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

  1. Create a Pie chart on a dataset that has a point geometry column, then create a Cartodiagram that uses that dataset and Pie chart (the dataset in Pie chart are not correctly displayed in cartodiagram #46477 works).
  2. Open the Cartodiagram in Explore and on a dashboard, and zoom in and out.
  3. Each pie should be centered on its location at every zoom level. Also try a donut with "Show total" on and a half donut (start angle 180, swept angle 180) with "Show total" on; the total should sit in the hole of the donut and on the flat edge of the half donut.
  4. Check that regular Pie charts outside the Cartodiagram look the same as before.

Unit tests: npm run test -- plugins/plugin-chart-echarts/test/Pie/transformProps.test.ts plugins/plugin-chart-cartodiagram

ADDITIONAL INFORMATION

  • Has associated issue: Fixes Pie chart are not correctly displayed in cartodiagram #46477
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: f38527a758f6

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (7a46732) to head (2905400).

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           
Flag Coverage Δ
javascript 83.41% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas

Copy link
Copy Markdown
Member

CC @jansule

schizophrenicmaniac and others added 2 commits November 28, 2026 09:20
…layed

# Conflicts:
#	superset-frontend/plugins/plugin-chart-echarts/test/Pie/transformProps.test.ts

@SBIN2010 SBIN2010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@schizophrenicmaniac

Copy link
Copy Markdown
Contributor Author

@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 left: '50%' gets placed by its top-left corner, so the label would sit about half its width to the right of the origin. So the text is wrapped in a zero-size group (bounding: 'raw') placed at those percentages, and the text is centered on the group. The new half-donut test checks { left: '50%', top: '67.5%' } on that group and that the text inside is centered.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pie chart are not correctly displayed in cartodiagram

3 participants