Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42ce95a

Browse files
committed
Simplify GridHelper invalidation.
GridHelperBase.invalidate/valid and Axes.invalidate_grid_helper are never used externally and appear to be internal. But invalidation doesn't need to be stored in a separate flag (`_force_update`), one can simply reset `_old_limits` (which only serves this purpose) and unify that with `_old_values` (which does the same). The only `_update` method that was previously called to regenerate invalidated grid info was `GridHelperCurveLinear._update`, which, other than the redundant check of staleness (already done in `_update_lim`), just forwarded to `_update_grid`, so get rid of `_update` and just stick to `_update_grid`.
1 parent 7c813db commit 42ce95a

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``GridHelperBase`` invalidation
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The ``GridHelperBase.invalidate``, ``GridHelperBase.valid``, and
4+
``axislines.Axes.invalidate_grid_helper`` methods are considered internal
5+
and deprecated.

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,26 @@ def _f(locs, labels):
315315
class GridHelperBase:
316316

317317
def __init__(self):
318-
self._force_update = True
318+
self._force_update = True # Remove together with invalidate()/valid().
319319
self._old_limits = None
320320
super().__init__()
321321

322322
def update_lim(self, axes):
323323
x1, x2 = axes.get_xlim()
324324
y1, y2 = axes.get_ylim()
325-
326325
if self._force_update or self._old_limits != (x1, x2, y1, y2):
327-
self._update(x1, x2, y1, y2)
326+
self._update_grid(x1, y1, x2, y2)
328327
self._force_update = False
329328
self._old_limits = (x1, x2, y1, y2)
330329

331-
def _update(self, x1, x2, y1, y2):
332-
pass
330+
def _update_grid(self, x1, y1, x2, y2):
331+
"""Cache relevant computations when the axes limits have changed."""
333332

333+
@_api.deprecated("3.4")
334334
def invalidate(self):
335335
self._force_update = True
336336

337+
@_api.deprecated("3.4")
337338
def valid(self):
338339
return not self._force_update
339340

@@ -555,6 +556,7 @@ def get_children(self):
555556
children.extend(super().get_children())
556557
return children
557558

559+
@_api.deprecated("3.4")
558560
def invalidate_grid_helper(self):
559561
self._grid_helper.invalidate()
560562

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ def __init__(self, aux_trans,
289289
"""
290290
super().__init__()
291291
self.grid_info = None
292-
self._old_values = None
293292
self._aux_trans = aux_trans
294293
self.grid_finder = GridFinder(aux_trans,
295294
extreme_finder,
@@ -302,16 +301,7 @@ def update_grid_finder(self, aux_trans=None, **kw):
302301
if aux_trans is not None:
303302
self.grid_finder.update_transform(aux_trans)
304303
self.grid_finder.update(**kw)
305-
self.invalidate()
306-
307-
def _update(self, x1, x2, y1, y2):
308-
"""bbox in 0-based image coordinates"""
309-
# update wcsgrid
310-
if self.valid() and self._old_values == (x1, x2, y1, y2):
311-
return
312-
self._update_grid(x1, y1, x2, y2)
313-
self._old_values = (x1, x2, y1, y2)
314-
self._force_update = False
304+
self._old_limits = None # Force revalidation.
315305

316306
def new_fixed_axis(self, loc,
317307
nth_coord=None,

0 commit comments

Comments
 (0)