Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide text on empty slices to avoid PDF exports in MS Word from SVG imports #6335

Merged
merged 5 commits into from Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6335_fix.md
@@ -0,0 +1 @@
- Hide pie text on empty slices to avoid PDF exports in MS Word from SVG imports [[#6335](https://github.com/plotly/plotly.js/pull/6335)]
16 changes: 12 additions & 4 deletions src/traces/pie/plot.js
Expand Up @@ -239,10 +239,18 @@ function plot(gd, cdModule) {
transform = positionTitleOutside(cd0, gs);
}

titleText.attr('transform',
strTranslate(transform.x, transform.y) +
strScale(Math.min(1, transform.scale)) +
strTranslate(transform.tx, transform.ty));
var scale = Math.min(1, transform.scale);

if(scale) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we could reproduce this ourselves, but some of the data we have from the Word tests suggests that there's some minimum scale that won't break things. There's certainly some size that succeeds but is already useless for practical purposes so could be deleted, somewhere between 0.1 and 0.01? Ideally we'd make this configurable but maybe we can hardcode something in that range to start?

titleText.attr('transform',
strTranslate(transform.x, transform.y) +
strScale(scale) +
strTranslate(transform.tx, transform.ty));

titleText.style('display', null);
} else {
titleText.style('display', 'none');
Copy link
Contributor

Choose a reason for hiding this comment

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

OIC, you prevent even setting the transform attribute when we're going to hide the text. That seems reasonable. After a little investigation it seems we DON'T delete empty slice paths, so what we're seeing from Word must be an extra automatic optimization it does to remove elements with no visible impact. I wish it extended that optimization to scaled-down text 😜

What happens if we later edit this pie, giving this slice nonzero size? Do we reuse the element - and if so do we need to clear the display: none in the if(scale) block?

}
});

// now make sure no labels overlap (at least within one pie)
Expand Down