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