From a081ad9be1db286b31e11d70b26c1199c2f96ea0 Mon Sep 17 00:00:00 2001 From: swtormy Date: Mon, 18 Nov 2024 10:27:23 +0300 Subject: [PATCH] fix: resolve pre-commit issues --- .../plugins/overlapping_marker_spiderfier.py | 21 ++++---- .../test_overlapping_marker_spiderfier.py | 53 +++++++++++++------ 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/folium/plugins/overlapping_marker_spiderfier.py b/folium/plugins/overlapping_marker_spiderfier.py index b3c5bbda5..b0aa26077 100644 --- a/folium/plugins/overlapping_marker_spiderfier.py +++ b/folium/plugins/overlapping_marker_spiderfier.py @@ -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 @@ -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) %} diff --git a/tests/plugins/test_overlapping_marker_spiderfier.py b/tests/plugins/test_overlapping_marker_spiderfier.py index 87186f647..67df9fe06 100644 --- a/tests/plugins/test_overlapping_marker_spiderfier.py +++ b/tests/plugins/test_overlapping_marker_spiderfier.py @@ -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 ( @@ -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(): @@ -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) @@ -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(): @@ -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."