11
11
12
12
var d3 = require ( 'd3' ) ;
13
13
14
- var Plots = require ( '../plots/plots' ) ;
15
14
var svgTextUtils = require ( '../lib/svg_text_utils' ) ;
16
15
var Drawing = require ( '../components/drawing' ) ;
17
16
var Color = require ( '../components/color' ) ;
@@ -20,80 +19,34 @@ var xmlnsNamespaces = require('../constants/xmlns_namespaces');
20
19
21
20
22
21
module . exports = function toSVG ( gd , format ) {
22
+ var fullLayout = gd . _fullLayout ,
23
+ svg = fullLayout . _paper ,
24
+ toppaper = fullLayout . _toppaper ,
25
+ i ;
23
26
24
27
// make background color a rect in the svg, then revert after scraping
25
28
// all other alterations have been dealt with by properly preparing the svg
26
29
// in the first place... like setting cursors with css classes so we don't
27
30
// have to remove them, and providing the right namespaces in the svg to
28
31
// begin with
29
- var fullLayout = gd . _fullLayout ,
30
- svg = fullLayout . _paper ,
31
- size = fullLayout . _size ,
32
- domain ,
33
- i ;
34
-
35
32
svg . insert ( 'rect' , ':first-child' )
36
33
. call ( Drawing . setRect , 0 , 0 , fullLayout . width , fullLayout . height )
37
34
. call ( Color . fill , fullLayout . paper_bgcolor ) ;
38
35
39
- /* Grab the 3d scenes and rasterize em. Calculate their positions,
40
- * then insert them into the SVG element as images */
41
- var sceneIds = Plots . getSubplotIds ( fullLayout , 'gl3d' ) ,
42
- scene ;
43
-
44
- for ( i = 0 ; i < sceneIds . length ; i ++ ) {
45
- scene = fullLayout [ sceneIds [ i ] ] ;
46
- domain = scene . domain ;
47
- insertGlImage ( fullLayout , scene . _scene , {
48
- x : size . l + size . w * domain . x [ 0 ] ,
49
- y : size . t + size . h * ( 1 - domain . y [ 1 ] ) ,
50
- width : size . w * ( domain . x [ 1 ] - domain . x [ 0 ] ) ,
51
- height : size . h * ( domain . y [ 1 ] - domain . y [ 0 ] )
52
- } ) ;
53
- }
54
-
55
- // similarly for 2d scenes
56
- var subplotIds = Plots . getSubplotIds ( fullLayout , 'gl2d' ) ,
57
- subplot ;
58
-
59
- for ( i = 0 ; i < subplotIds . length ; i ++ ) {
60
- subplot = fullLayout . _plots [ subplotIds [ i ] ] ;
61
- insertGlImage ( fullLayout , subplot . _scene2d , {
62
- x : size . l ,
63
- y : size . t ,
64
- width : size . w ,
65
- height : size . h
66
- } ) ;
67
- }
36
+ // subplot-specific to-SVG methods
37
+ // which notably add the contents of the gl-container
38
+ // into the main svg node
39
+ var basePlotModules = fullLayout . _basePlotModules || [ ] ;
40
+ for ( i = 0 ; i < basePlotModules . length ; i ++ ) {
41
+ var _module = basePlotModules [ i ] ;
68
42
69
- // Grab the geos off the geo-container and place them in geoimages
70
- var geoIds = Plots . getSubplotIds ( fullLayout , 'geo' ) ,
71
- geoLayout ,
72
- geoFramework ;
73
-
74
- for ( i = 0 ; i < geoIds . length ; i ++ ) {
75
- geoLayout = fullLayout [ geoIds [ i ] ] ;
76
- domain = geoLayout . domain ;
77
- geoFramework = geoLayout . _geo . framework ;
78
-
79
- geoFramework . attr ( 'style' , null ) ;
80
- geoFramework
81
- . attr ( {
82
- x : size . l + size . w * domain . x [ 0 ] + geoLayout . _marginX ,
83
- y : size . t + size . h * ( 1 - domain . y [ 1 ] ) + geoLayout . _marginY ,
84
- width : geoLayout . _width ,
85
- height : geoLayout . _height
86
- } ) ;
87
-
88
- fullLayout . _geoimages . node ( )
89
- . appendChild ( geoFramework . node ( ) ) ;
43
+ if ( _module . toSVG ) _module . toSVG ( gd ) ;
90
44
}
91
45
92
- // now that we've got the 3d images in the right layer,
93
46
// add top items above them assumes everything in toppaper is either
94
47
// a group or a defs, and if it's empty (like hoverlayer) we can ignore it.
95
- if ( fullLayout . _toppaper ) {
96
- var nodes = fullLayout . _toppaper . node ( ) . childNodes ;
48
+ if ( toppaper ) {
49
+ var nodes = toppaper . node ( ) . childNodes ;
97
50
98
51
// make copy of nodes as childNodes prop gets mutated in loop below
99
52
var topGroups = Array . prototype . slice . call ( nodes ) ;
@@ -164,20 +117,3 @@ module.exports = function toSVG(gd, format) {
164
117
165
118
return s ;
166
119
} ;
167
-
168
- function insertGlImage ( fullLayout , scene , opts ) {
169
- var imageData = scene . toImage ( 'png' ) ;
170
-
171
- fullLayout . _glimages . append ( 'svg:image' )
172
- . attr ( {
173
- xmlns : xmlnsNamespaces . svg ,
174
- 'xlink:href' : imageData ,
175
- x : opts . x ,
176
- y : opts . y ,
177
- width : opts . width ,
178
- height : opts . height ,
179
- preserveAspectRatio : 'none'
180
- } ) ;
181
-
182
- scene . destroy ( ) ;
183
- }
0 commit comments