@@ -358,8 +358,12 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
358358 plot_html , plotdivid , width , height = _plot_html (
359359 figure_or_data , config , validate , '100%' , 525 , True
360360 )
361- display_bundle ['text/html' ] = plot_html
362- display_bundle ['text/vnd.plotly.v1+html' ] = plot_html
361+ resize_script = ''
362+ if width == '100%' or height == '100%' :
363+ resize_script = _build_resize_script (plotdivid )
364+
365+ display_bundle ['text/html' ] = plot_html + resize_script
366+ display_bundle ['text/vnd.plotly.v1+html' ] = plot_html + resize_script
363367
364368 ipython_display .display (display_bundle , raw = True )
365369
@@ -389,6 +393,17 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
389393 ipython_display .display (ipython_display .HTML (script ))
390394
391395
396+ def _build_resize_script (plotdivid ):
397+ resize_script = (
398+ ''
399+ '<script type="text/javascript">'
400+ 'window.addEventListener("resize", function(){{'
401+ 'Plotly.Plots.resize(document.getElementById("{id}"));}});'
402+ '</script>'
403+ ).format (id = plotdivid )
404+ return resize_script
405+
406+
392407def plot (figure_or_data , show_link = True , link_text = 'Export to plot.ly' ,
393408 validate = True , output_type = 'file' , include_plotlyjs = True ,
394409 filename = 'temp-plot.html' , auto_open = True , image = None ,
@@ -477,13 +492,7 @@ def plot(figure_or_data, show_link=True, link_text='Export to plot.ly',
477492
478493 resize_script = ''
479494 if width == '100%' or height == '100%' :
480- resize_script = (
481- ''
482- '<script type="text/javascript">'
483- 'window.addEventListener("resize", function(){{'
484- 'Plotly.Plots.resize(document.getElementById("{id}"));}});'
485- '</script>'
486- ).format (id = plotdivid )
495+ resize_script = _build_resize_script (plotdivid )
487496
488497 if output_type == 'file' :
489498 with open (filename , 'w' ) as f :
0 commit comments