File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11var Plotly = require ( '@lib/index' ) ;
2+
3+ var d3 = require ( 'd3' ) ;
24var createGraphDiv = require ( '../assets/create_graph_div' ) ;
35var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
6+
47var subplotMock = require ( '../../image/mocks/multiple_subplots.json' ) ;
58var 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} ) ;
You can’t perform that action at this time.
0 commit comments