Skip to content

Commit 0582283

Browse files
committed
fixed function names, as well as added a better check for the caller of get_image_download_script
1 parent 7b4681a commit 0582283

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

plotly/offline/offline.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import warnings
1212
from pkg_resources import resource_string
1313
import time
14+
import sys
1415
import webbrowser
1516

1617
import plotly
@@ -49,17 +50,13 @@ def get_plotlyjs():
4950
plotlyjs = resource_string('plotly', path).decode('utf-8')
5051
return plotlyjs
5152

52-
def get_image_download_script(caller):
53+
def get_image_download_script():
5354
'''
54-
This function will return a script that will download an image of a Plotly
55-
plot.
56-
57-
Keyword Arguments:
58-
caller ('plot', 'iplot') -- specifies which function made the call for the
59-
download script. If `iplot`, then an extra condition is added into the
60-
download script to ensure that download prompts aren't iniitated on
61-
page reloads.
55+
This function will return a script that will download an image of the
56+
most recently rendered Plotly plot
6257
'''
58+
# get the name of the function that called `get_image_download_script`
59+
caller = sys._getframe(1).f_code.co_name
6360

6461
if caller == 'iplot':
6562
check_start = 'if(document.readyState == \'complete\') {{'
@@ -303,11 +300,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
303300
)
304301
)
305302
# if image is given, and is a valid format, we will download the image
306-
script = image_download_script('iplot').format(format=image,
307-
width=image_width,
308-
height=image_height,
309-
filename=filename,
310-
plot_id=plotdivid)
303+
script = get_image_download_script().format(format=image,
304+
width=image_width,
305+
height=image_height,
306+
filename=filename,
307+
plot_id=plotdivid)
311308
# allow time for the plot to draw
312309
time.sleep(1)
313310
# inject code to download an image of the plot
@@ -426,7 +423,7 @@ def plot(figure_or_data,
426423
)
427424
# if the check passes then download script is injected.
428425
# write the download script:
429-
script = image_download_script('plot')
426+
script = get_image_download_script()
430427
script = script.format(format=image,
431428
width=image_width,
432429
height=image_height,

0 commit comments

Comments
 (0)