|
11 | 11 | import warnings |
12 | 12 | from pkg_resources import resource_string |
13 | 13 | import time |
| 14 | +import sys |
14 | 15 | import webbrowser |
15 | 16 |
|
16 | 17 | import plotly |
@@ -49,17 +50,13 @@ def get_plotlyjs(): |
49 | 50 | plotlyjs = resource_string('plotly', path).decode('utf-8') |
50 | 51 | return plotlyjs |
51 | 52 |
|
52 | | -def get_image_download_script(caller): |
| 53 | +def get_image_download_script(): |
53 | 54 | ''' |
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 |
62 | 57 | ''' |
| 58 | + # get the name of the function that called `get_image_download_script` |
| 59 | + caller = sys._getframe(1).f_code.co_name |
63 | 60 |
|
64 | 61 | if caller == 'iplot': |
65 | 62 | check_start = 'if(document.readyState == \'complete\') {{' |
@@ -303,11 +300,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', |
303 | 300 | ) |
304 | 301 | ) |
305 | 302 | # 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) |
311 | 308 | # allow time for the plot to draw |
312 | 309 | time.sleep(1) |
313 | 310 | # inject code to download an image of the plot |
@@ -426,7 +423,7 @@ def plot(figure_or_data, |
426 | 423 | ) |
427 | 424 | # if the check passes then download script is injected. |
428 | 425 | # write the download script: |
429 | | - script = image_download_script('plot') |
| 426 | + script = get_image_download_script() |
430 | 427 | script = script.format(format=image, |
431 | 428 | width=image_width, |
432 | 429 | height=image_height, |
|
0 commit comments