Skip to content

Commit f9cc14c

Browse files
committed
snapshot: force *visibility: visible* for text elements ...
with *visibility: inherit* on SVG export
1 parent 33b8907 commit f9cc14c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/snapshot/tosvg.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,19 @@ module.exports = function toSVG(gd, format) {
7171
svg.selectAll('text')
7272
.attr('data-unformatted', null)
7373
.each(function() {
74-
// hidden text is pre-formatting mathjax, the browser ignores it but it can still confuse batik
7574
var txt = d3.select(this);
75+
76+
// hidden text is pre-formatting mathjax,
77+
// the browser ignores it but it can still confuse batik
7678
if(txt.style('visibility') === 'hidden') {
7779
txt.remove();
7880
return;
7981
}
82+
else {
83+
// force other visibility value to export as visible
84+
// to not potentially confuse non-browser SVG implementations
85+
txt.style('visibility', 'visible');
86+
}
8087

8188
// Font family styles break things because of quotation marks,
8289
// so we must remove them *after* the SVG DOM has been serialized

test/jasmine/tests/snapshot_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
var Plotly = require('@lib/index');
2+
3+
var d3 = require('d3');
24
var createGraphDiv = require('../assets/create_graph_div');
35
var destroyGraphDiv = require('../assets/destroy_graph_div');
6+
47
var subplotMock = require('../../image/mocks/multiple_subplots.json');
58
var annotationMock = require('../../image/mocks/annotations.json');
69

@@ -181,5 +184,28 @@ describe('Plotly.Snapshot', function() {
181184
expect(svgElements.length).toBe(1);
182185
}).then(done);
183186
});
187+
188+
it('should force *visibility: visible* for text elements with *visibility: inherit*', function(done) {
189+
d3.select(gd).style('visibility', 'inherit');
190+
191+
Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() {
192+
193+
d3.select(gd).selectAll('text').each(function() {
194+
expect(d3.select(this).style('visibility')).toEqual('visible');
195+
});
196+
197+
return Plotly.Snapshot.toSVG(gd);
198+
})
199+
.then(function(svg) {
200+
var svgDOM = parser.parseFromString(svg, 'image/svg+xml'),
201+
textElements = svgDOM.getElementsByTagName('text');
202+
203+
for(var i = 0; i < textElements.length; i++) {
204+
expect(textElements[i].style.visibility).toEqual('visible');
205+
}
206+
207+
done();
208+
});
209+
});
184210
});
185211
});

0 commit comments

Comments
 (0)