Skip to content

Commit

Permalink
Merge pull request #990 from plotly/visibility-inherit
Browse files Browse the repository at this point in the history
Try out visibility:inherit default for text
  • Loading branch information
etpinard authored Oct 12, 2016
2 parents 0109c9b + f9cc14c commit f7a8afa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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',
'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
if(txt.style('visibility') === 'hidden') {
txt.remove();
return;
}
else {
// force other visibility value to export as visible
// 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');
}

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

0 comments on commit f7a8afa

Please sign in to comment.