From 33b890758712c988635a74f9a7686f8f5bd927e5 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Wed, 28 Sep 2016 20:26:52 -0400 Subject: [PATCH 1/2] Try out visibility:inherit default for text --- src/lib/svg_text_utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index 8b8e37257d8..28b152085a8 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -91,7 +91,7 @@ exports.convertToTspans = function(_context, _callback) { } _context.text('') .style({ - visibility: 'visible', + visibility: 'inherit', 'white-space': 'pre' }); From f9cc14c81949472f650ce2ecdfa68a0f7da958fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 12 Oct 2016 10:01:52 -0400 Subject: [PATCH 2/2] snapshot: force *visibility: visible* for text elements ... with *visibility: inherit* on SVG export --- src/snapshot/tosvg.js | 9 ++++++++- test/jasmine/tests/snapshot_test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/snapshot/tosvg.js b/src/snapshot/tosvg.js index 3ef7ee18867..d43e608f59c 100644 --- a/src/snapshot/tosvg.js +++ b/src/snapshot/tosvg.js @@ -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 diff --git a/test/jasmine/tests/snapshot_test.js b/test/jasmine/tests/snapshot_test.js index 42bc1c524e3..d2050628f43 100644 --- a/test/jasmine/tests/snapshot_test.js +++ b/test/jasmine/tests/snapshot_test.js @@ -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'); @@ -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(); + }); + }); }); });