@@ -210,20 +210,20 @@ def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
210210
211211 Parameters
212212 ----------
213- width : str, default "100%"
214- The width of the Figure.
215- It may be a percentage or pixel value (like "300px").
216- height : str, default None
217- The height of the Figure.
218- It may be a percentage or a pixel value (like "300px").
219- ratio : str, default "60%"
220- A percentage defining the aspect ratio of the Figure.
221- It will be ignored if height is not None.
222- figsize : tuple of two int, default None
223- If you're a matplotlib addict, you can overwrite width and
224- height. Values will be converted into pixels in using 60 dpi.
225- For example figsize=(10, 5) will result in
226- width="600px", height="300px".
213+ width : str, default "100%"
214+ The width of the Figure.
215+ It may be a percentage or pixel value (like "300px").
216+ height : str, default None
217+ The height of the Figure.
218+ It may be a percentage or a pixel value (like "300px").
219+ ratio : str, default "60%"
220+ A percentage defining the aspect ratio of the Figure.
221+ It will be ignored if height is not None.
222+ figsize : tuple of two int, default None
223+ If you're a matplotlib addict, you can overwrite width and
224+ height. Values will be converted into pixels in using 60 dpi.
225+ For example figsize=(10, 5) will result in
226+ width="600px", height="300px".
227227 """
228228 super (Figure , self ).__init__ ()
229229 self ._name = 'Figure'
@@ -295,6 +295,9 @@ def to_dict(self, depth=-1, **kwargs):
295295 out ['script' ] = self .script .to_dict (depth = depth - 1 , ** kwargs )
296296 return out
297297
298+ def get_root (self ):
299+ return self
300+
298301 def render (self , ** kwargs ):
299302 """TODO : docstring here."""
300303 for name , child in self ._children .items ():
@@ -451,6 +454,69 @@ def _repr_html_(self, **kwargs):
451454 out = self ._parent ._repr_html_ (** kwargs )
452455 return out
453456
457+ class IFrame (Element ):
458+ def __init__ (self , html = None , width = "100%" , height = None , ratio = "60%" , figsize = None ):
459+ """Create a Figure object, to plot things into it.
460+
461+ Parameters
462+ ----------
463+ html : str, default None
464+ Eventual HTML code that you want to put in the frame.
465+ width : str, default "100%"
466+ The width of the Figure.
467+ It may be a percentage or pixel value (like "300px").
468+ height : str, default None
469+ The height of the Figure.
470+ It may be a percentage or a pixel value (like "300px").
471+ ratio : str, default "60%"
472+ A percentage defining the aspect ratio of the Figure.
473+ It will be ignored if height is not None.
474+ figsize : tuple of two int, default None
475+ If you're a matplotlib addict, you can overwrite width and
476+ height. Values will be converted into pixels in using 60 dpi.
477+ For example figsize=(10, 5) will result in
478+ width="600px", height="300px".
479+ """
480+ super (IFrame , self ).__init__ ()
481+ self ._name = 'IFrame'
482+
483+ self .width = width
484+ self .height = height
485+ self .ratio = ratio
486+ if figsize is not None :
487+ self .width = str (60 * figsize [0 ])+ 'px'
488+ self .height = str (60 * figsize [1 ])+ 'px'
489+
490+ if isinstance (html , text_type ) or isinstance (html , binary_type ):
491+ self .add_children (Element (html ))
492+ elif html is not None :
493+ self .add_children (html )
494+
495+ def render (self , ** kwargs ):
496+ """Displays the Figure in a Jupyter notebook.
497+
498+ Parameters
499+ ----------
500+
501+ """
502+ html = super (IFrame ,self ).render (** kwargs )
503+ html = "data:text/html;base64," + base64 .b64encode (html .encode ('utf8' )).decode ('utf8' ) # noqa
504+
505+ if self .height is None :
506+ iframe = (
507+ '<div style="width:{width};">'
508+ '<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">'
509+ '<iframe src="{html}" style="position:absolute;width:100%;height:100%;left:0;top:0;">'
510+ '</iframe>'
511+ '</div></div>' ).format # noqa
512+ iframe = iframe (html = html ,
513+ width = self .width ,
514+ ratio = self .ratio )
515+ else :
516+ iframe = ('<iframe src="{html}" width="{width}" '
517+ 'height="{height}"></iframe>' ).format
518+ iframe = iframe (html = html , width = self .width , height = self .height )
519+ return iframe
454520
455521class MacroElement (Element ):
456522 """This is a parent class for Elements defined by a macro template.
0 commit comments