Skip to content

Commit 65eeb9b

Browse files
committed
Follow up of #979, correcting our LegendControl docs where needed.
I left in a backwards-compatible shim for giving the name argument to the LegendControl.
1 parent 8c101e6 commit 65eeb9b

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

docs/source/controls/legend_control.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Example
1010

1111
m = Map(center=(-10,-45), zoom=4)
1212

13-
legend = LegendControl({"low":"#FAA", "medium":"#A55", "High":"#500"}, name="Legend", position="bottomright")
13+
legend = LegendControl({"low":"#FAA", "medium":"#A55", "High":"#500"}, title="Legend", position="bottomright")
1414
m.add(legend)
1515

1616
m
@@ -20,12 +20,12 @@ Example
2020
# Manipulate the legend
2121

2222
# Set/Get legend title
23-
legend.name = "Risk" # Set name
24-
legend.name # Get name
23+
legend.title = "Risk" # Set title
24+
legend.title # Get title
2525

2626
# Set/Get legend content
27-
legend.legends = {"el1":"#FAA", "el2":"#A55", "el3":"#500"} # Set content
28-
legend.legends # Get content
27+
legend.legend = {"el1":"#FAA", "el2":"#A55", "el3":"#500"} # Set content
28+
legend.legend # Get content
2929

3030
legend.add_legend_element("el5","#000") # Add a legend element
3131
legend.remove_legend_element("el5") # Remove a legend element

examples/LegendControl.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"cell_type": "markdown",
5555
"metadata": {},
5656
"source": [
57-
"By default, you need to provide at least a dictionary with pair key=> the label to display and value=> the desired color. By default, it is named 'Legend', but you can pass a name as argument as well."
57+
"By default, you need to provide at least a dictionary with pair key=> the label to display and value=> the desired color. By default, it is titled 'Legend', but you can pass a title as argument as well."
5858
]
5959
},
6060
{
@@ -65,7 +65,7 @@
6565
"source": [
6666
"a_legend = LegendControl(\n",
6767
" {\"low\": \"#FAA\", \"medium\": \"#A55\", \"High\": \"#500\"},\n",
68-
" name=\"Legend\",\n",
68+
" title=\"Legend\",\n",
6969
" position=\"bottomright\",\n",
7070
")"
7171
]
@@ -90,7 +90,7 @@
9090
"cell_type": "markdown",
9191
"metadata": {},
9292
"source": [
93-
"### Name"
93+
"### Title"
9494
]
9595
},
9696
{
@@ -99,8 +99,8 @@
9999
"metadata": {},
100100
"outputs": [],
101101
"source": [
102-
"a_legend.name = \"Risk\" ## set name\n",
103-
"a_legend.name # get name"
102+
"a_legend.title = \"Risk\" ## set title\n",
103+
"a_legend.title # get title"
104104
]
105105
},
106106
{

ipyleaflet/leaflet.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,10 +1932,13 @@ class LegendControl(Control):
19321932
"value 2": "#55A",
19331933
"value 3": "#005"}).tag(sync=True)
19341934

1935-
def __init__(self, legend, *args, name="Legend", **kwargs):
1935+
def __init__(self, legend, *args, **kwargs):
1936+
kwargs["legend"] = legend
1937+
# For backwards compatibility with ipyleaflet<=0.16.0
1938+
if 'name' in kwargs:
1939+
kwargs.setdefault('title', kwargs['name'])
1940+
del kwargs['name']
19361941
super().__init__(*args, **kwargs)
1937-
self.title = name
1938-
self.legend = legend
19391942

19401943
def add_legend_element(self, key, value):
19411944
"""Add a new legend element.

0 commit comments

Comments
 (0)