Skip to content

Commit 4102b75

Browse files
committed
Deprecate Tick.{gridOn,tick1On,label1On,...} in favor of set_visible.
Visibility attributes should just be set on the underlying artists (`tick.gridline.set_visible`, etc.) rather than maintaining yet another layer of control.
1 parent 9767cfe commit 4102b75

File tree

8 files changed

+258
-378
lines changed

8 files changed

+258
-378
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Deprecation of redundant `Tick` attributes
2+
``````````````````````````````````````````
3+
4+
The ``gridOn``, ``tick1On``, ``tick2On``, ``label1On``, and ``label2On``
5+
`~.Tick` attributes have been deprecated. Directly get and set the visibility
6+
on the underlying artists, available as the ``gridline``, ``tick1line``,
7+
``tick2line``, ``label1``, and ``label2`` attributes.
8+
9+
The ``label`` attribute, which was an alias for ``label1``, has been
10+
deprecated.
11+
12+
Subclasses that relied on setting the above visibility attributes needs to be
13+
updated; see e.g. :file:`examples/api/skewt.py`.

examples/api/skewt.py

+22-60
Original file line numberDiff line numberDiff line change
@@ -24,66 +24,28 @@
2424
# The sole purpose of this class is to look at the upper, lower, or total
2525
# interval as appropriate and see what parts of the tick to draw, if any.
2626
class SkewXTick(maxis.XTick):
27-
def update_position(self, loc):
28-
# This ensures that the new value of the location is set before
29-
# any other updates take place
30-
self._loc = loc
31-
super(SkewXTick, self).update_position(loc)
32-
33-
def _has_default_loc(self):
34-
return self.get_loc() is None
35-
36-
def _need_lower(self):
37-
return (self._has_default_loc() or
38-
transforms.interval_contains(self.axes.lower_xlim,
39-
self.get_loc()))
40-
41-
def _need_upper(self):
42-
return (self._has_default_loc() or
43-
transforms.interval_contains(self.axes.upper_xlim,
44-
self.get_loc()))
45-
46-
@property
47-
def gridOn(self):
48-
return (self._gridOn and (self._has_default_loc() or
49-
transforms.interval_contains(self.get_view_interval(),
50-
self.get_loc())))
51-
52-
@gridOn.setter
53-
def gridOn(self, value):
54-
self._gridOn = value
55-
56-
@property
57-
def tick1On(self):
58-
return self._tick1On and self._need_lower()
59-
60-
@tick1On.setter
61-
def tick1On(self, value):
62-
self._tick1On = value
63-
64-
@property
65-
def label1On(self):
66-
return self._label1On and self._need_lower()
67-
68-
@label1On.setter
69-
def label1On(self, value):
70-
self._label1On = value
71-
72-
@property
73-
def tick2On(self):
74-
return self._tick2On and self._need_upper()
75-
76-
@tick2On.setter
77-
def tick2On(self, value):
78-
self._tick2On = value
79-
80-
@property
81-
def label2On(self):
82-
return self._label2On and self._need_upper()
83-
84-
@label2On.setter
85-
def label2On(self, value):
86-
self._label2On = value
27+
def draw(self, renderer):
28+
base_visibility = {
29+
artist: artist.get_visible() for artist in [
30+
self.gridline, self.tick1line, self.tick2line,
31+
self.label1, self.label2]}
32+
try:
33+
needs_lower = transforms.interval_contains(
34+
self.axes.lower_xlim, self.get_loc())
35+
needs_upper = transforms.interval_contains(
36+
self.axes.upper_xlim, self.get_loc())
37+
self.tick1line.set_visible(
38+
self.tick1line.get_visible() and needs_lower)
39+
self.label1.set_visible(
40+
self.label1.get_visible() and needs_lower)
41+
self.tick2line.set_visible(
42+
self.tick2line.get_visible() and needs_upper)
43+
self.label2.set_visible(
44+
self.label2.get_visible() and needs_upper)
45+
super(SkewXTick, self).draw(renderer)
46+
finally:
47+
for artist, visible in base_visibility.items():
48+
artist.set_visible(visible)
8749

8850
def get_view_interval(self):
8951
return self.axes.xaxis.get_view_interval()

0 commit comments

Comments
 (0)