Skip to content

Commit 2f61294

Browse files
committed
update graph_widget in example_basic
1 parent c2e12ed commit 2f61294

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

example_basic/graph_widget.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self, **kwargs):
7373
self.touch_mode='pan'
7474
self.hover_on = False
7575
self.xsorted = True #to manage x sorted data (if numpy is used)
76+
self.minzoom = dp(40) #minimum pixel distance to apply zoom
7677

7778
#zoom box coordonnate
7879
self.x0_box = None
@@ -449,7 +450,14 @@ def on_touch_up(self, event):
449450

450451
x, y = event.x, event.y
451452
if abs(self._box_size[0]) > 1 or abs(self._box_size[1]) > 1 or self.touch_mode=='zoombox':
452-
self.reset_box()
453+
self.reset_box()
454+
if not self.collide_point(x, y) and self.do_update:
455+
#update axis lim if zoombox is used and touch outside widget
456+
self.update_lim()
457+
ax=self.axes
458+
ax.figure.canvas.draw_idle()
459+
ax.figure.canvas.flush_events()
460+
return True
453461

454462
# stop propagating if its within our bounds
455463
if self.collide_point(x, y):
@@ -511,8 +519,8 @@ def apply_pan(self, ax, event):
511519

512520
cur_xlim = ax.get_xlim()
513521
cur_ylim = ax.get_ylim()
514-
cur_xlim -= dx
515-
cur_ylim -= dy
522+
cur_xlim -= dx/2
523+
cur_ylim -= dy/2
516524
ax.set_xlim(cur_xlim)
517525
ax.set_ylim(cur_ylim)
518526

@@ -598,7 +606,7 @@ def update_lim(self):
598606

599607
def reset_box(self):
600608
""" reset zoombox and apply zoombox limit if zoombox option if selected"""
601-
if abs(self._box_size[0])>dp(50) and abs(self._box_size[1])>dp(50):
609+
if min(abs(self._box_size[0]),abs(self._box_size[1]))>self.minzoom:
602610
trans = self.axes.transData.inverted()
603611
self.x0_box, self.y0_box = trans.transform_point((self._box_pos[0], self._box_pos[1]-self.pos[1]))
604612
self.x1_box, self.y1_box = trans.transform_point((self._box_size[0]+self._box_pos[0], self._box_size[1]+self._box_pos[1]-self.pos[1]))
@@ -675,7 +683,7 @@ def draw_box(self, event, x0, y0, x1, y1) -> None:
675683
else:
676684
y0=y0_max[0][1]+pos_y
677685

678-
if abs(x1-x0)<dp(20) and abs(y1-y0)>dp(50):
686+
if abs(x1-x0)<dp(20) and abs(y1-y0)>self.minzoom:
679687
self.pos_x_rect_ver=x0
680688
self.pos_y_rect_ver=y0
681689

@@ -687,7 +695,7 @@ def draw_box(self, event, x0, y0, x1, y1) -> None:
687695

688696
self._alpha_ver=1
689697

690-
elif abs(y1-y0)<dp(20) and abs(x1-x0)>dp(50):
698+
elif abs(y1-y0)<dp(20) and abs(x1-x0)>self.minzoom:
691699
self.pos_x_rect_hor=x0
692700
self.pos_y_rect_hor=y0
693701

@@ -784,7 +792,7 @@ def blit(self, bbox=None):
784792
rectangle:
785793
(self.pos_x_rect_ver-dp(20), self.pos_y_rect_ver-dp(1), dp(40),dp(4))
786794
787-
#horizontal rectangle right
795+
#vertical rectangle top
788796
Color:
789797
rgba:0, 0, 0, self._alpha_ver
790798
Line:

example_basic/graph_widget.py.rej

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)