File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -71,12 +71,19 @@ module.exports = function toSVG(gd, format) {
71
71
svg . selectAll ( 'text' )
72
72
. attr ( 'data-unformatted' , null )
73
73
. each ( function ( ) {
74
- // hidden text is pre-formatting mathjax, the browser ignores it but it can still confuse batik
75
74
var txt = d3 . select ( this ) ;
75
+
76
+ // hidden text is pre-formatting mathjax,
77
+ // the browser ignores it but it can still confuse batik
76
78
if ( txt . style ( 'visibility' ) === 'hidden' ) {
77
79
txt . remove ( ) ;
78
80
return ;
79
81
}
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
+ }
80
87
81
88
// Font family styles break things because of quotation marks,
82
89
// so we must remove them *after* the SVG DOM has been serialized
Original file line number Diff line number Diff line change 1
1
var Plotly = require ( '@lib/index' ) ;
2
+
3
+ var d3 = require ( 'd3' ) ;
2
4
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
3
5
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
6
+
4
7
var subplotMock = require ( '../../image/mocks/multiple_subplots.json' ) ;
5
8
var annotationMock = require ( '../../image/mocks/annotations.json' ) ;
6
9
@@ -181,5 +184,28 @@ describe('Plotly.Snapshot', function() {
181
184
expect ( svgElements . length ) . toBe ( 1 ) ;
182
185
} ) . then ( done ) ;
183
186
} ) ;
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
+ } ) ;
184
210
} ) ;
185
211
} ) ;
You can’t perform that action at this time.
0 commit comments