Skip to content

Commit

Permalink
fix: resolve pre-commit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
swtormy committed Nov 18, 2024
1 parent bcd5948 commit 9b9de5e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
1 change: 0 additions & 1 deletion docs/user_guide/plugins/overlapping_marker_spiderfier.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ oms.add_to(m)
m
```

21 changes: 11 additions & 10 deletions folium/plugins/overlapping_marker_spiderfier.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from jinja2 import Template

from folium.elements import JSCSSMixin, MacroElement
from folium.utilities import parse_options


class OverlappingMarkerSpiderfier(JSCSSMixin, MacroElement):
"""
A plugin that handles overlapping markers on a map by spreading them out in a spiral or circle pattern when clicked.
This plugin is useful when you have multiple markers in close proximity that would otherwise be difficult to interact with.
When a user clicks on a cluster of overlapping markers, they spread out in a 'spider' pattern, making each marker
When a user clicks on a cluster of overlapping markers, they spread out in a 'spider' pattern, making each marker
individually accessible.
Markers must be added to the map **before** calling `oms.add_to(map)`.
Markers must be added to the map **before** calling `oms.add_to(map)`.
The plugin identifies and manages all markers already present on the map.
Parameters
----------
options : dict, optional
Expand All @@ -25,16 +27,15 @@ class OverlappingMarkerSpiderfier(JSCSSMixin, MacroElement):
Weight of the spider legs
- circleSpiralSwitchover : int, optional
Number of markers at which to switch from circle to spiral pattern
Example
-------
>>> oms = OverlappingMarkerSpiderfier(options={
... "keepSpiderfied": True,
... "nearbyDistance": 30,
... "legWeight": 2.0
... })
>>> oms = OverlappingMarkerSpiderfier(
... options={"keepSpiderfied": True, "nearbyDistance": 30, "legWeight": 2.0}
... )
>>> oms.add_to(map)
"""

_template = Template(
"""
{% macro script(this, kwargs) %}
Expand Down
53 changes: 37 additions & 16 deletions tests/plugins/test_overlapping_marker_spiderfier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_oms_js_inclusion():
Test that the OverlappingMarkerSpiderfier JavaScript library is included in the map.
"""
m = Map([45.05, 3.05], zoom_start=14)
oms = OverlappingMarkerSpiderfier().add_to(m)
OverlappingMarkerSpiderfier().add_to(m)

rendered_map = m._parent.render()
assert (
Expand All @@ -38,16 +38,22 @@ def test_marker_addition():
).T

m = Map([45.05, 3.05], zoom_start=14)
markers = [Marker(location=loc, popup=f"Marker {
i}") for i, loc in enumerate(data)]
markers = [
Marker(
location=loc,
popup=f"Marker {
i}",
)
for i, loc in enumerate(data)
]

for marker in markers:
marker.add_to(m)

assert len(m._children) == len(markers) + 1, (
f"Expected {len(markers)} markers on the map, but found {
assert (
len(m._children) == len(markers) + 1
), f"Expected {len(markers)} markers on the map, but found {
len(m._children) - 1}."
)


def test_map_bounds():
Expand All @@ -64,8 +70,14 @@ def test_map_bounds():
).T

m = Map([45.05, 3.05], zoom_start=14)
markers = [Marker(location=loc, popup=f"Marker {
i}") for i, loc in enumerate(data)]
markers = [
Marker(
location=loc,
popup=f"Marker {
i}",
)
for i, loc in enumerate(data)
]

for marker in markers:
marker.add_to(m)
Expand All @@ -76,10 +88,18 @@ def test_map_bounds():
min_lat, min_lon = data.min(axis=0)
max_lat, max_lon = data.max(axis=0)

assert bounds[0][0] <= min_lat, "Map bounds do not correctly include the minimum latitude."
assert bounds[0][1] <= min_lon, "Map bounds do not correctly include the minimum longitude."
assert bounds[1][0] >= max_lat, "Map bounds do not correctly include the maximum latitude."
assert bounds[1][1] >= max_lon, "Map bounds do not correctly include the maximum longitude."
assert (
bounds[0][0] <= min_lat
), "Map bounds do not correctly include the minimum latitude."
assert (
bounds[0][1] <= min_lon
), "Map bounds do not correctly include the minimum longitude."
assert (
bounds[1][0] >= max_lat
), "Map bounds do not correctly include the maximum latitude."
assert (
bounds[1][1] >= max_lon
), "Map bounds do not correctly include the maximum longitude."


def test_overlapping_marker_spiderfier_integration():
Expand All @@ -88,9 +108,10 @@ def test_overlapping_marker_spiderfier_integration():
"""
m = Map([45.05, 3.05], zoom_start=14)
oms = OverlappingMarkerSpiderfier(
options={"keepSpiderfied": True, "nearbyDistance": 20})
options={"keepSpiderfied": True, "nearbyDistance": 20}
)
oms.add_to(m)

assert oms.get_name() in m._children, (
f"OverlappingMarkerSpiderfier is not correctly added to the map."
)
assert (
oms.get_name() in m._children
), "OverlappingMarkerSpiderfier is not correctly added to the map."

0 comments on commit 9b9de5e

Please sign in to comment.