@@ -4255,41 +4255,14 @@ def _set_view(self, view):
42554255 self .set_xlim ((xmin , xmax ))
42564256 self .set_ylim ((ymin , ymax ))
42574257
4258- def _set_view_from_bbox (self , bbox , direction = 'in' ,
4259- mode = None , twinx = False , twiny = False ):
4258+ def _prepare_view_from_bbox (self , bbox , direction = 'in' ,
4259+ mode = None , twinx = False , twiny = False ):
42604260 """
4261- Update view from a selection bbox.
4262-
4263- .. note::
4264-
4265- Intended to be overridden by new projection types, but if not, the
4266- default implementation sets the view limits to the bbox directly.
4267-
4268- Parameters
4269- ----------
4270- bbox : 4-tuple or 3 tuple
4271- * If bbox is a 4 tuple, it is the selected bounding box limits,
4272- in *display* coordinates.
4273- * If bbox is a 3 tuple, it is an (xp, yp, scl) triple, where
4274- (xp, yp) is the center of zooming and scl the scale factor to
4275- zoom by.
4261+ Helper function to prepare the new bounds from a bbox.
42764262
4277- direction : str
4278- The direction to apply the bounding box.
4279- * `'in'` - The bounding box describes the view directly, i.e.,
4280- it zooms in.
4281- * `'out'` - The bounding box describes the size to make the
4282- existing view, i.e., it zooms out.
4283-
4284- mode : str or None
4285- The selection mode, whether to apply the bounding box in only the
4286- `'x'` direction, `'y'` direction or both (`None`).
4287-
4288- twinx : bool
4289- Whether this axis is twinned in the *x*-direction.
4290-
4291- twiny : bool
4292- Whether this axis is twinned in the *y*-direction.
4263+ This helper function returns the new x and y bounds from the zoom
4264+ bbox. This a convenience method to abstract the bbox logic
4265+ out of the base setter.
42934266 """
42944267 if len (bbox ) == 3 :
42954268 xp , yp , scl = bbox # Zooming code
@@ -4360,6 +4333,46 @@ def _set_view_from_bbox(self, bbox, direction='in',
43604333 symax1 = symax0 + factor * (symax0 - symax )
43614334 new_ybound = y_trf .inverted ().transform ([symin1 , symax1 ])
43624335
4336+ return new_xbound , new_ybound
4337+
4338+ def _set_view_from_bbox (self , bbox , direction = 'in' ,
4339+ mode = None , twinx = False , twiny = False ):
4340+ """
4341+ Update view from a selection bbox.
4342+
4343+ .. note::
4344+
4345+ Intended to be overridden by new projection types, but if not, the
4346+ default implementation sets the view limits to the bbox directly.
4347+
4348+ Parameters
4349+ ----------
4350+ bbox : 4-tuple or 3 tuple
4351+ * If bbox is a 4 tuple, it is the selected bounding box limits,
4352+ in *display* coordinates.
4353+ * If bbox is a 3 tuple, it is an (xp, yp, scl) triple, where
4354+ (xp, yp) is the center of zooming and scl the scale factor to
4355+ zoom by.
4356+
4357+ direction : str
4358+ The direction to apply the bounding box.
4359+ * `'in'` - The bounding box describes the view directly, i.e.,
4360+ it zooms in.
4361+ * `'out'` - The bounding box describes the size to make the
4362+ existing view, i.e., it zooms out.
4363+
4364+ mode : str or None
4365+ The selection mode, whether to apply the bounding box in only the
4366+ `'x'` direction, `'y'` direction or both (`None`).
4367+
4368+ twinx : bool
4369+ Whether this axis is twinned in the *x*-direction.
4370+
4371+ twiny : bool
4372+ Whether this axis is twinned in the *y*-direction.
4373+ """
4374+ new_xbound , new_ybound = self ._prepare_view_from_bbox (
4375+ bbox , direction = direction , mode = mode , twinx = twinx , twiny = twiny )
43634376 if not twinx and mode != "y" :
43644377 self .set_xbound (new_xbound )
43654378 self .set_autoscalex_on (False )
@@ -4400,22 +4413,13 @@ def end_pan(self):
44004413 """
44014414 del self ._pan_start
44024415
4403- def drag_pan (self , button , key , x , y ):
4416+ def _get_pan_points (self , button , key , x , y ):
44044417 """
4405- Called when the mouse moves during a pan operation .
4418+ Helper function to return the new points after a pan.
44064419
4407- Parameters
4408- ----------
4409- button : `.MouseButton`
4410- The pressed mouse button.
4411- key : str or None
4412- The pressed key, if any.
4413- x, y : float
4414- The mouse coordinates in display coords.
4415-
4416- Notes
4417- -----
4418- This is intended to be overridden by new projection types.
4420+ This helper function returns the points on the axis after a pan has
4421+ occurred. This is a convenience method to abstract the pan logic
4422+ out of the base setter.
44194423 """
44204424 def format_deltas (key , dx , dy ):
44214425 if key == 'control' :
@@ -4469,8 +4473,29 @@ def format_deltas(key, dx, dy):
44694473 points = result .get_points ().astype (object )
44704474 # Just ignore invalid limits (typically, underflow in log-scale).
44714475 points [~ valid ] = None
4472- self .set_xlim (points [:, 0 ])
4473- self .set_ylim (points [:, 1 ])
4476+ return points
4477+
4478+ def drag_pan (self , button , key , x , y ):
4479+ """
4480+ Called when the mouse moves during a pan operation.
4481+
4482+ Parameters
4483+ ----------
4484+ button : `.MouseButton`
4485+ The pressed mouse button.
4486+ key : str or None
4487+ The pressed key, if any.
4488+ x, y : float
4489+ The mouse coordinates in display coords.
4490+
4491+ Notes
4492+ -----
4493+ This is intended to be overridden by new projection types.
4494+ """
4495+ points = self ._get_pan_points (button , key , x , y )
4496+ if points is not None :
4497+ self .set_xlim (points [:, 0 ])
4498+ self .set_ylim (points [:, 1 ])
44744499
44754500 def get_children (self ):
44764501 # docstring inherited.
0 commit comments