File tree Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,11 @@ function toImage(gd, opts) {
143143 function convert ( ) {
144144 return new Promise ( function ( resolve , reject ) {
145145 var svg = toSVG ( clonedGd ) ;
146+ var width = clonedGd . _fullLayout . width ;
147+ var height = clonedGd . _fullLayout . height ;
148+
149+ Plotly . purge ( clonedGd )
150+ document . body . removeChild ( clonedGd )
146151
147152 if ( format === 'svg' ) {
148153 if ( imageDataOnly ) {
@@ -157,8 +162,8 @@ function toImage(gd, opts) {
157162
158163 svgToImg ( {
159164 format : format ,
160- width : clonedGd . _fullLayout . width ,
161- height : clonedGd . _fullLayout . height ,
165+ width : width ,
166+ height : height ,
162167 canvas : canvas ,
163168 svg : svg ,
164169 // ask svgToImg to return a Promise
@@ -167,14 +172,8 @@ function toImage(gd, opts) {
167172 // compatibility
168173 promise : true
169174 } )
170- . then ( function ( url ) {
171- Plotly . purge ( clonedGd ) ;
172- document . body . removeChild ( clonedGd ) ;
173- resolve ( url ) ;
174- } )
175- . catch ( function ( err ) {
176- reject ( err ) ;
177- } ) ;
175+ . then ( resolve )
176+ . catch ( reject )
178177 } ) ;
179178 }
180179
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ var Lib = require('@src/lib');
33
44var d3 = require ( 'd3' ) ;
55var createGraphDiv = require ( '../assets/create_graph_div' ) ;
6+ var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
67var fail = require ( '../assets/fail_test' ) ;
78var customMatchers = require ( '../assets/custom_matchers' ) ;
89var subplotMock = require ( '@mocks/multiple_subplots.json' ) ;
@@ -20,12 +21,7 @@ describe('Plotly.toImage', function() {
2021 gd = createGraphDiv ( ) ;
2122 } ) ;
2223
23- afterEach ( function ( ) {
24- // make sure ALL graph divs are deleted,
25- // even the ones generated by Plotly.toImage
26- d3 . selectAll ( '.js-plotly-plot' ) . remove ( ) ;
27- d3 . selectAll ( '#graph' ) . remove ( ) ;
28- } ) ;
24+ afterEach ( destroyGraphDiv )
2925
3026 function createImage ( url ) {
3127 return new Promise ( function ( resolve , reject ) {
You can’t perform that action at this time.
0 commit comments