diff --git a/CHANGES.txt b/CHANGES.txt index 4d220c1591..381cba5498 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,7 @@ - Added `zoom_control` to `Map` to toggle zoom controls as per enhancement (#795) (okomarov #899) - Change default `date_options` in TimestampedGeoJson (andy23512 #914) - Added gradient argument to HeatMapWithTime (jtbaker #925) +- Added `Tooltip` and `GeoJsonTooltip` classes (jtbaker #883) API changes diff --git a/folium/__init__.py b/folium/__init__.py index e03ff878c1..493b588218 100644 --- a/folium/__init__.py +++ b/folium/__init__.py @@ -11,6 +11,7 @@ from folium.features import ( ClickForMarker, ColorLine, CustomIcon, DivIcon, GeoJson, LatLngPopup, RegularPolygonMarker, TopoJson, Vega, VegaLite, + GeoJsonTooltip, ) from folium.raster_layers import TileLayer, WmsTileLayer @@ -18,7 +19,7 @@ from folium.folium import Map from folium.map import ( - FeatureGroup, FitBounds, Icon, LayerControl, Marker, Popup + FeatureGroup, FitBounds, Icon, LayerControl, Marker, Popup, Tooltip ) from folium.vector_layers import Circle, CircleMarker, PolyLine, Polygon, Rectangle # noqa @@ -52,6 +53,7 @@ 'LayerControl', 'Marker', 'Popup', + 'Tooltip', 'TileLayer', 'ClickForMarker', 'CustomIcon', diff --git a/folium/features.py b/folium/features.py index 2f9d900f7b..9cffef8b58 100644 --- a/folium/features.py +++ b/folium/features.py @@ -10,10 +10,12 @@ import json from branca.colormap import LinearColormap -from branca.element import (CssLink, Element, Figure, JavascriptLink, MacroElement) # noqa -from branca.utilities import (_locations_tolist, _parse_size, image_to_url, iter_points, none_max, none_min) # noqa +from branca.element import (Element, Figure, JavascriptLink, MacroElement) +from branca.utilities import (_locations_tolist, _parse_size, image_to_url, + none_max, none_min) + +from folium.map import (FeatureGroup, Icon, Layer, Marker, Tooltip) -from folium.map import FeatureGroup, Icon, Layer, Marker from folium.utilities import get_bounds from folium.vector_layers import PolyLine @@ -49,10 +51,9 @@ class RegularPolygonMarker(Marker): radius: int, default 15 Marker radius, in pixels popup: string or folium.Popup, default None - Input text or visualization for object. Can pass either text, - or a folium.Popup object. - If None, no popup will be displayed. - + Input text or visualization for object displayed when clicking. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. https://humangeo.github.io/leaflet-dvf/ @@ -72,17 +73,16 @@ class RegularPolygonMarker(Marker): rotation: {{this.rotation}}, radius: {{this.radius}} } - ) - .addTo({{this._parent.get_name()}}); + ).addTo({{this._parent.get_name()}}); {% endmacro %} """) def __init__(self, location, color='black', opacity=1, weight=2, - fill_color='blue', fill_opacity=1, - number_of_sides=4, rotation=0, radius=15, popup=None): + fill_color='blue', fill_opacity=1, number_of_sides=4, + rotation=0, radius=15, popup=None, tooltip=None): super(RegularPolygonMarker, self).__init__( _locations_tolist(location), - popup=popup + popup=popup, tooltip=tooltip ) self._name = 'RegularPolygonMarker' self.color = color @@ -325,6 +325,9 @@ class GeoJson(Layer): How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation. Leaflet defaults to 1.0. + tooltip: GeoJsonTooltip, Tooltip or str, default None + Display a text when hovering over the object. Can utilize the data, + see folium.GeoJsonTooltip for info on how to do that. Examples -------- @@ -345,44 +348,39 @@ class GeoJson(Layer): """ _template = Template(u""" - {% macro script(this, kwargs) %} - - {% if this.highlight %} - {{this.get_name()}}_onEachFeature = function onEachFeature(feature, layer) { - layer.on({ - mouseout: function(e) { - e.target.setStyle(e.target.feature.properties.style);}, - mouseover: function(e) { - e.target.setStyle(e.target.feature.properties.highlight);}, - click: function(e) { - {{this._parent.get_name()}}.fitBounds(e.target.getBounds());} - }); - }; - {% endif %} - - var {{this.get_name()}} = L.geoJson( - {% if this.embed %}{{this.style_data()}}{% else %}"{{this.data}}"{% endif %} - {% if this.smooth_factor is not none or this.highlight %} - , { - {% if this.smooth_factor is not none %} - smoothFactor:{{this.smooth_factor}} - {% endif %} - - {% if this.highlight %} - {% if this.smooth_factor is not none %} - , - {% endif %} - onEachFeature: {{this.get_name()}}_onEachFeature - {% endif %} - } + {% macro script(this, kwargs) %} + {% if this.highlight %} + {{this.get_name()}}_onEachFeature = function onEachFeature(feature, layer) { + layer.on({ + mouseout: function(e) { + e.target.setStyle(e.target.feature.properties.style);}, + mouseover: function(e) { + e.target.setStyle(e.target.feature.properties.highlight);}, + click: function(e) { + {{this._parent.get_name()}}.fitBounds(e.target.getBounds());} + }); + }; + {% endif %} + var {{this.get_name()}} = L.geoJson( + {% if this.embed %}{{this.style_data()}}{% else %}"{{this.data}}"{% endif %} + {% if this.smooth_factor is not none or this.highlight %} + , { + {% if this.smooth_factor is not none %} + smoothFactor:{{this.smooth_factor}} + {% endif %} + + {% if this.highlight %} + {% if this.smooth_factor is not none %} + , {% endif %} - ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} - .addTo({{this._parent.get_name()}}); - {{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;}); - - {% endmacro %} - """) # noqa + onEachFeature: {{this.get_name()}}_onEachFeature + {% endif %} + } + {% endif %} + ).addTo({{this._parent.get_name()}}); + {{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;}); + {% endmacro %} + """) # noqa def __init__(self, data, style_function=None, name=None, overlay=True, control=True, show=True, @@ -390,7 +388,6 @@ def __init__(self, data, style_function=None, name=None, super(GeoJson, self).__init__(name=name, overlay=overlay, control=control, show=show) self._name = 'GeoJson' - self.tooltip = tooltip if isinstance(data, dict): self.embed = True self.data = data @@ -410,7 +407,6 @@ def __init__(self, data, style_function=None, name=None, self.data = json.loads(json.dumps(data.__geo_interface__)) # noqa else: raise ValueError('Unhandled object {!r}.'.format(data)) - self.style_function = style_function or (lambda x: {}) self.highlight = highlight_function is not None @@ -419,6 +415,11 @@ def __init__(self, data, style_function=None, name=None, self.smooth_factor = smooth_factor + if isinstance(tooltip, (GeoJsonTooltip, Tooltip)): + self.add_child(tooltip) + elif tooltip is not None: + self.add_child(Tooltip(tooltip)) + def style_data(self): """ Applies `self.style_function` to each feature of `self.data` and @@ -476,6 +477,9 @@ class TopoJson(Layer): How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation. Leaflet defaults to 1.0. + tooltip: GeoJsonTooltip, Tooltip or str, default None + Display a text when hovering over the object. Can utilize the data, + see folium.GeoJsonTooltip for info on how to do that. Examples -------- @@ -496,21 +500,18 @@ class TopoJson(Layer): """ _template = Template(u""" - {% macro script(this, kwargs) %} - var {{this.get_name()}}_data = {{this.style_data()}}; - var {{this.get_name()}} = L.geoJson(topojson.feature( - {{this.get_name()}}_data, - {{this.get_name()}}_data.{{this.object_path}}) - {% if this.smooth_factor is not none %} - , {smoothFactor: {{this.smooth_factor}}} - {% endif %} - ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} - .addTo({{this._parent.get_name()}}); - {{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;}); - - {% endmacro %} - """) # noqa + {% macro script(this, kwargs) %} + var {{this.get_name()}}_data = {{this.style_data()}}; + var {{this.get_name()}} = L.geoJson(topojson.feature( + {{this.get_name()}}_data, + {{this.get_name()}}_data.{{this.object_path}}) + {% if this.smooth_factor is not none %} + , {smoothFactor: {{this.smooth_factor}}} + {% endif %} + ).addTo({{this._parent.get_name()}}); + {{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;}); + {% endmacro %} + """) # noqa def __init__(self, data, object_path, style_function=None, name=None, overlay=True, control=True, show=True, @@ -518,7 +519,7 @@ def __init__(self, data, object_path, style_function=None, super(TopoJson, self).__init__(name=name, overlay=overlay, control=control, show=show) self._name = 'TopoJson' - self.tooltip = tooltip + if 'read' in dir(data): self.embed = True self.data = json.load(data) @@ -538,6 +539,11 @@ def style_function(x): self.smooth_factor = smooth_factor + if isinstance(tooltip, (GeoJsonTooltip, Tooltip)): + self.add_child(tooltip) + elif tooltip is not None: + self.add_child(Tooltip(tooltip)) + def style_data(self): """ Applies self.style_function to each feature of self.data and returns @@ -595,10 +601,127 @@ def get_bounds(self): self.data['transform']['translate'][1] + self.data['transform']['scale'][1] * ymax, # noqa self.data['transform']['translate'][0] + self.data['transform']['scale'][0] * xmax # noqa ] - ] +class GeoJsonTooltip(Tooltip): + """ + Create a tooltip that uses data from either geojson or topojson. + + Parameters + ---------- + fields: list or tuple. + Labels of GeoJson/TopoJson 'properties' or GeoPandas GeoDataFrame + columns you'd like to display. + aliases: list/tuple of strings, same length/order as fields, default None. + Optional aliases you'd like to display in the tooltip as field name + instead of the keys of `fields`. + labels: bool, default True. + Set to False to disable displaying the field names or aliases. + localize: bool, default False. + This will use JavaScript's .toLocaleString() to format 'clean' values + as strings for the user's location; i.e. 1,000,000.00 comma separators, + float truncation, etc. + *Available for most of JavaScript's primitive types (any data you'll + serve into the template). + style: str, default None. + HTML inline style properties like font and colors. Will be applied to + a div with the text in it. + sticky: bool, default True + Whether the tooltip should follow the mouse. + **kwargs: Assorted. + These values will map directly to the Leaflet Options. More info + available here: https://leafletjs.com/reference-1.2.0#tooltip + + Examples + -------- + # Provide fields and aliases, with Style. + >>> Tooltip( + >>> fields=['CNTY_NM', 'census-pop-2015', 'census-md-income-2015'], + >>> aliases=['County', '2015 Census Population', '2015 Median Income'], + >>> localize=True, + >>> style=('background-color: grey; color: white; font-family:' + >>> 'courier new; font-size: 24px; padding: 10px;') + >>> ) + # Provide fields, with labels off and fixed tooltip positions. + >>> Tooltip(fields=('CNTY_NM',), labels=False, sticky=False) + """ + _template = Template(u""" + {% macro script(this, kwargs) %} + {{ this._parent.get_name() }}.bindTooltip( + function(layer){ + // Convert non-primitive to String. + let handleObject = (feature)=>typeof(feature)=='object' ? JSON.stringify(feature) : feature; + let fields = {{ this.fields }}; + {% if this.aliases %} + let aliases = {{ this.aliases }}; + {% endif %} + return '' + + String( + fields.map( + columnname=> + `{% if this.labels %} + {% if this.aliases %} + ${aliases[fields.indexOf(columnname)] + {% if this.localize %}.toLocaleString(){% endif %}} + {% else %} + ${ columnname{% if this.localize %}.toLocaleString(){% endif %}} + {% endif %} + {% endif %} + ${handleObject(layer.feature.properties[columnname]) + {% if this.localize %}.toLocaleString(){% endif %}}` + ).join('')) + +'' + }, {{ this.options }}); + {% endmacro %} + """) + + def __init__(self, fields, aliases=None, labels=True, + localize=False, style=None, sticky=True, **kwargs): + super(GeoJsonTooltip, self).__init__( + text='', style=style, sticky=sticky, **kwargs + ) + self._name = "GeoJsonTooltip" + + assert isinstance(fields, (list, tuple)), "Please pass a list or " \ + "tuple to fields." + if aliases is not None: + assert isinstance(aliases, (list, tuple)) + assert len(fields) == len(aliases), "fields and aliases must have" \ + " the same length." + assert isinstance(labels, bool), "labels requires a boolean value." + assert isinstance(localize, bool), "localize must be bool." + assert 'permanent' not in kwargs, "The `permanent` option does not " \ + "work with GeoJsonTooltip." + + self.fields = fields + self.aliases = aliases + self.labels = labels + self.localize = localize + if style: + assert isinstance(style, str), \ + "Pass a valid inline HTML style property string to style." + # noqa outside of type checking. + self.style = style + + def render(self, **kwargs): + """Renders the HTML representation of the element.""" + if isinstance(self._parent, GeoJson): + keys = tuple(self._parent.data['features'][0]['properties'].keys()) + elif isinstance(self._parent, TopoJson): + obj_name = self._parent.object_path.split('.')[-1] + keys = tuple(self._parent.data['objects'][obj_name][ + 'geometries'][0]['properties'].keys()) + else: + raise TypeError('You cannot add a GeoJsonTooltip to anything else ' + 'than a GeoJson or TopoJson object.') + keys = tuple(x for x in keys if x not in ('style', 'highlight')) + for value in self.fields: + assert value in keys, ("The field {} is not available in the data. " + "Choose from: {}.".format(value, keys)) + super(GeoJsonTooltip, self).render(**kwargs) + + class DivIcon(MacroElement): """ Represents a lightweight icon for markers that uses a simple `div` diff --git a/folium/map.py b/folium/map.py index c2fb726134..0c1c4e6fbd 100644 --- a/folium/map.py +++ b/folium/map.py @@ -13,7 +13,7 @@ from branca.element import CssLink, Element, Figure, Html, JavascriptLink, MacroElement # noqa -from folium.utilities import _validate_coordinates, get_bounds +from folium.utilities import _validate_coordinates, get_bounds, camelize from jinja2 import Template @@ -215,6 +215,8 @@ class Marker(MacroElement): popup: string or folium.Popup, default None Label for the Marker; either an escaped HTML string to initialize folium.Popup or a folium.Popup instance. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. icon: Icon plugin the Icon plugin to use to render the marker. @@ -228,21 +230,18 @@ class Marker(MacroElement): >>> Marker(location=[45.5, -122.3], popup=folium.Popup('Portland, OR')) # If the popup label has characters that need to be escaped in HTML >>> Marker(location=[45.5, -122.3], - popoup=folium.Popup('Mom & Pop Arrow Shop >>', parse_html=True)) + popup=folium.Popup('Mom & Pop Arrow Shop >>', parse_html=True)) """ _template = Template(u""" - {% macro script(this, kwargs) %} - - var {{this.get_name()}} = L.marker( - [{{this.location[0]}}, {{this.location[1]}}], - { - icon: new L.Icon.Default() - } - ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} - .addTo({{this._parent.get_name()}}); - {% endmacro %} - """) + {% macro script(this, kwargs) %} + var {{this.get_name()}} = L.marker( + [{{this.location[0]}}, {{this.location[1]}}], + { + icon: new L.Icon.Default() + } + ).addTo({{this._parent.get_name()}}); + {% endmacro %} + """) def __init__(self, location, popup=None, tooltip=None, icon=None): super(Marker, self).__init__() @@ -255,6 +254,10 @@ def __init__(self, location, popup=None, tooltip=None, icon=None): self.add_child(Popup(popup)) elif popup is not None: self.add_child(popup) + if isinstance(tooltip, Tooltip): + self.add_child(tooltip) + elif tooltip is not None: + self.add_child(Tooltip(tooltip.__str__())) def _get_self_bounds(self): """ @@ -299,7 +302,8 @@ class Popup(Element): {% endfor %} """) # noqa - def __init__(self, html=None, parse_html=False, max_width=300, show=False, sticky=False): + def __init__(self, html=None, parse_html=False, max_width=300, show=False, + sticky=False): super(Popup, self).__init__() self._name = 'Popup' self.header = Element() @@ -335,6 +339,76 @@ def render(self, **kwargs): name=self.get_name()) +class Tooltip(MacroElement): + """ + Create a tooltip that shows text when hovering over its parent object. + + Parameters + ---------- + text: str + String to display as a tooltip on the object. If the argument is of a + different type it will be converted to str. + style: str, default None. + HTML inline style properties like font and colors. Will be applied to + a div with the text in it. + sticky: bool, default True + Whether the tooltip should follow the mouse. + **kwargs: Assorted. + These values will map directly to the Leaflet Options. More info + available here: https://leafletjs.com/reference-1.2.0#tooltip + + """ + _template = Template(u""" + {% macro script(this, kwargs) %} + {{ this._parent.get_name() }}.bindTooltip( + '' + + '{{ this.text }}' + '', + {{ this.options }} + ); + {% endmacro %} + """) + valid_options = { + "pane": (str, ), + "offset": (tuple, ), + "direction": (str, ), + "permanent": (bool, ), + "sticky": (bool, ), + "interactive": (bool, ), + "opacity": (float, int), + "attribution": (str, ), + "className": (str, ), + } + + def __init__(self, text, style=None, sticky=True, **kwargs): + super(Tooltip, self).__init__() + self._name = "Tooltip" + + self.text = str(text) + + kwargs.update({'sticky': sticky}) + self.options = self.parse_options(kwargs) + + if style: + assert isinstance(style, str), \ + "Pass a valid inline HTML style property string to style." + # noqa outside of type checking. + self.style = style + + def parse_options(self, kwargs): + """Validate the provided kwargs and return options as json string.""" + kwargs = {camelize(key): value for key, value in kwargs.items()} + for key in kwargs.keys(): + assert key in self.valid_options, ( + "The option {} is not in the available options: {}." + .format(key, ', '.join(self.valid_options)) + ) + assert isinstance(kwargs[key], self.valid_options[key]), ( + "The option {} must be one of the following types: {}." + .format(key, self.valid_options[key]) + ) + return json.dumps(kwargs) + + class FitBounds(MacroElement): """Fit the map to contain a bounding box with the maximum zoom level possible. diff --git a/folium/utilities.py b/folium/utilities.py index 013dd6f286..f829182789 100644 --- a/folium/utilities.py +++ b/folium/utilities.py @@ -342,3 +342,17 @@ def get_bounds(locations, lonlat=False): if lonlat: bounds = _locations_mirror(bounds) return bounds + + +def camelize(key): + """Convert a python_style_variable_name to lowerCamelCase. + + Examples + -------- + >>> camelize('variable_name') + 'variableName' + >>> camelize('variableName') + 'variableName' + """ + return ''.join(x.capitalize() if i > 0 else x + for i, x in enumerate(key.split('_'))) diff --git a/folium/vector_layers.py b/folium/vector_layers.py index 70322e9de6..b0b5383cd5 100644 --- a/folium/vector_layers.py +++ b/folium/vector_layers.py @@ -140,8 +140,8 @@ class PolyLine(Marker): Latitude and Longitude of line (Northing, Easting) popup: str or folium.Popup, default None Input text or visualization for object displayed when clicking. - tooltip: str, default None - Input text or visualization for object displayed when hovering. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. smooth_factor: float, default 1.0 How much to simplify the polyline on each zoom level. More means better performance and smoother look, @@ -159,16 +159,14 @@ class PolyLine(Marker): {{this.location}}, {{ this.options }} ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} .addTo({{this._parent.get_name()}}); {% endmacro %} """) # noqa def __init__(self, locations, popup=None, tooltip=None, **kwargs): - super(PolyLine, self).__init__(location=locations, popup=popup) + super(PolyLine, self).__init__(location=locations, popup=popup, + tooltip=tooltip) self._name = 'PolyLine' - self.tooltip = tooltip - self.options = _parse_options(line=True, **kwargs) @@ -186,8 +184,8 @@ class Polygon(Marker): Latitude and Longitude of line (Northing, Easting) popup: string or folium.Popup, default None Input text or visualization for object displayed when clicking. - tooltip: string , default None - Input text or visualization for object displayed when hovering. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. http://leafletjs.com/reference-1.2.0.html#polygon @@ -200,16 +198,13 @@ class Polygon(Marker): {{this.location}}, {{ this.options }} ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} .addTo({{this._parent.get_name()}}); {% endmacro %} """) def __init__(self, locations, popup=None, tooltip=None, **kwargs): - super(Polygon, self).__init__(locations, popup=popup) + super(Polygon, self).__init__(locations, popup=popup, tooltip=tooltip) self._name = 'Polygon' - self.tooltip = tooltip - self.options = _parse_options(line=True, **kwargs) @@ -227,8 +222,8 @@ class Rectangle(Marker): Latitude and Longitude of line (Northing, Easting) popup: string or folium.Popup, default None Input text or visualization for object displayed when clicking. - tooltip: string , default None - Input text or visualization for object displayed when hovering. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. http://leafletjs.com/reference-1.2.0.html#rectangle @@ -241,16 +236,14 @@ class Rectangle(Marker): {{this.location}}, {{ this.options }} ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} .addTo({{this._parent.get_name()}}); {% endmacro %} """) def __init__(self, bounds, popup=None, tooltip=None, **kwargs): - super(Rectangle, self).__init__(location=bounds, popup=popup) + super(Rectangle, self).__init__(location=bounds, popup=popup, + tooltip=tooltip) self._name = 'rectangle' - self.tooltip = tooltip - self.options = _parse_options(line=True, **kwargs) @@ -271,8 +264,8 @@ class Circle(Marker): Latitude and Longitude of line (Northing, Easting) popup: string or folium.Popup, default None Input text or visualization for object displayed when clicking. - tooltip: string , default None - Input text or visualization for object displayed when hovering. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. radius: float Radius of the circle, in meters. @@ -287,16 +280,14 @@ class Circle(Marker): [{{this.location[0]}}, {{this.location[1]}}], {{ this.options }} ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} .addTo({{this._parent.get_name()}}); {% endmacro %} """) def __init__(self, location, radius, popup=None, tooltip=None, **kwargs): - super(Circle, self).__init__(location=location, popup=popup) + super(Circle, self).__init__(location=location, popup=popup, + tooltip=tooltip) self._name = 'circle' - self.tooltip = tooltip - self.options = _parse_options(line=False, radius=radius, **kwargs) @@ -312,8 +303,8 @@ class CircleMarker(Marker): Latitude and Longitude of line (Northing, Easting) popup: string or folium.Popup, default None Input text or visualization for object displayed when clicking. - tooltip: string , default None - Input text or visualization for object displayed when hovering. + tooltip: str or folium.Tooltip, default None + Display a text when hovering over the object. radius: float, default 10 Radius of the circle marker, in pixels. @@ -327,14 +318,12 @@ class CircleMarker(Marker): [{{this.location[0]}}, {{this.location[1]}}], {{ this.options }} ) - {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %} .addTo({{this._parent.get_name()}}); {% endmacro %} """) def __init__(self, location, radius=10, popup=None, tooltip=None, **kwargs): - super(CircleMarker, self).__init__(location=location, popup=popup) + super(CircleMarker, self).__init__(location=location, popup=popup, + tooltip=tooltip) self._name = 'CircleMarker' - self.tooltip = tooltip - self.options = _parse_options(line=False, radius=radius, **kwargs) diff --git a/tests/test_utilities.py b/tests/test_utilities.py new file mode 100644 index 0000000000..a481b7ee8b --- /dev/null +++ b/tests/test_utilities.py @@ -0,0 +1,10 @@ +from __future__ import (absolute_import, division, print_function) + +from folium.utilities import camelize + + +def test_camelize(): + assert camelize('variable_name') == 'variableName' + assert camelize('variableName') == 'variableName' + assert camelize('name') == 'name' + assert camelize('very_long_variable_name') == 'veryLongVariableName'