Skip to content

Commit ba76fcd

Browse files
author
Stephanie Reeder
committed
Merge pull request #281 from ODM2/scroll_zoom
fix issue #119
2 parents d0025bc + f20f5a7 commit ba76fcd

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

odmtools/gui/mnuPlotToolbar.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __init__(self, plotCanvas, multPlots=False, allowselect=False):
132132

133133
self.msg = wx.StaticText(self, -1, "")
134134
self.AddControl(self.msg)
135-
135+
self.canvas.mpl_connect('scroll_event', self.on_scroll_zoom)
136136
self.Realize()
137137

138138
def editSeries(self, xys, edit):
@@ -248,6 +248,8 @@ def on_toggle_zoom_data_tool(self, event):
248248
self.canvas.draw()
249249

250250

251+
252+
251253
#must add these methods for mac functionality
252254
def release_zoom(self, event):
253255
super(self.__class__, self).release_zoom(event)
@@ -264,3 +266,37 @@ def forward(self, event):
264266
def home(self, event):
265267
super(self.__class__, self).home(event)
266268
self.canvas.draw()
269+
270+
271+
272+
273+
def on_scroll_zoom(self, event):
274+
axes = self.canvas.figure.axes[0]
275+
base_scale = 1.2
276+
# get the current x and y limits
277+
cur_xlim = axes.get_xlim()
278+
cur_ylim = axes.get_ylim()
279+
cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5
280+
cur_yrange = (cur_ylim[1] - cur_ylim[0])*.5
281+
xdata = event.xdata # get event x location
282+
ydata = event.ydata # get event y location
283+
if event.button == 'up':
284+
# deal with zoom in
285+
scale_factor = 1/base_scale
286+
elif event.button == 'down':
287+
# deal with zoom out
288+
scale_factor = base_scale
289+
else:
290+
# deal with something that should never happen
291+
scale_factor = 1
292+
print event.button
293+
# set new limits
294+
axes.set_xlim([xdata - cur_xrange*scale_factor,
295+
xdata + cur_xrange*scale_factor])
296+
axes.set_ylim([ydata - cur_yrange*scale_factor,
297+
ydata + cur_yrange*scale_factor])
298+
self.canvas.draw() # force re-draw
299+
300+
# fig = ax.get_figure() # get the figure of interest
301+
# attach the call back
302+

odmtools/gui/plotTimeSeries.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ def drawEditPlot(self, oneSeries):
278278
curraxis.set_xlabel('Date')
279279

280280
convertedDates = matplotlib.dates.date2num(dates)
281+
282+
scale = 1.5
283+
f = zoom_factory(curraxis , base_scale = scale)
281284
self.xys = zip(convertedDates, oneSeries.dataTable['DataValue'])
282285
self.toolbar.editSeries(self.xys, self.editCurve)
283286
self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
@@ -696,3 +699,6 @@ def __call__(self, event):
696699
self.toolbar.msg.SetLabelText("X= %s, Y= %.4f (%s)" % (xValue, y, self.name))
697700
self.toolbar.msg.SetForegroundColour((66, 66, 66))
698701
#logger.debug('{n}: ({x}, {y:0.2f})'.format(n=self.name, x=xValue.strftime("%Y-%m-%d %H:%M:%S"), y=y))
702+
703+
704+

0 commit comments

Comments
 (0)