Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8146_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove stale leader lines and label offsets of pie slices when the labels move back inside after a resize [[#8146](https://github.com/plotly/plotly.js/pull/8146)]
10 changes: 8 additions & 2 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ function plot(gd, cdModule) {
var hasOutsideText = false;

slices.each(function (pt, i) {
// Clear the outside-label state of the previous draw.
// Otherwise a label that moved back inside keeps its old leader line and offset.
pt.yLabelMin = undefined;
pt.yLabelMid = undefined;
pt.yLabelMax = undefined;
pt.labelExtraX = 0;
pt.labelExtraY = 0;

if (pt.hidden) {
d3.select(this).selectAll('path,g').remove();
return;
Expand Down Expand Up @@ -219,8 +227,6 @@ function plot(gd, cdModule) {
pt.yLabelMin = targetY - textBB.height / 2;
pt.yLabelMid = targetY;
pt.yLabelMax = targetY + textBB.height / 2;
pt.labelExtraX = 0;
pt.labelExtraY = 0;
hasOutsideText = true;
}

Expand Down
37 changes: 37 additions & 0 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,43 @@ describe('pie relayout', function() {
})
.then(done, done.fail);
});

it('removes leader lines and label offsets that a larger size no longer needs', (done) => {
const labels = [];
const values = [];
for (let i = 0; i < 8; i++) {
labels.push(`Label ${i}`);
values.push(i < 4 ? 20 : 3);
}
const data = [{ type: 'pie', labels, values, textposition: 'auto', textinfo: 'label' }];
const largeLayout = { width: 1000, height: 1000, showlegend: false };
const countTextLines = () => d3SelectAll('.pielayer path.textline').size();
const getTextTransforms = () => {
const transforms = [];
d3SelectAll(SLICES_TEXT_SELECTOR).each(function () {
transforms.push(this.getAttribute('transform'));
});
return transforms;
};
let textLinesAfterRelayout;
let transformsAfterRelayout;

Plotly.newPlot(gd, data, { width: 300, height: 300, showlegend: false })
.then(() => {
expect(countTextLines()).toBeGreaterThan(0, 'leader lines at the small size');
return Plotly.relayout(gd, { width: largeLayout.width, height: largeLayout.height });
})
.then(() => {
textLinesAfterRelayout = countTextLines();
transformsAfterRelayout = getTextTransforms();
return Plotly.newPlot(gd, data, largeLayout);
})
.then(() => {
expect(textLinesAfterRelayout).toBe(countTextLines(), 'leader lines after relayout');
expect(transformsAfterRelayout).toEqual(getTextTransforms());
})
.then(done, done.fail);
});
});

describe('Test pie interactions edge cases:', function() {
Expand Down
Loading