Skip to content

Commit a358df3

Browse files
committed
Merge pull request #344 from BibMartin/doctring_end
Complete docstrings
2 parents 5f50773 + 528b3fd commit a358df3

File tree

4 files changed

+78
-24
lines changed

4 files changed

+78
-24
lines changed

folium/colormap.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,13 @@ class ColorMap(MacroElement):
264264
265265
Parameters
266266
----------
267-
TODO: docstring"""
268-
267+
vmin: float
268+
The left bound of the color scale.
269+
vmax: float
270+
The right bound of the color scale.
271+
caption: str
272+
A caption to draw with the colormap.
273+
"""
269274
def __init__(self, vmin=0., vmax=1., caption=""):
270275
super(ColorMap, self).__init__()
271276
self._name = 'ColorMap'
@@ -278,7 +283,7 @@ def __init__(self, vmin=0., vmax=1., caption=""):
278283
self._template = self._env.get_template('color_scale.js')
279284

280285
def render(self, **kwargs):
281-
"""TODO: docstring"""
286+
"""Renders the HTML representation of the element."""
282287
self.color_domain = [self.vmin + (self.vmax-self.vmin) * k/499. for
283288
k in range(500)]
284289
self.color_range = [self.__call__(x) for x in self.color_domain]

folium/element.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ class Element(object):
2525
2626
Parameters
2727
----------
28-
TODO: docstring.
28+
template: str, default None
29+
A jinaj2-compatible template string for rendering the element.
30+
If None, template will be:
31+
{% for name, element in this._children.items() %}
32+
{{element.render(**kwargs)}}
33+
{% endfor %}
34+
so that all the element's children are rendered.
35+
template_name: str, default None
36+
If no template is provided, you can also provide a filename.
2937
"""
3038
def __init__(self, template=None, template_name=None):
3139
self._name = 'Element'
@@ -42,7 +50,10 @@ def __init__(self, template=None, template_name=None):
4250
""")
4351

4452
def get_name(self):
45-
"""TODO: docstring."""
53+
"""Returns a string representation of the object.
54+
This string has to be unique and to be a python and javascript-compatible
55+
variable name.
56+
"""
4657
return _camelify(self._name) + '_' + self._id
4758

4859
def _get_self_bounds(self):
@@ -95,7 +106,7 @@ def add_to(self, parent, name=None, index=None):
95106
return self
96107

97108
def to_dict(self, depth=-1, ordered=True, **kwargs):
98-
"""TODO: docstring."""
109+
"""Returns a dict representation of the object."""
99110
if ordered:
100111
dict_fun = OrderedDict
101112
else:
@@ -109,7 +120,7 @@ def to_dict(self, depth=-1, ordered=True, **kwargs):
109120
return out
110121

111122
def to_json(self, depth=-1, **kwargs):
112-
"""TODO: docstring."""
123+
"""Returns a JSON representation of the object."""
113124
return json.dumps(self.to_dict(depth=depth, ordered=True), **kwargs)
114125

115126
def get_root(self):
@@ -146,15 +157,15 @@ def save(self, outfile, close_file=True, **kwargs):
146157

147158

148159
class Link(Element):
149-
"""TODO: docstring."""
160+
"""An abstract class for embedding a link in the HTML."""
150161
def get_code(self):
151-
"""TODO : docstring."""
162+
"""Opens the link and returns the response's content."""
152163
if self.code is None:
153164
self.code = urlopen(self.url).read()
154165
return self.code
155166

156167
def to_dict(self, depth=-1, **kwargs):
157-
"""TODO : docstring."""
168+
"""Returns a dict representation of the object."""
158169
out = super(Link, self).to_dict(depth=-1, **kwargs)
159170
out['url'] = self.url
160171
return out
@@ -331,15 +342,15 @@ def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
331342
"""), name='css_style')
332343

333344
def to_dict(self, depth=-1, **kwargs):
334-
"""TODO: docstring."""
345+
"""Returns a dict representation of the object."""
335346
out = super(Figure, self).to_dict(depth=depth, **kwargs)
336347
out['header'] = self.header.to_dict(depth=depth-1, **kwargs)
337348
out['html'] = self.html.to_dict(depth=depth-1, **kwargs)
338349
out['script'] = self.script.to_dict(depth=depth-1, **kwargs)
339350
return out
340351

341352
def get_root(self):
342-
"""TODO: docstring."""
353+
"""Returns the root of the elements tree."""
343354
return self
344355

345356
def render(self, **kwargs):
@@ -375,7 +386,21 @@ def _repr_html_(self, **kwargs):
375386
return iframe
376387

377388
def add_subplot(self, x, y, n, margin=0.05):
378-
"""TODO: docstring."""
389+
"""Creates a div child subplot in a matplotlib.figure.add_subplot style.
390+
391+
Parameters
392+
----------
393+
x : int
394+
The number of rows in the grid.
395+
y : int
396+
The number of columns in the grid.
397+
n : int
398+
The cell number in the grid, counted from 1 to x*y.
399+
400+
Example:
401+
>>> fig.add_subplot(3,2,5)
402+
# Create a div in the 5th cell of a 3rows x 2columns grid(bottom-left corner).
403+
"""
379404
width = 1./y
380405
height = 1./x
381406
left = ((n-1) % y)*width
@@ -427,11 +452,21 @@ def __init__(self, data, width="100%", height="100%"):
427452

428453

429454
class Div(Figure):
430-
"""Create a Map with Folium and Leaflet.js.
455+
"""Create a Div to be embedded in a Figure.
431456
432457
Parameters
433458
----------
434-
TODO: docstring.
459+
width: int or str, default '100%'
460+
The width of the div in pixels (int) or percentage (str).
461+
height: int or str, default '100%'
462+
The height of the div in pixels (int) or percentage (str).
463+
left: int or str, default '0%'
464+
The left-position of the div in pixels (int) or percentage (str).
465+
top: int or str, default '0%'
466+
The top-position of the div in pixels (int) or percentage (str).
467+
position: str, default 'relative'
468+
The position policy of the div.
469+
Usual values are 'relative', 'absolute', 'fixed', 'static'.
435470
"""
436471
def __init__(self, width='100%', height='100%',
437472
left="0%", top="0%", position='relative'):
@@ -475,7 +510,7 @@ def __init__(self, width='100%', height='100%',
475510
""")
476511

477512
def get_root(self):
478-
"""TODO: docstring."""
513+
"""Returns the root of the elements tree."""
479514
return self
480515

481516
def render(self, **kwargs):

folium/features.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(self, location, color='black', opacity=1, weight=2,
138138
""")
139139

140140
def render(self, **kwargs):
141-
"""TODO: docstring."""
141+
"""Renders the HTML representation of the element."""
142142
super(RegularPolygonMarker, self).render()
143143

144144
figure = self.get_root()
@@ -197,7 +197,7 @@ def __init__(self, data, width=None, height=None,
197197
self._template = Template(u"")
198198

199199
def render(self, **kwargs):
200-
"""TODO: docstring"""
200+
"""Renders the HTML representation of the element."""
201201
self.json = json.dumps(self.data)
202202

203203
self._parent.html.add_children(Element(Template("""
@@ -322,7 +322,9 @@ def style_function(x): return {}
322322
""") # noqa
323323

324324
def style_data(self):
325-
"""TODO: docstring."""
325+
"""Applies self.style_function to each feature of self.data and returns a corresponding
326+
JSON output.
327+
"""
326328
if 'features' not in self.data.keys():
327329
# Catch case when GeoJSON is just a single Feature or a geometry.
328330
if not (isinstance(self.data, dict) and 'geometry' in self.data.keys()): # noqa
@@ -438,7 +440,9 @@ def style_function(x): return {}
438440
""") # noqa
439441

440442
def style_data(self):
441-
"""TODO: docstring."""
443+
"""Applies self.style_function to each feature of self.data and returns a corresponding
444+
JSON output.
445+
"""
442446
def recursive_get(data, keys):
443447
if len(keys):
444448
return recursive_get(data.get(keys[0]), keys[1:])
@@ -450,7 +454,7 @@ def recursive_get(data, keys):
450454
return json.dumps(self.data, sort_keys=True)
451455

452456
def render(self, **kwargs):
453-
"""TODO: docstring."""
457+
"""Renders the HTML representation of the element."""
454458
super(TopoJson, self).render(**kwargs)
455459

456460
figure = self.get_root()
@@ -516,7 +520,7 @@ def __init__(self, name=None, overlay=True, control=True):
516520
""")
517521

518522
def render(self, **kwargs):
519-
"""TODO: docstring"""
523+
"""Renders the HTML representation of the element."""
520524
super(MarkerCluster, self).render()
521525

522526
figure = self.get_root()

folium/map.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ def add_tile_layer(self, tiles='OpenStreetMap', name=None,
179179
API_key=None, max_zoom=18, min_zoom=1,
180180
attr=None, tile_name=None, tile_url=None,
181181
active=False, detect_retina=False, **kwargs):
182-
"""TODO: docstring."""
182+
"""Add a tile layer to the map.
183+
184+
See TileLayer for options."""
183185
if tile_name is not None:
184186
name = tile_name
185187
warnings.warn("'tile_name' is deprecated. Use 'name' instead.")
@@ -487,7 +489,15 @@ def _get_self_bounds(self):
487489

488490

489491
class Popup(Element):
490-
"""TODO: docstring."""
492+
"""Create a Popup instance that can be linked to a Layer.
493+
494+
Parameters
495+
----------
496+
html: string or Element
497+
Content of the Popup.
498+
max_width: int, default 300
499+
The maximal width of the popup.
500+
"""
491501
def __init__(self, html=None, max_width=300):
492502
super(Popup, self).__init__()
493503
self._name = 'Popup'

0 commit comments

Comments
 (0)