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 branca/templates/color_scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.tickSize(1)
.tickValues({{ this.tick_labels }});

{{this.get_name()}}.svg = d3.select(".legend.leaflet-control").append("svg")
{{this.get_name()}}.svg = d3.select({{this.get_name()}}.legend.getContainer()).append("svg")
.attr("id", 'legend')
.attr("width", {{ this.width }})
.attr("height", {{ this.height }});
Expand Down
13 changes: 13 additions & 0 deletions tests/test_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

import branca.colormap as cm
from branca.element import Figure


def test_simple_step():
Expand Down Expand Up @@ -151,3 +152,15 @@ def test_max_labels_step(max_labels, expected):
except AssertionError: # rendering outside parent Figure raises error
pass
assert colorbar.tick_labels == expected


def test_each_legend_draws_into_its_own_control():
figure = Figure()
first = cm.LinearColormap(["red", "blue"]).add_to(figure)
second = cm.StepColormap(["red", "blue"]).add_to(figure)
out = figure.render()
# A global selector would put every legend into the first one on the page.
assert 'd3.select(".legend.leaflet-control")' not in out
for colormap in (first, second):
name = colormap.get_name()
assert f"d3.select({name}.legend.getContainer())" in out