Skip to content

fix(pie): clear stale leader lines when outside labels move back inside - #8146

Open
b84330808 wants to merge 2 commits into
plotly:mainfrom
b84330808:fix-pie-stale-textline
Open

b84330808 wants to merge 2 commits into
plotly:mainfrom
b84330808:fix-pie-stale-textline

Conversation

@b84330808

Copy link
Copy Markdown

Remove the stale leader lines and label offsets that stay on a pie after its labels move back inside.

Fixes #4979 and #5616.

Cause

A redraw without a recalc reuses the calcdata points. A resize through Plotly.relayout or Plotly.react is such a redraw. plot in src/traces/pie/plot.js set labelExtraX, labelExtraY and yLabelMid only for the labels that were outside on the current draw. A label that moved back inside kept the values of the previous draw. scootLabels then treated the label as an outside label, and plotTextLines drew its old leader line. The other outside labels moved to avoid the stale label.

Fix

Reset this state for every slice at the start of each draw. The reset also clears the state of hidden slices, so plotTextLines no longer draws a line for a hidden slice.

Tests

  • New jasmine test in pie_test.js (pie relayout suite). The test draws a pie at 300x300 px, where some labels need leader lines. Then the test calls Plotly.relayout to 1000x1000 px. The test expects the same leader lines and label positions as a new plot at 1000x1000 px. Without the fix, the resized plot has 3 leader lines where the new plot has none, and 3 labels are 2 to 8 px lower.
  • I ran the pie, funnelarea, legend, sunburst, treemap and icicle suites in headless Chrome on Windows. The uniformtext "react with new uniform text options" test fails for pie, funnelarea, sunburst and treemap on this machine with and without the change. All other tests pass.
  • npm run lint and npm run typecheck pass. npm run test-syntax reports the same getComputedStyle count error with and without the change on this Windows checkout.

Screenshots

The same figure (8 slices, textposition: 'auto'), first drawn at 300x300 px and then resized with Plotly.relayout to 700x700 px.

Before:

before

After:

after

The change moves no image baselines that I know of. No mock resizes a pie after the first draw.

draftlogs/0000_fix.md holds a placeholder number. I will rename it to the number of this pull request.

🐦

I used Claude Code to write this change.

b84330808 and others added 2 commits October 26, 2026 12:47
A redraw without a recalc (for example a resize through relayout or react)
reuses the calcdata points. The plot step set labelExtraX, labelExtraY and
yLabelMid only for labels that were outside on the current draw. A label
that moved back inside kept the values of the previous draw. scootLabels
then treated the label as an outside label, and plotTextLines drew its old
leader line and shifted the other labels.

Reset this state for every slice at the start of each draw.

Fixes plotly#4979 and plotly#5616.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KoolADE85

Copy link
Copy Markdown
Contributor

Thanks for the PR! We'll take a closer look and follow up.

@KoolADE85 KoolADE85 self-assigned this Oct 26, 2026
@KoolADE85
KoolADE85 self-requested a review October 26, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.textline remains when window size gets large

2 participants