Skip to content
Open
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
2 changes: 1 addition & 1 deletion folium/plugins/time_slider_choropleth.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):

$("#slider_{{ this.get_name() }}").show();

d3.selectAll('path')
d3.selectAll('path[id^="{{ this.get_name() }}-feature-"]')
.attr('stroke', '{{ this.stroke_color }}')
.attr('stroke-width', {{ this.stroke_width }})
.attr('stroke-dasharray', '5,5')
Expand Down
31 changes: 31 additions & 0 deletions tests/plugins/test_time_slider_choropleth.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,34 @@ def test_slider_overlays_map():
rendered = plugin._template.module.script(plugin)

assert '.style("position", "absolute")' in rendered


def test_stroke_style_only_targets_own_features():
# the stroke and fill reset must not restyle paths of other layers
geojson = json.dumps(
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "0",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
},
}
],
}
)
styledict = {"0": {"1420070400": {"color": "#ff0000", "opacity": 0.5}}}

m = folium.Map((0, 0), zoom_start=2)
folium.GeoJson(geojson, name="other").add_to(m)
plugin = TimeSliderChoropleth(geojson, styledict)
plugin.add_to(m)
rendered = plugin._template.module.script(plugin)

assert "d3.selectAll('path')" not in rendered
selector = f"d3.selectAll('path[id^=\"{plugin.get_name()}-feature-\"]')"
assert selector in rendered