11# -*- coding: utf-8 -*-
22"""
3- Features
3+ Elements
44------
55
6- A generic class for creating features .
6+ A generic class for creating Elements .
77"""
88import warnings
99from uuid import uuid4
@@ -20,21 +20,21 @@ def _camelify(out):
2020 else x .lower ()+ "_" if i < len (out )- 1 and x .islower () and out [i + 1 ].isupper ()
2121 else x .lower () for i ,x in enumerate (list (out ))])).lstrip ('_' ).replace ('__' ,'_' )
2222
23- class Feature (object ):
24- """Basic feature object that does nothing.
25- Other features may inherit from this one."""
23+ class Element (object ):
24+ """Basic Element object that does nothing.
25+ Other Elements may inherit from this one."""
2626 def __init__ (self , template = None , template_name = None ):
27- """Creates a feature ."""
28- self ._name = 'Feature '
27+ """Creates a Element ."""
28+ self ._name = 'Element '
2929 self ._id = uuid4 ().hex
3030 self ._env = ENV
3131 self ._children = OrderedDict ()
3232 self ._parent = None
3333 self ._template = Template (template ) if template is not None \
3434 else ENV .get_template (template_name ) if template_name is not None \
3535 else Template (u"""
36- {% for name, feature in this._children.items() %}
37- {{feature .render(**kwargs)}}
36+ {% for name, element in this._children.items() %}
37+ {{element .render(**kwargs)}}
3838 {% endfor %}
3939 """ )
4040
@@ -54,7 +54,7 @@ def add_children(self, child, name=None, index=None):
5454 child ._parent = self
5555
5656 def add_to (self , parent , name = None , index = None ):
57- """Add feature to a parent."""
57+ """Add element to a parent."""
5858 parent .add_children (self , name = name , index = index )
5959
6060 def to_dict (self , depth = - 1 , ordered = True , ** kwargs ):
@@ -74,7 +74,7 @@ def to_json(self, depth=-1, **kwargs):
7474 return json .dumps (self .to_dict (depth = depth , ordered = True ), ** kwargs )
7575
7676 def get_root (self ):
77- """Returns the root of the features tree."""
77+ """Returns the root of the elements tree."""
7878 if self ._parent is None :
7979 return self
8080 else :
@@ -118,13 +118,13 @@ def render(self, **kwargs):
118118 "https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css" ),
119119 ]
120120
121- class Figure (Feature ):
121+ class Figure (Element ):
122122 def __init__ (self ):
123123 super (Figure , self ).__init__ ()
124124 self ._name = 'Figure'
125- self .header = Feature ()
126- self .html = Feature ()
127- self .script = Feature ()
125+ self .header = Element ()
126+ self .html = Element ()
127+ self .script = Element ()
128128 #self.axes = []
129129
130130 self .header ._parent = self
@@ -145,7 +145,7 @@ def __init__(self):
145145 """ )
146146
147147 # Create the meta tag
148- self .header .add_children (Feature (
148+ self .header .add_children (Element (
149149 '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />' ),
150150 name = 'meta_http' )
151151
@@ -157,7 +157,7 @@ def __init__(self):
157157 for name , url in _default_css :
158158 self .header .add_children (CssLink (url ), name = name )
159159
160- self .header .add_children (Feature ("""
160+ self .header .add_children (Element ("""
161161 <style>
162162
163163 html, body {
@@ -217,7 +217,7 @@ def _repr_html_(self, figsize=(17,10), **kwargs):
217217 )
218218 return iframe
219219
220- class Link (Feature ):
220+ class Link (Element ):
221221 def get_code (self ):
222222 if self .code is None :
223223 self .code = urlopen (self .url ).read ()
@@ -277,9 +277,9 @@ def __init__(self, url, download=False):
277277 {% endif %}
278278 """ )
279279
280- class MacroFeature ( Feature ):
281- """This is a parent class for Features defined by a macro template.
282- To compute your own feature , all you have to do is:
280+ class MacroElement ( Element ):
281+ """This is a parent class for Elements defined by a macro template.
282+ To compute your own element , all you have to do is:
283283 * To inherit from this class
284284 * Overwrite the '_name' attribute
285285 * Overwrite the '_template' attribute with something of the form:
@@ -297,33 +297,33 @@ class MacroFeature(Feature):
297297 """
298298 def __init__ (self ):
299299 """TODO : docstring here"""
300- super (MacroFeature , self ).__init__ ()
301- self ._name = 'MacroFeature '
300+ super (MacroElement , self ).__init__ ()
301+ self ._name = 'MacroElement '
302302
303303 self ._template = Template (u"" )
304304
305305 def render (self , ** kwargs ):
306306 figure = self .get_root ()
307- assert isinstance (figure ,Figure ), ("You cannot render this Feature "
307+ assert isinstance (figure ,Figure ), ("You cannot render this Element "
308308 "if it's not in a Figure." )
309309
310310 header = self ._template .module .__dict__ .get ('header' ,None )
311311 if header is not None :
312- figure .header .add_children (Feature (header (self , kwargs )),
312+ figure .header .add_children (Element (header (self , kwargs )),
313313 name = self .get_name ())
314314
315315 html = self ._template .module .__dict__ .get ('html' ,None )
316316 if html is not None :
317- figure .html .add_children (Feature (html (self , kwargs )),
317+ figure .html .add_children (Element (html (self , kwargs )),
318318 name = self .get_name ())
319319
320320 script = self ._template .module .__dict__ .get ('script' ,None )
321321 if script is not None :
322- figure .script .add_children (Feature (script (self , kwargs )),
322+ figure .script .add_children (Element (script (self , kwargs )),
323323 name = self .get_name ())
324324
325- for name , feature in self ._children .items ():
326- feature .render (** kwargs )
325+ for name , element in self ._children .items ():
326+ element .render (** kwargs )
327327
328328def _parse_size (value ):
329329 try :
@@ -339,7 +339,7 @@ def _parse_size(value):
339339 raise ValueError (msg (value , value_type ))
340340 return value , value_type
341341
342- class Map (MacroFeature ):
342+ class Map (MacroElement ):
343343 def __init__ (self , location = None , width = '100%' , height = '100%' ,
344344 tiles = 'OpenStreetMap' , API_key = None , max_zoom = 18 , min_zoom = 1 ,
345345 zoom_start = 10 , attr = None , min_lat = - 90 , max_lat = 90 ,
@@ -480,7 +480,7 @@ def add_tile_layer(self, tiles='OpenStreetMap', name=None,
480480 attr = attr , API_key = API_key )
481481 self .add_children (tile_layer , name = tile_layer .tile_name )
482482
483- class TileLayer (MacroFeature ):
483+ class TileLayer (MacroElement ):
484484 def __init__ (self , tiles = 'OpenStreetMap' , name = None ,
485485 min_zoom = 1 , max_zoom = 18 , attr = None , API_key = None ):
486486 """TODO docstring here
@@ -561,7 +561,7 @@ def __init__(self, url, name=None,
561561 {% endmacro %}
562562 """ )
563563
564- class Icon (MacroFeature ):
564+ class Icon (MacroElement ):
565565 def __init__ (self , color = 'blue' , icon = 'info-sign' , angle = 0 ):
566566 """TODO : docstring here"""
567567 super (Icon , self ).__init__ ()
@@ -583,7 +583,7 @@ def __init__(self, color='blue', icon='info-sign', angle=0):
583583 {% endmacro %}
584584 """ )
585585
586- class Marker (MacroFeature ):
586+ class Marker (MacroElement ):
587587 def __init__ (self , location , popup = None , icon = None ):
588588 """Create a simple stock Leaflet marker on the map, with optional
589589 popup text or Vincent visualization.
@@ -627,7 +627,7 @@ def __init__(self, location, popup=None, icon=None):
627627 {% endmacro %}
628628 """ )
629629
630- class RegularPolygonMarker (MacroFeature ):
630+ class RegularPolygonMarker (MacroElement ):
631631 def __init__ (self , location , popup = None , icon = None ,
632632 color = 'black' , opacity = 1 , weight = 2 ,
633633 fill_color = 'blue' , fill_opacity = 1 ,
@@ -669,15 +669,15 @@ def render(self, **kwargs):
669669 super (RegularPolygonMarker , self ).render ()
670670
671671 figure = self .get_root ()
672- assert isinstance (figure ,Figure ), ("You cannot render this Feature "
672+ assert isinstance (figure ,Figure ), ("You cannot render this Element "
673673 "if it's not in a Figure." )
674674
675675 figure .header .add_children (\
676676 JavascriptLink ("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf"
677677 "/0.2/leaflet-dvf.markers.min.js" ),
678678 name = 'dvf_js' )
679679
680- class Html (Feature ):
680+ class Html (Element ):
681681 def __init__ (self , data , width = "100%" , height = "100%" ):
682682 """TODO : docstring here"""
683683 super (Html , self ).__init__ ()
@@ -693,19 +693,19 @@ def __init__(self, data, width="100%", height="100%"):
693693 {{this.data}}</div>
694694 """ )
695695
696- class Popup (Feature ):
696+ class Popup (Element ):
697697 def __init__ (self , html , max_width = 300 ):
698698 super (Popup , self ).__init__ ()
699699 self ._name = 'Popup'
700- self .header = Feature ()
701- self .html = Feature ()
702- self .script = Feature ()
700+ self .header = Element ()
701+ self .html = Element ()
702+ self .script = Element ()
703703
704704 self .header ._parent = self
705705 self .html ._parent = self
706706 self .script ._parent = self
707707
708- if isinstance (html , Feature ):
708+ if isinstance (html , Element ):
709709 self .html .add_children (html )
710710 elif isinstance (html , text_type ) or isinstance (html ,binary_type ):
711711 self .html .add_children (Html (text_type (html )))
@@ -715,15 +715,15 @@ def __init__(self, html, max_width=300):
715715 self ._template = Template (u"""
716716 var {{this.get_name()}} = L.popup({maxWidth: '{{this.max_width}}'});
717717
718- {% for name, feature in this.html._children.items() %}
719- var {{name}} = $('{{feature .render(**kwargs).replace('\\ n',' ')}}')[0];
718+ {% for name, element in this.html._children.items() %}
719+ var {{name}} = $('{{element .render(**kwargs).replace('\\ n',' ')}}')[0];
720720 {{this.get_name()}}.setContent({{name}});
721721 {% endfor %}
722722
723723 {{this._parent.get_name()}}.bindPopup({{this.get_name()}});
724724
725- {% for name, feature in this.script._children.items() %}
726- {{feature .render()}}
725+ {% for name, element in this.script._children.items() %}
726+ {{element .render()}}
727727 {% endfor %}
728728 """ )
729729
@@ -733,13 +733,13 @@ def render(self, **kwargs):
733733 child .render (** kwargs )
734734
735735 figure = self .get_root ()
736- assert isinstance (figure ,Figure ), ("You cannot render this Feature "
736+ assert isinstance (figure ,Figure ), ("You cannot render this Element "
737737 "if it's not in a Figure." )
738738
739- figure .script .add_children (Feature (\
739+ figure .script .add_children (Element (\
740740 self ._template .render (this = self , kwargs = kwargs )), name = self .get_name ())
741741
742- class Vega (Feature ):
742+ class Vega (Element ):
743743 def __init__ (self , data , width = "100%" , height = "100%" ):
744744 """TODO : docstring here"""
745745 super (Vega , self ).__init__ ()
@@ -753,18 +753,18 @@ def __init__(self, data, width="100%", height="100%"):
753753 def render (self , ** kwargs ):
754754 self .json = json .dumps (self .data )
755755
756- self ._parent .html .add_children (Feature (Template ("""
756+ self ._parent .html .add_children (Element (Template ("""
757757 <div id="{{this.get_name()}}"
758758 style="width: {{this.width[0]}}{{this.width[1]}}; height: {{this.height[0]}}{{this.height[1]}};">
759759 </div>
760760 """ ).render (this = self , kwargs = kwargs )), name = self .get_name ())
761761
762- self ._parent .script .add_children (Feature (Template ("""
762+ self ._parent .script .add_children (Element (Template ("""
763763 vega_parse({{this.json}},{{this.get_name()}});
764764 """ ).render (this = self )), name = self .get_name ())
765765
766766 figure = self .get_root ()
767- assert isinstance (figure ,Figure ), ("You cannot render this Feature "
767+ assert isinstance (figure ,Figure ), ("You cannot render this Element "
768768 "if it's not in a Figure." )
769769
770770 figure .header .add_children (\
0 commit comments