Skip to content

Commit b2f9db9

Browse files
committed
fixing code to fix tests
1 parent ad728a3 commit b2f9db9

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

plotly/offline/offline.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ def _plot_html(figure_or_data, show_link, link_text, validate,
184184
id=plotdivid, script=script,
185185
height=height, width=width)
186186

187-
return plotly_html_div, plotdivid, width, height, plotdivid
187+
if download:
188+
return plotly_html_div, plotdivid, width, height, plotdivid
189+
else:
190+
return plotly_html_div, plotdivid, width, height
188191

189192

190193
def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
@@ -232,31 +235,39 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
232235
if not tools._ipython_imported:
233236
raise ImportError('`iplot` can only run inside an IPython Notebook.')
234237

235-
plot_html, plotdivid, width, height, plot_id = _plot_html(
236-
figure_or_data, show_link, link_text, validate,
237-
'100%', 525, global_requirejs=True, download=download_image)
238-
239-
display(HTML(plot_html))
240-
241-
# Write script to download image of the plot
242-
script = ('<script>'
243-
'function downloadimage(format, height, width,'
244-
' filename) {{'
245-
'var p = document.getElementById(\'{plot_id}\');'
246-
'Plotly.downloadImage(p, {{format: format, height: height, '
247-
'width: width, filename: filename}});'
248-
'}};'
249-
'if(document.readyState == \'complete\') {{'
250-
'downloadimage(\'{format}\', {height}, {width}, \'{filename}\');'
251-
'}}'
252-
'</script>'
253-
).format(format=format, width=_width, height=_height,
254-
filename=filename, plot_id=plot_id)
255-
# allow time for the plot to draw
256-
import time
257-
time.sleep(1)
258-
#inject code to download an image of the plot
259-
display(HTML(script))
238+
def inject():
239+
display(HTML(plot_html))
240+
241+
# Write script to download image of the plot
242+
script = ('<script>'
243+
'function downloadimage(format, height, width,'
244+
' filename) {{'
245+
'var p = document.getElementById(\'{plot_id}\');'
246+
'Plotly.downloadImage(p, {{format: format, height: height, '
247+
'width: width, filename: filename}});'
248+
'}};'
249+
'if(document.readyState == \'complete\') {{'
250+
'downloadimage(\'{format}\', {height}, {width}, \'{filename}\');'
251+
'}}'
252+
'</script>'
253+
).format(format=format, width=_width, height=_height,
254+
filename=filename, plot_id=plot_id)
255+
# allow time for the plot to draw
256+
import time
257+
time.sleep(1)
258+
#inject code to download an image of the plot
259+
display(HTML(script))
260+
261+
if download_image:
262+
plot_html, plotdivid, width, height, plot_id = _plot_html(
263+
figure_or_data, show_link, link_text, validate,
264+
'100%', 525, global_requirejs=True, download=download_image)
265+
inject()
266+
else:
267+
plot_html, plotdivid, width, height = _plot_html(
268+
figure_or_data, show_link, link_text, validate,
269+
'100%', 525, global_requirejs=True, download=download_image)
270+
inject()
260271

261272

262273
def plot(figure_or_data,

0 commit comments

Comments
 (0)