Skip to content

Finished pep8ing #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions folium/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import

__version__ = '0.2.0.dev'

from folium.folium import Map, initialize_notebook, CircleMarker

from folium.map import FeatureGroup, FitBounds,Icon, LayerControl, Marker, Popup, TileLayer
from folium.map import (FeatureGroup, FitBounds, Icon, LayerControl, Marker,
Popup, TileLayer)

from folium.features import (ClickForMarker, ColorScale, CustomIcon, DivIcon,
GeoJson, GeoJsonStyle, ImageOverlay, LatLngPopup,
MarkerCluster, MultiPolyLine, PolyLine, Vega,
RegularPolygonMarker, TopoJson, WmsTileLayer)

from folium.features import (ClickForMarker, ColorScale, CustomIcon, DivIcon, GeoJson, GeoJsonStyle,
ImageOverlay, LatLngPopup, MarkerCluster, MultiPolyLine, PolyLine,
RegularPolygonMarker, TopoJson, Vega, WmsTileLayer)
__all__ = ['Map',
'initialize_notebook',
'CircleMarker',
'FeatureGroup',
'FitBounds',
'Icon',
'LayerControl',
'Marker',
'Popup',
'TileLayer',
'ClickForMarker',
'ColorScale',
'CustomIcon',
'DivIcon',
'GeoJson',
'GeoJsonStyle',
'ImageOverlay',
'LatLngPopup',
'MarkerCluster',
'MultiPolyLine',
'PolyLine',
'Vega',
'RegularPolygonMarker',
'TopoJson',
'WmsTileLayer']
52 changes: 27 additions & 25 deletions folium/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def to_dict(self, depth=-1, ordered=True, **kwargs):
out['id'] = self._id
if depth != 0:
out['children'] = dict_fun([(name, child.to_dict(depth=depth-1))
for name, child in self._children.items()])
for name, child in self._children.items()]) # noqa
return out

def to_json(self, depth=-1, **kwargs):
Expand Down Expand Up @@ -177,11 +177,11 @@ def __init__(self, url, download=False):
('bootstrap',
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"),
('awesome_markers',
"https://rawi.8713187.xyz/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"),
"https://rawi.8713187.xyz/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"), # noqa
('marker_cluster_src',
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"),
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"), # noqa
('marker_cluster',
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"),
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"), # noqa
]

_default_css = [
Expand All @@ -190,17 +190,17 @@ def __init__(self, url, download=False):
("bootstrap_css",
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"),
("bootstrap_theme_css",
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"),
"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"), # noqa
("awesome_markers_font_css",
"https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"),
"https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"), # noqa
("awesome_markers_css",
"https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css"),
"https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css"), # noqa
("marker_cluster_default_css",
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"),
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"), # noqa
("marker_cluster_css",
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"),
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"), # noqa
("awesome_rotate_css",
"https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css"),
"https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css"), # noqa
]


Expand All @@ -211,16 +211,19 @@ def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
Parameters
----------
width : str, default "100%"
The width of the Figure. It may be a percentage or a distance (like "300px").
The width of the Figure.
It may be a percentage or pixel value (like "300px").
height : str, default None
The height of the Figure. It may be a percentage or a distance (like "300px").
The height of the Figure.
It may be a percentage or a pixel value (like "300px").
ratio : str, default "60%"
A percentage defining the aspect ratio of the Figure.
It will be ignored if height is not None.
figsize : tuple of two int, default None
If you're a matplotlib addict, you can overwrite width and height.
Values will be converted into pixels in using 60 dpi.
For example figsize=(10,5) will result in width="600px", height="300px".
If you're a matplotlib addict, you can overwrite width and
height. Values will be converted into pixels in using 60 dpi.
For example figsize=(10, 5) will result in
width="600px", height="300px".
"""
super(Figure, self).__init__()
self._name = 'Figure'
Expand Down Expand Up @@ -252,9 +255,9 @@ def __init__(self, width="100%", height=None, ratio="60%", figsize=None):
</script>
""")

# Create the meta tag
# Create the meta tag.
self.header.add_children(Element(
'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'),
'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'), # noqa
name='meta_http')

# Import Javascripts
Expand Down Expand Up @@ -305,19 +308,18 @@ def _repr_html_(self, **kwargs):
----------
"""
html = self.render(**kwargs)
html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8')
html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8') # noqa

if self.height is None:
iframe = """
iframe = ("""
<div style="width:{width};">
<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">
<iframe src="{html}" style="position:absolute;width:100%;height:100%;left:0;top:0;">
</iframe>
</div></div>""".format(
html=html,
width=self.width,
ratio=self.ratio,
)
</div></div>""") # noqa
iframe.format(html=html,
width=self.width,
ratio=self.ratio)
else:
iframe = ('<iframe src="{html}" width="{width}" '
'height="{height}"></iframe>').format
Expand Down Expand Up @@ -359,7 +361,7 @@ def __init__(self, data, width="100%", height="100%"):
<div id="{{this.get_name()}}"
style="width: {{this.width[0]}}{{this.width[1]}}; height: {{this.height[0]}}{{this.height[1]}};">
{{this.data|e}}</div>
""")
""") # noqa


class Div(Figure):
Expand Down
59 changes: 32 additions & 27 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, url, name=None,
).addTo({{this._parent.get_name()}});

{% endmacro %}
""")
""") # noqa


class RegularPolygonMarker(MacroElement):
Expand Down Expand Up @@ -99,7 +99,7 @@ def render(self, **kwargs):
"if it's not in a Figure.")

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.2/leaflet-dvf.markers.min.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.2/leaflet-dvf.markers.min.js"), # noqa
name='dvf_js')


Expand Down Expand Up @@ -145,11 +145,11 @@ def render(self, **kwargs):
""").render(this=self, **kwargs)), name=self.get_name())

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
name='d3')

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js"), # noqa
name='vega')

figure.header.add_children(
Expand All @@ -158,7 +158,7 @@ def render(self, **kwargs):

figure.script.add_children(
Template("""function vega_parse(spec, div) {
vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}"""),
vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}"""), # noqa
name='vega_parse')


Expand All @@ -171,7 +171,7 @@ def __init__(self, data):
----------
data: file, dict or str.
The geo-json data you want to plot.
If file, then data will be read in the file and fully embedded in Leaflet's javascript.
If file, then data will be read in the file and fully embedded in Leaflet's javascript. # noqa
If dict, then data will be converted to JSON and embedded in the javascript.
If str, then data will be passed to the javascript as-is.

Expand All @@ -196,7 +196,7 @@ def __init__(self, data):

self._template = Template(u"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = L.geoJson({{this.data}}).addTo({{this._parent.get_name()}});
var {{this.get_name()}} = L.geoJson({{this.data}}).addTo({{this._parent.get_name()}}); # noqa
{% endmacro %}
""")

Expand Down Expand Up @@ -234,7 +234,7 @@ def render(self, **kwargs):
"if it's not in a Figure.")

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"), # noqa
name='topojson')


Expand Down Expand Up @@ -306,7 +306,7 @@ def render(self, **kwargs):
"if it's not in a Figure.")

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
name='d3')


Expand Down Expand Up @@ -334,7 +334,7 @@ def render(self, **kwargs):
"if it's not in a Figure.")

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), # noqa
name='d3')


Expand Down Expand Up @@ -363,19 +363,19 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ("You cannot render this Element "
"if it's not in a Figure.")
figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"), # noqa
name='marker_cluster_src')

figure.header.add_children(
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"),
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"), # noqa
name='marker_cluster')

figure.header.add_children(
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"),
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"), # noqa
name='marker_cluster_css')

figure.header.add_children(
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"),
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"), # noqa
name="marker_cluster_default_css")


Expand Down Expand Up @@ -449,7 +449,7 @@ def __init__(self):
}
{{this._parent.get_name()}}.on('click', latLngPop);
{% endmacro %}
""")
""") # noqa


class ClickForMarker(MacroElement):
Expand All @@ -476,7 +476,7 @@ def __init__(self, popup=None):
};
{{this._parent.get_name()}}.on('click', newMarker);
{% endmacro %}
""")
""") # noqa


class PolyLine(MacroElement):
Expand Down Expand Up @@ -517,7 +517,7 @@ def __init__(self, locations, color=None, weight=None,
});
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
{% endmacro %}
""")
""") # noqa


class MultiPolyLine(MacroElement):
Expand Down Expand Up @@ -558,7 +558,7 @@ def __init__(self, locations, color=None, weight=None,
});
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
{% endmacro %}
""")
""") # noqa


class ImageOverlay(MacroElement):
Expand All @@ -572,10 +572,13 @@ def __init__(self, image, bounds, opacity=1., attribution=None,
image: string, file or array-like object
The data you want to draw on the map.
* If string, it will be written directly in the output file.
* If file, it's content will be converted as embedded in the output file.
* If array-like, it will be converted to PNG base64 string and embedded in the output.
* If file, it's content will be converted as embedded in the
output file.
* If array-like, it will be converted to PNG base64 string and
embedded in the output.
bounds: list
Image bounds on the map in the form [[lat_min, lon_min], [lat_max, lon_max]]
Image bounds on the map in the form
[[lat_min, lon_min], [lat_max, lon_max]]
opacity: float, default Leaflet's default (1.0)
attr: string, default Leaflet's default ("")
origin : ['upper' | 'lower'], optional, default 'upper'
Expand All @@ -584,9 +587,9 @@ def __init__(self, image, bounds, opacity=1., attribution=None,
colormap : callable, used only for `mono` image.
Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)]
for transforming a mono image into RGB.
It must output iterables of length 3 or 4, with values between 0. and 1.
Hint : you can use colormaps from `matplotlib.cm`.
mercator_project : bool, default False, used only for array-like image.
It must output iterables of length 3 or 4, with values between
0. and 1. Hint : you can use colormaps from `matplotlib.cm`.
mercator_project : bool, default False, used for array-like image.
Transforms the data to project (longitude, latitude)
coordinates to the Mercator projection.
"""
Expand Down Expand Up @@ -627,8 +630,10 @@ def __init__(self, icon_image, icon_size=None, icon_anchor=None,
icon_image : string, file or array-like object
The data you want to use as an icon.
* If string, it will be written directly in the output file.
* If file, it's content will be converted as embedded in the output file.
* If array-like, it will be converted to PNG base64 string and embedded in the output.
* If file, it's content will be converted as embedded in the
output file.
* If array-like, it will be converted to PNG base64 string and
embedded in the output.
icon_size : tuple of 2 int
Size of the icon image in pixels.
icon_anchor : tuple of 2 int
Expand Down Expand Up @@ -676,4 +681,4 @@ def __init__(self, icon_image, icon_size=None, icon_anchor=None,
});
{{this._parent.get_name()}}.setIcon({{this.get_name()}});
{% endmacro %}
""")
""") # noqa
4 changes: 2 additions & 2 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
colormap : callable, used only for `mono` image.
Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)]
for transforming a mono image into RGB.
It must output iterables of length 3 or 4, with values between 0. and 1.
Hint : you can use colormaps from `matplotlib.cm`.
It must output iterables of length 3 or 4, with values between
0. and 1. Hint : you can use colormaps from `matplotlib.cm`.

mercator_project : bool, default False, used only for array-like image.
Transforms the data to project (longitude,latitude) coordinates
Expand Down
5 changes: 3 additions & 2 deletions folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ def __init__(self, name=None, overlay=True):
Parameters
----------
name : str, default None
The name of the featureGroup layer. It will be displayed in the LayerControl.
If None, get_name() will be called to get the object's technical (ugly) name.
The name of the featureGroup layer.
It will be displayed in the LayerControl.
If None get_name() will be called to get the technical (ugly) name.
overlay : bool, default True
Whether your layer will be an overlay (ticked with a check box in
LayerControls) or a base layer (ticked with a radio button).
Expand Down
Loading