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

Try out visibility:inherit default for text #990

Merged
merged 2 commits into from
Oct 12, 2016
Merged
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
2 changes: 1 addition & 1 deletion src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ exports.convertToTspans = function(_context, _callback) {
}
_context.text('')
.style({
visibility: 'visible',
visibility: 'inherit',
Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitively the first step to take. 👍

My only concern here is possible incompatibilities in Illustrator and svg conversion tools (e.g. Batik).

To avoid any rolling 🎲 , I'm thinking about adding a few lines to the toSVG routine making sure all exported images get visibility: 'visible' as opposed to inherit while interactive graphs would get 'inherit'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know about. That's the sort of obscure possibility for interaction that I thought maybe could exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to pull this fix wherever you need or redo it elsewhere. I won't worry further about it.

'white-space': 'pre'
});

Expand Down
9 changes: 8 additions & 1 deletion src/snapshot/tosvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ module.exports = function toSVG(gd, format) {
svg.selectAll('text')
.attr('data-unformatted', null)
.each(function() {
// hidden text is pre-formatting mathjax, the browser ignores it but it can still confuse batik
var txt = d3.select(this);

// hidden text is pre-formatting mathjax,
// the browser ignores it but it can still confuse batik
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to make sense 👍

if(txt.style('visibility') === 'hidden') {
txt.remove();
return;
}
else {
// force other visibility value to export as visible
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also makes sense. Presumably it overwrites visibility: inherit (or anything that's not hidden, for that matter), with visible. Which seems correct.

// to not potentially confuse non-browser SVG implementations
txt.style('visibility', 'visible');
}

// Font family styles break things because of quotation marks,
// so we must remove them *after* the SVG DOM has been serialized
Expand Down
26 changes: 26 additions & 0 deletions test/jasmine/tests/snapshot_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var Plotly = require('@lib/index');

var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

var subplotMock = require('../../image/mocks/multiple_subplots.json');
var annotationMock = require('../../image/mocks/annotations.json');

Expand Down Expand Up @@ -181,5 +184,28 @@ describe('Plotly.Snapshot', function() {
expect(svgElements.length).toBe(1);
}).then(done);
});

it('should force *visibility: visible* for text elements with *visibility: inherit*', function(done) {
d3.select(gd).style('visibility', 'inherit');

Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() {

d3.select(gd).selectAll('text').each(function() {
expect(d3.select(this).style('visibility')).toEqual('visible');
});

return Plotly.Snapshot.toSVG(gd);
})
.then(function(svg) {
var svgDOM = parser.parseFromString(svg, 'image/svg+xml'),
textElements = svgDOM.getElementsByTagName('text');

for(var i = 0; i < textElements.length; i++) {
expect(textElements[i].style.visibility).toEqual('visible');
Copy link
Contributor Author

@rreusser rreusser Oct 12, 2016

Choose a reason for hiding this comment

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

Good check. 👍

}

done();
});
});
});
});