@@ -4255,41 +4255,14 @@ def _set_view(self, view):
4255
4255
self .set_xlim ((xmin , xmax ))
4256
4256
self .set_ylim ((ymin , ymax ))
4257
4257
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 ):
4260
4260
"""
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.
4276
4262
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.
4293
4266
"""
4294
4267
if len (bbox ) == 3 :
4295
4268
xp , yp , scl = bbox # Zooming code
@@ -4360,6 +4333,46 @@ def _set_view_from_bbox(self, bbox, direction='in',
4360
4333
symax1 = symax0 + factor * (symax0 - symax )
4361
4334
new_ybound = y_trf .inverted ().transform ([symin1 , symax1 ])
4362
4335
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 )
4363
4376
if not twinx and mode != "y" :
4364
4377
self .set_xbound (new_xbound )
4365
4378
self .set_autoscalex_on (False )
@@ -4400,22 +4413,13 @@ def end_pan(self):
4400
4413
"""
4401
4414
del self ._pan_start
4402
4415
4403
- def drag_pan (self , button , key , x , y ):
4416
+ def _get_pan_points (self , button , key , x , y ):
4404
4417
"""
4405
- Called when the mouse moves during a pan operation .
4418
+ Helper function to return the new points after a pan.
4406
4419
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.
4419
4423
"""
4420
4424
def format_deltas (key , dx , dy ):
4421
4425
if key == 'control' :
@@ -4469,8 +4473,29 @@ def format_deltas(key, dx, dy):
4469
4473
points = result .get_points ().astype (object )
4470
4474
# Just ignore invalid limits (typically, underflow in log-scale).
4471
4475
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 ])
4474
4499
4475
4500
def get_children (self ):
4476
4501
# docstring inherited.
0 commit comments