Skip to content

Commit 855a8dd

Browse files
authored
Merge pull request #1005 from jasongrout/legend
Add deprecation warnings for API changes
2 parents 28cc971 + 850a4c3 commit 855a8dd

File tree

6 files changed

+120
-29
lines changed

6 files changed

+120
-29
lines changed

CHANGELOG.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
## v0.17.0
2+
3+
Here are some highlights of changes in this version. See the full list of changes for more details: https://github.com/jupyter-widgets/ipyleaflet/compare/0.16.0...0.17.0
4+
25
### New Features
36

47
* Make it possible to use Choropleth layer with data containing NaNs [#972](https://github.com/jupyter-widgets/ipyleaflet/pull/972)
58
* Add Map panes [#999](https://github.com/jupyter-widgets/ipyleaflet/pull/999)
69
* Allow setting Map.dragging [#1001](https://github.com/jupyter-widgets/ipyleaflet/pull/1001)
710
* Add visible attribute to GeoJSON layer [#1002](https://github.com/jupyter-widgets/ipyleaflet/pull/1002)
8-
* [BREAKING CHANGE] Remove get and set decorators in LegendControl [#979](https://github.com/jupyter-widgets/ipyleaflet/pull/979)
911

10-
## Maintenance
12+
### Deprecated API
13+
14+
* Deprecate LegendControl properties `name`, `legends`, `positioning`, and `positionning` [#979](https://github.com/jupyter-widgets/ipyleaflet/pull/979) and [#1005](https://github.com/jupyter-widgets/ipyleaflet/pull/1005). Update your code with the following substitutions for a LegendControl `legend`:
15+
* `legend.name` -> `legend.title`
16+
* `legend.legends` -> `legend.legend`
17+
* `legend.positioning` -> `legend.position`
18+
* `legend.positionnning` -> `legend.position`
19+
20+
The `name` argument in creating a LegendControl is also deprecated, please use the `title` argument instead: `LegendControl({}, title='My Title')`.
21+
* Deprecate layer and control-specific method names for Map and LayerGroup, in favor of methods that work for both layers and controls [#982](https://github.com/jupyter-widgets/ipyleaflet/pull/982). Update your code with the following substitutions for a Map `map` (or LayerGroup):
22+
* `map.add_control(...)` or `map.add_layer(...)` -> `map.add(...)`
23+
* `map.remove_control(...)` or `map.remove_layer(...)` -> `map.remove(...)`
24+
* `map.substitute_control(...)` or `map.substitute_layer(...)` -> `map.substitute(...)`
25+
* `map.clear_controls(...)` or `map.clear_layers(...)` -> `map.clear(...)`
26+
27+
The inline operators still continue to work as before, such as `map += control` or `map -= layer`.
28+
29+
### Maintenance
1130

1231
* Compute the public path automatically [#988](https://github.com/jupyter-widgets/ipyleaflet/pull/988)
1332

@@ -16,8 +35,6 @@
1635
* Document use of multiple basemaps [#971](https://github.com/jupyter-widgets/ipyleaflet/pull/971)
1736
* Add a small introduction text [#992](https://github.com/jupyter-widgets/ipyleaflet/pull/992)
1837

19-
**Full Changelog**: https://github.com/jupyter-widgets/ipyleaflet/compare/0.16.0...0.17.0
20-
2138
## v0.16.0
2239
### New features
2340

docs/source/changelog.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Releases
2+
========
3+
4+
The changes for each release are listed in the `ChangeLog <https://github.com/jupyter-widgets/ipyleaflet/blob/master/CHANGELOG.md>`_.

docs/source/controls/legend_control.rst

+5-5
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

docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ Table of Contents
3333
controls/index
3434
api_reference/index
3535
related_projects/index
36+
changelog

examples/LegendControl.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"cell_type": "markdown",
6767
"metadata": {},
6868
"source": [
69-
"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."
69+
"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."
7070
]
7171
},
7272
{
@@ -77,7 +77,7 @@
7777
"source": [
7878
"a_legend = LegendControl(\n",
7979
" {\"low\": \"#FAA\", \"medium\": \"#A55\", \"High\": \"#500\"},\n",
80-
" name=\"Legend\",\n",
80+
" title=\"Legend\",\n",
8181
" position=\"bottomright\",\n",
8282
")"
8383
]
@@ -102,7 +102,7 @@
102102
"cell_type": "markdown",
103103
"metadata": {},
104104
"source": [
105-
"### Name"
105+
"### Title"
106106
]
107107
},
108108
{
@@ -111,8 +111,8 @@
111111
"metadata": {},
112112
"outputs": [],
113113
"source": [
114-
"a_legend.name = \"Risk\" ## set name\n",
115-
"a_legend.name # get name"
114+
"a_legend.title = \"Risk\" ## set title\n",
115+
"a_legend.title # get title"
116116
]
117117
},
118118
{

ipyleaflet/leaflet.py

+84-15
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ def add_layer(self, layer):
11071107
layer: layer instance
11081108
The new layer to include in the group.
11091109
"""
1110-
warnings.warn("add_layer will be deprecated in future version, use add instead", PendingDeprecationWarning)
1110+
warnings.warn("add_layer is deprecated, use add instead", DeprecationWarning)
11111111

11121112
self.add(layer)
11131113

@@ -1122,7 +1122,7 @@ def remove_layer(self, rm_layer):
11221122
layer: layer instance
11231123
The layer to remove from the group.
11241124
"""
1125-
warnings.warn("remove_layer will be deprecated in future version, use remove instead", PendingDeprecationWarning)
1125+
warnings.warn("remove_layer is deprecated, use remove instead", DeprecationWarning)
11261126

11271127
self.remove(rm_layer)
11281128

@@ -1139,7 +1139,7 @@ def substitute_layer(self, old, new):
11391139
new: layer instance
11401140
The new layer to include in the group.
11411141
"""
1142-
warnings.warn("substitute_layer will be deprecated in future version, substitute instead", PendingDeprecationWarning)
1142+
warnings.warn("substitute_layer is deprecated, use substitute instead", DeprecationWarning)
11431143

11441144
self.substitute(old, new)
11451145

@@ -1151,7 +1151,7 @@ def clear_layers(self):
11511151
11521152
"""
11531153

1154-
warnings.warn("clear_layers will be deprecated in future version, use clear instead", PendingDeprecationWarning)
1154+
warnings.warn("clear_layers is deprecated, use clear instead", DeprecationWarning)
11551155

11561156
self.layers = ()
11571157

@@ -1915,6 +1915,10 @@ class LegendControl(Control):
19151915
19161916
A control which contains a legend.
19171917
1918+
.. deprecated :: 0.17.0
1919+
The constructor argument 'name' is deprecated, use the 'title' argument instead.
1920+
1921+
19181922
Attributes
19191923
----------
19201924
title: str, default 'Legend'
@@ -1932,10 +1936,75 @@ class LegendControl(Control):
19321936
"value 2": "#55A",
19331937
"value 3": "#005"}).tag(sync=True)
19341938

1935-
def __init__(self, legend, *args, name="Legend", **kwargs):
1939+
def __init__(self, legend, *args, **kwargs):
1940+
kwargs["legend"] = legend
1941+
# For backwards compatibility with ipyleaflet<=0.16.0
1942+
if 'name' in kwargs:
1943+
warnings.warn("the name argument is deprecated, use title instead", DeprecationWarning)
1944+
kwargs.setdefault('title', kwargs['name'])
1945+
del kwargs['name']
19361946
super().__init__(*args, **kwargs)
1937-
self.title = name
1938-
self.legend = legend
1947+
1948+
@property
1949+
def name(self):
1950+
"""The title of the legend.
1951+
1952+
.. deprecated :: 0.17.0
1953+
Use title attribute instead.
1954+
"""
1955+
warnings.warn(".name is deprecated, use .title instead", DeprecationWarning)
1956+
return self.title
1957+
1958+
@name.setter
1959+
def name(self, title):
1960+
warnings.warn(".name is deprecated, use .title instead", DeprecationWarning)
1961+
self.title = title
1962+
1963+
@property
1964+
def legends(self):
1965+
"""The legend information.
1966+
1967+
.. deprecated :: 0.17.0
1968+
Use legend attribute instead.
1969+
"""
1970+
1971+
warnings.warn(".legends is deprecated, use .legend instead", DeprecationWarning)
1972+
return self.legend
1973+
1974+
@legends.setter
1975+
def legends(self, legends):
1976+
warnings.warn(".legends is deprecated, use .legend instead", DeprecationWarning)
1977+
self.legend = legends
1978+
1979+
@property
1980+
def positioning(self):
1981+
"""The position information.
1982+
1983+
.. deprecated :: 0.17.0
1984+
Use position attribute instead.
1985+
"""
1986+
warnings.warn(".positioning is deprecated, use .position instead", DeprecationWarning)
1987+
return self.position
1988+
1989+
@positioning.setter
1990+
def positioning(self, position):
1991+
warnings.warn(".positioning is deprecated, use .position instead", DeprecationWarning)
1992+
self.position = position
1993+
1994+
@property
1995+
def positionning(self):
1996+
"""The position information.
1997+
1998+
.. deprecated :: 0.17.0
1999+
Use position attribute instead.
2000+
"""
2001+
warnings.warn(".positionning is deprecated, use .position instead", DeprecationWarning)
2002+
return self.position
2003+
2004+
@positionning.setter
2005+
def positionning(self, position):
2006+
warnings.warn(".positionning is deprecated, use .position instead", DeprecationWarning)
2007+
self.position = position
19392008

19402009
def add_legend_element(self, key, value):
19412010
"""Add a new legend element.
@@ -2283,15 +2352,15 @@ def _validate_layers(self, proposal):
22832352
def add_layer(self, layer):
22842353
"""Add a layer on the map.
22852354
2286-
.. deprecated :: 0.0
2355+
.. deprecated :: 0.17.0
22872356
Use add method instead.
22882357
22892358
Parameters
22902359
----------
22912360
layer: Layer instance
22922361
The new layer to add.
22932362
"""
2294-
warnings.warn("add_layer will be deprecated in future version, use add instead", PendingDeprecationWarning)
2363+
warnings.warn("add_layer is deprecated, use add instead", DeprecationWarning)
22952364
self.add(layer)
22962365

22972366
def remove_layer(self, rm_layer):
@@ -2305,7 +2374,7 @@ def remove_layer(self, rm_layer):
23052374
layer: Layer instance
23062375
The layer to remove.
23072376
"""
2308-
warnings.warn("remove_layer will be deprecated in future version, use remove instead", PendingDeprecationWarning)
2377+
warnings.warn("remove_layer is deprecated, use remove instead", DeprecationWarning)
23092378

23102379
self.remove(rm_layer)
23112380

@@ -2322,7 +2391,7 @@ def substitute_layer(self, old, new):
23222391
new: Layer instance
23232392
The new layer to add.
23242393
"""
2325-
warnings.warn("substitute_layer will be deprecated in future version, use substitute instead", PendingDeprecationWarning)
2394+
warnings.warn("substitute_layer is deprecated, use substitute instead", DeprecationWarning)
23262395

23272396
self.substitute(old, new)
23282397

@@ -2333,7 +2402,7 @@ def clear_layers(self):
23332402
Use add method instead.
23342403
23352404
"""
2336-
warnings.warn("clear_layers will be deprecated in future version, use clear instead", PendingDeprecationWarning)
2405+
warnings.warn("clear_layers is deprecated, use clear instead", DeprecationWarning)
23372406

23382407
self.layers = ()
23392408

@@ -2364,7 +2433,7 @@ def add_control(self, control):
23642433
The new control to add.
23652434
"""
23662435

2367-
warnings.warn("add_control will be deprecated in future version, use add instead", PendingDeprecationWarning)
2436+
warnings.warn("add_control is deprecated, use add instead", DeprecationWarning)
23682437

23692438
self.add(control)
23702439

@@ -2379,7 +2448,7 @@ def remove_control(self, control):
23792448
control: Control instance
23802449
The control to remove.
23812450
"""
2382-
warnings.warn("remove_control will be deprecated in future version, use remove instead", PendingDeprecationWarning)
2451+
warnings.warn("remove_control is deprecated, use remove instead", DeprecationWarning)
23832452

23842453
self.remove(control)
23852454

@@ -2389,7 +2458,7 @@ def clear_controls(self):
23892458
.. deprecated :: 0.17.0
23902459
Use clear method instead.
23912460
"""
2392-
warnings.warn("clear_controls will be deprecated in future version, use clear instead", PendingDeprecationWarning)
2461+
warnings.warn("clear_controls is deprecated, use clear instead", DeprecationWarning)
23932462

23942463
self.controls = ()
23952464

0 commit comments

Comments
 (0)