@@ -3,6 +3,7 @@ var Plotly = require('@lib/index');
3
3
var d3 = require ( 'd3' ) ;
4
4
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
5
5
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
6
+ var fail = require ( '../assets/fail_test' ) ;
6
7
7
8
var subplotMock = require ( '../../image/mocks/multiple_subplots.json' ) ;
8
9
var annotationMock = require ( '../../image/mocks/annotations.json' ) ;
@@ -191,16 +192,15 @@ describe('Plotly.Snapshot', function() {
191
192
} ) ;
192
193
193
194
describe ( 'toSVG' , function ( ) {
194
- var parser = new DOMParser ( ) ,
195
- gd ;
195
+ var parser = new DOMParser ( ) ;
196
+ var gd ;
196
197
197
198
beforeEach ( function ( ) {
198
199
gd = createGraphDiv ( ) ;
199
200
} ) ;
200
201
201
202
afterEach ( destroyGraphDiv ) ;
202
203
203
-
204
204
it ( 'should not return any nested svg tags of plots' , function ( done ) {
205
205
Plotly . plot ( gd , subplotMock . data , subplotMock . layout ) . then ( function ( ) {
206
206
return Plotly . Snapshot . toSVG ( gd ) ;
@@ -245,5 +245,53 @@ describe('Plotly.Snapshot', function() {
245
245
done ( ) ;
246
246
} ) ;
247
247
} ) ;
248
+
249
+ it ( 'should handle quoted style properties' , function ( done ) {
250
+ Plotly . plot ( gd , [ {
251
+ y : [ 1 , 2 , 1 ] ,
252
+ marker : {
253
+ gradient : {
254
+ type : 'radial' ,
255
+ color : '#fff'
256
+ } ,
257
+ color : [ 'red' , 'blue' , 'green' ]
258
+ }
259
+ } ] , {
260
+ font : { family : 'Times New Roman' }
261
+ } )
262
+ . then ( function ( ) {
263
+ d3 . selectAll ( 'text' ) . each ( function ( ) {
264
+ var tx = d3 . select ( this ) ;
265
+ expect ( tx . style ( 'font-family' ) ) . toEqual ( '\"Times New Roman\"' ) ;
266
+ } ) ;
267
+
268
+ d3 . selectAll ( '.point' ) . each ( function ( ) {
269
+ var pt = d3 . select ( this ) ;
270
+ expect ( pt . style ( 'fill' ) . substr ( 0 , 6 ) ) . toEqual ( 'url(\"#' ) ;
271
+ } ) ;
272
+
273
+ return Plotly . Snapshot . toSVG ( gd ) ;
274
+ } )
275
+ . then ( function ( svg ) {
276
+ var svgDOM = parser . parseFromString ( svg , 'image/svg+xml' ) ;
277
+ var i ;
278
+
279
+ var textElements = svgDOM . getElementsByTagName ( 'text' ) ;
280
+ expect ( textElements . length ) . toEqual ( 11 ) ;
281
+
282
+ for ( i = 0 ; i < textElements . length ; i ++ ) {
283
+ expect ( textElements [ i ] . style [ 'font-family' ] ) . toEqual ( '\"Times New Roman\"' ) ;
284
+ }
285
+
286
+ var pointElements = svgDOM . getElementsByClassName ( 'point' ) ;
287
+ expect ( pointElements . length ) . toEqual ( 3 ) ;
288
+
289
+ for ( i = 0 ; i < pointElements . length ; i ++ ) {
290
+ expect ( pointElements [ i ] . style . fill . substr ( 0 , 6 ) ) . toEqual ( 'url(\"#' ) ;
291
+ }
292
+ } )
293
+ . catch ( fail )
294
+ . then ( done ) ;
295
+ } ) ;
248
296
} ) ;
249
297
} ) ;
0 commit comments