Skip to content

Commit d2011d3

Browse files
author
Martin Journois
committed
Moved __init__ docstrings to object
1 parent cfb6044 commit d2011d3

6 files changed

Lines changed: 732 additions & 662 deletions

File tree

folium/colormap.py

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,14 @@ def _base(x):
260260

261261

262262
class ColorMap(MacroElement):
263-
"""A generic class for creating colormaps."""
263+
"""A generic class for creating colormaps.
264+
265+
Parameters
266+
----------
267+
TODO: docstring
268+
"""
264269

265270
def __init__(self, vmin=0., vmax=1., caption=""):
266-
"""
267-
"""
268271
super(ColorMap, self).__init__()
269272
self._name = 'ColorMap'
270273

@@ -276,6 +279,7 @@ def __init__(self, vmin=0., vmax=1., caption=""):
276279
self._template = self._env.get_template('color_scale.js')
277280

278281
def render(self, **kwargs):
282+
"""TODO: docstring"""
279283
self.color_domain = [self.vmin + (self.vmax-self.vmin) * k/499. for
280284
k in range(500)]
281285
self.color_range = [self.__call__(x) for x in self.color_domain]
@@ -340,33 +344,32 @@ def _repr_html_(self):
340344

341345

342346
class LinearColormap(ColorMap):
347+
"""Creates a ColorMap based on linear interpolation of a set of colors
348+
over a given index.
349+
350+
Parameters
351+
----------
352+
colors : list-like object
353+
The set of colors to be used for interpolation.
354+
Colors can be provided in the form:
355+
* tuples of int between 0 and 255 (e.g: `(255,255,0)` or
356+
`(255, 255, 0, 255)`)
357+
* tuples of floats between 0. and 1. (e.g: `(1.,1.,0.)` or
358+
`(1., 1., 0., 1.)`)
359+
* HTML-like string (e.g: `"#ffff00`)
360+
* a color name or shortcut (e.g: `"y"` or `"yellow"`)
361+
index : list of floats, default None
362+
The values corresponding to each color.
363+
It has to be sorted, and have the same length as `colors`.
364+
If None, a regular grid between `vmin` and `vmax` is created.
365+
vmin : float, default 0.
366+
The minimal value for the colormap.
367+
Values lower than `vmin` will be bound directly to `colors[0]`.
368+
vmax : float, default 1.
369+
The maximal value for the colormap.
370+
Values higher than `vmax` will be bound directly to `colors[-1]`.
371+
"""
343372
def __init__(self, colors, index=None, vmin=0., vmax=1., caption=""):
344-
"""Creates a ColorMap based on linear interpolation of a set of colors
345-
over a given index.
346-
347-
Parameters
348-
----------
349-
colors : list-like object
350-
The set of colors to be used for interpolation.
351-
Colors can be provided in the form:
352-
* tuples of int between 0 and 255 (e.g: `(255,255,0)` or
353-
`(255, 255, 0, 255)`)
354-
* tuples of floats between 0. and 1. (e.g: `(1.,1.,0.)` or
355-
`(1., 1., 0., 1.)`)
356-
* HTML-like string (e.g: `"#ffff00`)
357-
* a color name or shortcut (e.g: `"y"` or `"yellow"`)
358-
index : list of floats, default None
359-
The values corresponding to each color.
360-
It has to be sorted, and have the same length as `colors`.
361-
If None, a regular grid between `vmin` and `vmax` is created.
362-
vmin : float, default 0.
363-
The minimal value for the colormap.
364-
Values lower than `vmin` will be bound directly to `colors[0]`.
365-
vmax : float, default 1.
366-
The maximal value for the colormap.
367-
Values higher than `vmax` will be bound directly to `colors[-1]`.
368-
369-
"""
370373
super(LinearColormap, self).__init__(vmin=vmin, vmax=vmax,
371374
caption=caption)
372375

@@ -522,32 +525,33 @@ def scale(self, vmin=0., vmax=1.):
522525

523526

524527
class StepColormap(ColorMap):
525-
def __init__(self, colors, index=None, vmin=0., vmax=1., caption=""):
526-
"""Creates a ColorMap based on stepwise constant colorfunction.
528+
"""Creates a ColorMap based on linear interpolation of a set of colors
529+
over a given index.
530+
531+
Parameters
532+
----------
533+
colors : list-like object
534+
The set of colors to be used for interpolation.
535+
Colors can be provided in the form:
536+
* tuples of int between 0 and 255 (e.g: `(255,255,0)` or
537+
`(255, 255, 0, 255)`)
538+
* tuples of floats between 0. and 1. (e.g: `(1.,1.,0.)` or
539+
`(1., 1., 0., 1.)`)
540+
* HTML-like string (e.g: `"#ffff00`)
541+
* a color name or shortcut (e.g: `"y"` or `"yellow"`)
542+
index : list of floats, default None
543+
The values corresponding to each color.
544+
It has to be sorted, and have the same length as `colors`.
545+
If None, a regular grid between `vmin` and `vmax` is created.
546+
vmin : float, default 0.
547+
The minimal value for the colormap.
548+
Values lower than `vmin` will be bound directly to `colors[0]`.
549+
vmax : float, default 1.
550+
The maximal value for the colormap.
551+
Values higher than `vmax` will be bound directly to `colors[-1]`.
527552
528-
Parameters
529-
----------
530-
colors : list-like object
531-
The set of colors to be used.
532-
Colors can be provided in the form:
533-
* tuples of int between 0 and 255 (e.g: `(255, 255, 0)` or
534-
`(255, 255, 0, 255)`)
535-
* tuples of floats between 0. and 1. (e.g: `(1., 1., 0.)` or
536-
`(1., 1., 0., 1.)`)
537-
* HTML-like string (e.g: `"#ffff00`)
538-
* a color name or shortcut (e.g: `"y"` or `"yellow"`)
539-
index : list of floats, default None
540-
The values corresponding to each color.
541-
Must be be sorted and its length must be equal to `len(colors)+1`.
542-
If None, a regular grid between `vmin` and `vmax` is created.
543-
vmin : float, default 0.
544-
The minimal value for the colormap.
545-
Values lower than `vmin` will be bound directly to `colors[0]`.
546-
vmax : float, default 1.
547-
The maximal value for the colormap.
548-
Values higher than `vmax` will be bound directly to `colors[-1]`.
549-
550-
"""
553+
"""
554+
def __init__(self, colors, index=None, vmin=0., vmax=1., caption=""):
551555
super(StepColormap, self).__init__(vmin=vmin, vmax=vmax,
552556
caption=caption)
553557

@@ -609,7 +613,6 @@ def scale(self, vmin=0., vmax=1.):
609613

610614
class _LinearColormaps(object):
611615
"""A class for hosting the list of built-in linear colormaps."""
612-
613616
def __init__(self):
614617
self._schemes = _schemes.copy()
615618
self._colormaps = {key: LinearColormap(val) for

folium/element.py

Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121

2222
class Element(object):
2323
"""Basic Element object that does nothing.
24-
Other Elements may inherit from this one."""
24+
Other Elements may inherit from this one.
25+
26+
Parameters
27+
----------
28+
TODO: docstring.
29+
"""
2530
def __init__(self, template=None, template_name=None):
26-
"""Creates a Element."""
2731
self._name = 'Element'
2832
self._id = uuid4().hex
2933
self._env = ENV
@@ -144,6 +148,8 @@ def save(self, outfile, close_file=True, **kwargs):
144148
class Link(Element):
145149
"""Link
146150
----
151+
152+
TODO: docstring.
147153
"""
148154
def get_code(self):
149155
"""TODO : docstring."""
@@ -159,16 +165,15 @@ def to_dict(self, depth=-1, **kwargs):
159165

160166

161167
class JavascriptLink(Link):
162-
"""TODO: docstring."""
168+
"""Create a JavascriptLink object based on a url.
169+
Parameters
170+
----------
171+
url : str
172+
The url to be linked
173+
download : bool, default False
174+
Whether the target document shall be loaded right now.
175+
"""
163176
def __init__(self, url, download=False):
164-
"""Create a JavascriptLink object based on a url.
165-
Parameters
166-
----------
167-
url : str
168-
The url to be linked
169-
download : bool, default False
170-
Whether the target document shall be loaded right now.
171-
"""
172177
super(JavascriptLink, self).__init__()
173178
self._name = 'JavascriptLink'
174179
self.url = url
@@ -186,16 +191,15 @@ def __init__(self, url, download=False):
186191

187192

188193
class CssLink(Link):
189-
"""TODO: docstring."""
194+
"""Create a CssLink object based on a url.
195+
Parameters
196+
----------
197+
url : str
198+
The url to be linked
199+
download : bool, default False
200+
Whether the target document shall be loaded right now.
201+
"""
190202
def __init__(self, url, download=False):
191-
"""Create a CssLink object based on a url.
192-
Parameters
193-
----------
194-
url : str
195-
The url to be linked
196-
download : bool, default False
197-
Whether the target document shall be loaded right now.
198-
"""
199203
super(CssLink, self).__init__()
200204
self._name = 'CssLink'
201205
self.url = url
@@ -247,27 +251,26 @@ def __init__(self, url, download=False):
247251

248252

249253
class Figure(Element):
250-
"""TODO: docstring."""
254+
"""Create a Figure object, to plot things into it.
255+
256+
Parameters
257+
----------
258+
width : str, default "100%"
259+
The width of the Figure.
260+
It may be a percentage or pixel value (like "300px").
261+
height : str, default None
262+
The height of the Figure.
263+
It may be a percentage or a pixel value (like "300px").
264+
ratio : str, default "60%"
265+
A percentage defining the aspect ratio of the Figure.
266+
It will be ignored if height is not None.
267+
figsize : tuple of two int, default None
268+
If you're a matplotlib addict, you can overwrite width and
269+
height. Values will be converted into pixels in using 60 dpi.
270+
For example figsize=(10, 5) will result in
271+
width="600px", height="300px".
272+
"""
251273
def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
252-
"""Create a Figure object, to plot things into it.
253-
254-
Parameters
255-
----------
256-
width : str, default "100%"
257-
The width of the Figure.
258-
It may be a percentage or pixel value (like "300px").
259-
height : str, default None
260-
The height of the Figure.
261-
It may be a percentage or a pixel value (like "300px").
262-
ratio : str, default "60%"
263-
A percentage defining the aspect ratio of the Figure.
264-
It will be ignored if height is not None.
265-
figsize : tuple of two int, default None
266-
If you're a matplotlib addict, you can overwrite width and
267-
height. Values will be converted into pixels in using 60 dpi.
268-
For example figsize=(10, 5) will result in
269-
width="600px", height="300px".
270-
"""
271274
super(Figure, self).__init__()
272275
self._name = 'Figure'
273276
self.header = Element()
@@ -398,21 +401,21 @@ def add_subplot(self, x, y, n, margin=0.05):
398401

399402

400403
class Html(Element):
401-
"""A basic Element for embedding HTML."""
402-
def __init__(self, data, width="100%", height="100%"):
403-
"""Create an HTML div object for embedding data.
404+
"""Create an HTML div object for embedding data.
405+
406+
Parameters
407+
----------
408+
data : str
409+
The HTML data to be embedded.
410+
width : int or str, default '100%'
411+
The width of the output div element.
412+
Ex: 120 , '120px', '80%'
413+
height : int or str, default '100%'
414+
The height of the output div element.
415+
Ex: 120 , '120px', '80%'
416+
"""
404417

405-
Parameters
406-
----------
407-
data : str
408-
The HTML data to be embedded.
409-
width : int or str, default '100%'
410-
The width of the output div element.
411-
Ex: 120 , '120px', '80%'
412-
height : int or str, default '100%'
413-
The height of the output div element.
414-
Ex: 120 , '120px', '80%'
415-
"""
418+
def __init__(self, data, width="100%", height="100%"):
416419
super(Html, self).__init__()
417420
self._name = 'Html'
418421
self.data = data
@@ -428,10 +431,14 @@ def __init__(self, data, width="100%", height="100%"):
428431

429432

430433
class Div(Figure):
431-
"""TODO: docstring."""
434+
"""Create a Map with Folium and Leaflet.js.
435+
436+
Parameters
437+
----------
438+
TODO: docstring.
439+
"""
432440
def __init__(self, width='100%', height='100%',
433441
left="0%", top="0%", position='relative'):
434-
"""Create a Map with Folium and Leaflet.js."""
435442
super(Figure, self).__init__()
436443
self._name = 'Div'
437444

@@ -517,30 +524,29 @@ def _repr_html_(self, **kwargs):
517524

518525

519526
class IFrame(Element):
520-
"""TODO: docstring."""
527+
"""Create a Figure object, to plot things into it.
528+
529+
Parameters
530+
----------
531+
html : str, default None
532+
Eventual HTML code that you want to put in the frame.
533+
width : str, default "100%"
534+
The width of the Figure.
535+
It may be a percentage or pixel value (like "300px").
536+
height : str, default None
537+
The height of the Figure.
538+
It may be a percentage or a pixel value (like "300px").
539+
ratio : str, default "60%"
540+
A percentage defining the aspect ratio of the Figure.
541+
It will be ignored if height is not None.
542+
figsize : tuple of two int, default None
543+
If you're a matplotlib addict, you can overwrite width and
544+
height. Values will be converted into pixels in using 60 dpi.
545+
For example figsize=(10, 5) will result in
546+
width="600px", height="300px".
547+
"""
521548
def __init__(self, html=None, width="100%", height=None, ratio="60%",
522549
figsize=None):
523-
"""Create a Figure object, to plot things into it.
524-
525-
Parameters
526-
----------
527-
html : str, default None
528-
Eventual HTML code that you want to put in the frame.
529-
width : str, default "100%"
530-
The width of the Figure.
531-
It may be a percentage or pixel value (like "300px").
532-
height : str, default None
533-
The height of the Figure.
534-
It may be a percentage or a pixel value (like "300px").
535-
ratio : str, default "60%"
536-
A percentage defining the aspect ratio of the Figure.
537-
It will be ignored if height is not None.
538-
figsize : tuple of two int, default None
539-
If you're a matplotlib addict, you can overwrite width and
540-
height. Values will be converted into pixels in using 60 dpi.
541-
For example figsize=(10, 5) will result in
542-
width="600px", height="300px".
543-
"""
544550
super(IFrame, self).__init__()
545551
self._name = 'IFrame'
546552

@@ -597,7 +603,6 @@ class MacroElement(Element):
597603
{% endmacro %}
598604
"""
599605
def __init__(self):
600-
"""Creates a MacroElement object."""
601606
super(MacroElement, self).__init__()
602607
self._name = 'MacroElement'
603608

0 commit comments

Comments
 (0)