Skip to content

Commit f7a8afa

Browse files
authored
Merge pull request #990 from plotly/visibility-inherit
Try out visibility:inherit default for text
2 parents 0109c9b + f9cc14c commit f7a8afa

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/lib/svg_text_utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ exports.convertToTspans = function(_context, _callback) {
9191
}
9292
_context.text('')
9393
.style({
94-
visibility: 'visible',
94+
visibility: 'inherit',
9595
'white-space': 'pre'
9696
});
9797

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)