@@ -48,6 +48,37 @@ def get_plotlyjs():
48
48
plotlyjs = resource_string ('plotly' , path ).decode ('utf-8' )
49
49
return plotlyjs
50
50
51
+ def image_download_script (type ):
52
+
53
+ if type == 'iplot' :
54
+ check_start = 'if(document.readyState == \' complete\' ) {{'
55
+ check_end = '}}'
56
+ elif type == 'plot' :
57
+ check_start = ''
58
+ check_end = ''
59
+
60
+ return (
61
+ ('<script>'
62
+ 'function downloadimage(format, height, width,'
63
+ ' filename) {{'
64
+ 'var p = document.getElementById(\' {plot_id}\' );'
65
+ 'Plotly.downloadImage(p, {{format: format, height: height, '
66
+ 'width: width, filename: filename}});'
67
+ '}};' +
68
+ check_start +
69
+ 'if(confirm(\' Do you want to save this image as '
70
+ '{filename}.{format}?\\ n\\ n'
71
+ 'For higher resolution images and more export options, '
72
+ 'consider making requests to our image servers. Type: '
73
+ 'help(py.image) for more details.'
74
+ '\' )) {{'
75
+ 'downloadimage(\' {format}\' , {height}, {width}, '
76
+ '\' {filename}\' );}}' +
77
+ check_end +
78
+ '</script>'
79
+ )
80
+ )
81
+
51
82
52
83
def init_notebook_mode (connected = False ):
53
84
"""
@@ -269,14 +300,23 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
269
300
'}};'
270
301
'if(document.readyState == \' complete\' ) {{'
271
302
'if(confirm(\' Do you want to save this image as '
272
- '{filename}.{format}?\' )) {{'
303
+ '{filename}.{format}?\\ n\\ n\\ n\\ n'
304
+ 'For higher resolution images and more export options, '
305
+ 'consider making requests to our image servers. Type: '
306
+ 'help(py.image) for more details.'
307
+ '\' )) {{'
273
308
'downloadimage(\' {format}\' , {height}, {width}, '
274
309
'\' {filename}\' );}}'
275
310
'}}'
276
311
'</script>'
277
312
).format (format = image , width = image_width ,
278
313
height = image_height , filename = filename ,
279
314
plot_id = plotdivid )
315
+ script = image_download_script ('iplot' ).format (format = image ,
316
+ width = image_width ,
317
+ height = image_height ,
318
+ filename = filename ,
319
+ plot_id = plotdivid )
280
320
# allow time for the plot to draw
281
321
import time
282
322
time .sleep (1 )
@@ -412,6 +452,13 @@ def plot(figure_or_data,
412
452
).format (format = image , width = image_width ,
413
453
height = image_height ,
414
454
filename = image_filename , plot_id = plotdivid )
455
+
456
+ script = image_download_script ('plot' )
457
+ script = script .format (format = image ,
458
+ width = image_width ,
459
+ height = image_height ,
460
+ filename = image_filename ,
461
+ plot_id = plotdivid )
415
462
else :
416
463
script = ''
417
464
0 commit comments