Skip to content

Commit

Permalink
Merge pull request #6335 from plotly/pie-empty-slices
Browse files Browse the repository at this point in the history
Hide text on empty slices to avoid PDF exports in MS Word from SVG imports
  • Loading branch information
archmoj committed Oct 6, 2022
2 parents 3ae9c77 + e8eef1c commit e1d94b7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions draftlogs/6335_fix.md
@@ -0,0 +1 @@
- Hide text on empty slices to avoid PDF exports in MS Word from SVG imports [[#6335](https://github.com/plotly/plotly.js/pull/6335)]
5 changes: 5 additions & 0 deletions src/lib/index.js
Expand Up @@ -1331,6 +1331,11 @@ lib.getTextTransform = function(transform) {
);
};

lib.setTransormAndDisplay = function(s, transform) {
s.attr('transform', lib.getTextTransform(transform));
s.style('display', transform.scale ? null : 'none');
};

lib.ensureUniformFontSize = function(gd, baseFont) {
var out = lib.extendFlat({}, baseFont);
out.size = Math.max(
Expand Down
4 changes: 2 additions & 2 deletions src/traces/bar/plot.js
Expand Up @@ -431,8 +431,8 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, opts, makeOnCom
recordMinTextSize(trace.type === 'histogram' ? 'bar' : trace.type, transform, fullLayout);
calcBar.transform = transform;

transition(textSelection, fullLayout, opts, makeOnCompleteCallback)
.attr('transform', Lib.getTextTransform(transform));
var s = transition(textSelection, fullLayout, opts, makeOnCompleteCallback);
Lib.setTransormAndDisplay(s, transform);
}

function getRotateFromAngle(angle) {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/bar/uniform_text.js
Expand Up @@ -30,7 +30,7 @@ function resizeText(gd, gTrace, traceType) {
transform.scale = (shouldHide && transform.hide) ? 0 : minSize / transform.fontSize;

var el = d3.select(this).select('text');
el.attr('transform', Lib.getTextTransform(transform));
Lib.setTransormAndDisplay(el, transform);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/traces/funnelarea/plot.js
Expand Up @@ -128,7 +128,7 @@ module.exports = function plot(gd, cdModule) {
recordMinTextSize(trace.type, transform, fullLayout);
cd[i].transform = transform;

sliceText.attr('transform', Lib.getTextTransform(transform));
Lib.setTransormAndDisplay(sliceText, transform);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/traces/pie/plot.js
Expand Up @@ -199,7 +199,7 @@ function plot(gd, cdModule) {
recordMinTextSize(trace.type, transform, fullLayout);
cd[i].transform = transform;

sliceText.attr('transform', Lib.getTextTransform(transform));
Lib.setTransormAndDisplay(sliceText, transform);
});
});

Expand Down Expand Up @@ -307,7 +307,7 @@ function plotTextLines(slices, trace) {
pt.transform.targetX += pt.labelExtraX;
pt.transform.targetY += pt.labelExtraY;

sliceText.attr('transform', Lib.getTextTransform(pt.transform));
Lib.setTransormAndDisplay(sliceText, pt.transform);

// then add a line to the new location
var lineStartX = pt.cxFinal + pt.pxmid[0];
Expand Down

0 comments on commit e1d94b7

Please sign in to comment.