@@ -13,6 +13,11 @@ var EventEmitter = require('events').EventEmitter;
1313var Plotly = require ( '../plotly' ) ;
1414var Lib = require ( '../lib' ) ;
1515
16+ var helpers = require ( './helpers' ) ;
17+ var clonePlot = require ( './cloneplot' ) ;
18+ var toSVG = require ( './tosvg' ) ;
19+ var svgToImg = require ( './svgtoimg' ) ;
20+
1621
1722/**
1823 * @param {object } gd figure Object
@@ -22,10 +27,9 @@ var Lib = require('../lib');
2227function toImage ( gd , opts ) {
2328
2429 // first clone the GD so we can operate in a clean environment
25- var Snapshot = Plotly . Snapshot ;
2630 var ev = new EventEmitter ( ) ;
2731
28- var clone = Snapshot . clone ( gd , { format : 'png' } ) ;
32+ var clone = clonePlot ( gd , { format : 'png' } ) ;
2933 var clonedGd = clone . td ;
3034
3135 // put the cloned div somewhere off screen before attaching to DOM
@@ -34,15 +38,15 @@ function toImage(gd, opts) {
3438 document . body . appendChild ( clonedGd ) ;
3539
3640 function wait ( ) {
37- var delay = Snapshot . getDelay ( clonedGd . _fullLayout ) ;
41+ var delay = helpers . getDelay ( clonedGd . _fullLayout ) ;
3842
3943 setTimeout ( function ( ) {
40- var svg = Plotly . Snapshot . toSVG ( clonedGd ) ;
44+ var svg = toSVG ( clonedGd ) ;
4145
4246 var canvas = document . createElement ( 'canvas' ) ;
4347 canvas . id = Lib . randstr ( ) ;
4448
45- ev = Plotly . Snapshot . svgToImg ( {
49+ ev = svgToImg ( {
4650 format : opts . format ,
4751 width : clonedGd . _fullLayout . width ,
4852 height : clonedGd . _fullLayout . height ,
@@ -58,12 +62,9 @@ function toImage(gd, opts) {
5862 } , delay ) ;
5963 }
6064
61- var redrawFunc = Snapshot . getRedrawFunc ( clonedGd ) ;
65+ var redrawFunc = helpers . getRedrawFunc ( clonedGd ) ;
6266
6367 Plotly . plot ( clonedGd , clone . data , clone . layout , clone . config )
64- // TODO: the following is Plotly.Plots.redrawText but without the waiting.
65- // we shouldn't need to do this, but in *occasional* cases we do. Figure
66- // out why and take it out.
6768 . then ( redrawFunc )
6869 . then ( wait )
6970 . catch ( function ( err ) {
0 commit comments