Skip to content

fix(pie): apply percentage number formats to pie chart labels - #42913

Closed
Kr1dhay wants to merge 2 commits into
apache:masterfrom
Kr1dhay:fix/pie-percentage-format
Closed

fix(pie): apply percentage number formats to pie chart labels#42913
Kr1dhay wants to merge 2 commits into
apache:masterfrom
Kr1dhay:fix/pie-percentage-format

Conversation

@Kr1dhay

@Kr1dhay Kr1dhay commented Aug 8, 2026

Copy link
Copy Markdown

SUMMARY

Fixes #42834.

On a pie chart, setting Labels → Percentage and then choosing a Number format had no effect on the percentage label. The percent formatter was a hardcoded module constant:

// Pie/transformProps.ts
const percentFormatter = getNumberFormatter(NumberFormats.PERCENT_2_POINT);

number_format only ever reached numberFormatter, so the percent half of every label was pinned to ,.2%.

This implements approach #2 from the issue thread, which the reporter asked for: the number_format control now drives percentage labels when the selected format is a percentage D3 format (,.1%, .0%, …). Any other format — SMART_NUMBER, currency, ,d — keeps the existing two-decimal default.

The type check matters for backwards compatibility: applying a value format such as ,d to a fraction would render 12.34% as 0. Gating on the format type means no existing chart changes output; only a user who deliberately picks a % format sees a difference.

Detection uses .includes('%'), the idiom already used for this purpose in sharedControls.tsx (y_axis_format, x_axis_number_format).

The change covers every percent-bearing surface, since they all share one formatter: the four percent label types (percent, key_percent, key_value_percent, value_percent), the template label type's {percent}, tooltips, and the "Other" bucket rows.

One consequence worth calling out: because a single control drives both halves of the label, picking a % format also formats the value half as a percentage. That is inherent to reusing number_format rather than adding a second control — happy to switch to a dedicated percentage_format control if maintainers prefer that shape.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Automated — superset-frontend/plugins/plugin-chart-echarts/test/Pie/transformProps.test.ts:

cd superset-frontend
npx jest plugins/plugin-chart-echarts/test/Pie/transformProps.test.ts

Four cases added: parseParams honours an injected percent formatter; a % number format reaches the label; a non-% format leaves the percentage at ,.2% (the backwards-compatibility guard); and the template label type picks up the format. The pre-existing should be formatted using the number formatter test already asserts ,d leaves percentages at 55.50% and still passes unchanged.

Manual:

  1. Create a Pie chart with a dimension and a metric.
  2. Set Labels → Label Type to Category and Percentage.
  3. Set Number format to ,.1% → percentages render with one decimal (12.3%).
  4. Set it back to SMART_NUMBER or ,d → percentages return to 12.34%, exactly as before this change.

ADDITIONAL INFORMATION

  • Has associated issue: Pie Charts do not format Percentage values correctly #42834
  • 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

The percent half of a pie chart label was pinned to ',.2%' by a hardcoded
module constant, so choosing a Number format had no effect on it.

Percentage labels now honour the Number format control when the selected
format is a percentage D3 format (',.1%', '.0%', ...). Any other format
(SMART_NUMBER, currency, integer) keeps the previous two-decimal default,
since applying a value format to a fraction would render 0.42 rather than
42%. Existing charts are therefore unaffected.

Fixes apache#42834
@netlify

netlify Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 9e4bb13
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a773ed57f384100074b93a2
😎 Deploy Preview https://deploy-preview-42913--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@Kr1dhay Kr1dhay closed this Aug 8, 2026
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 Charts do not format Percentage values correctly

1 participant