Skip to content

Commit 7de77c1

Browse files
committed
overlay the time slider so it stops hiding the attribution
the slider was inserted as a block sibling of the map, so with the map at 100% height the page overflowed and the attribution got clipped. position it absolutely over the map instead. fixes #1301
1 parent e17b64c commit 7de77c1

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

folium/plugins/time_slider_choropleth.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
5050
}
5151
5252
let slider_body = d3.select("body").insert("div", "div.folium-map")
53-
.attr("id", "slider_{{ this.get_name() }}");
53+
.attr("id", "slider_{{ this.get_name() }}")
54+
// overlay the slider on the map so it doesn't push the map
55+
// (and its attribution) out of view
56+
.style("position", "absolute")
57+
.style("top", "10px")
58+
.style("left", "50%")
59+
.style("transform", "translateX(-50%)")
60+
.style("z-index", "999")
61+
.style("background", "rgba(255, 255, 255, 0.8)")
62+
.style("border-radius", "4px")
63+
.style("padding", "2px 8px");
5464
$("#slider_{{ this.get_name() }}").hide();
5565
// insert time slider label
5666
slider_body.append("output")

tests/plugins/test_time_slider_choropleth.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,32 @@ def norm(col):
9191

9292
expected_styledict = normalize(json.dumps(styledict, sort_keys=True))
9393
assert expected_styledict in normalize(rendered)
94+
95+
96+
def test_slider_overlays_map():
97+
# the slider must not push the map (and its attribution) out of view,
98+
# so it is positioned as an overlay instead of a block element
99+
geojson = json.dumps(
100+
{
101+
"type": "FeatureCollection",
102+
"features": [
103+
{
104+
"type": "Feature",
105+
"id": "0",
106+
"properties": {},
107+
"geometry": {
108+
"type": "Polygon",
109+
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
110+
},
111+
}
112+
],
113+
}
114+
)
115+
styledict = {"0": {"1420070400": {"color": "#ff0000", "opacity": 0.5}}}
116+
117+
m = folium.Map((0, 0), zoom_start=2)
118+
plugin = TimeSliderChoropleth(geojson, styledict)
119+
plugin.add_to(m)
120+
rendered = plugin._template.module.script(plugin)
121+
122+
assert '.style("position", "absolute")' in rendered

0 commit comments

Comments
 (0)