@@ -57,7 +57,6 @@ def __init__(self, controller=None, parent=None, backend="qt"):
5757 self .delta_y = 40.0 # um
5858 self .gain_y = 0.02
5959 self .factor_x = 1.0
60- self .factor_y = 1.0
6160 espx = self .delta_x / 2.5
6261 for chan_ind , chan_id in enumerate (self .controller .channel_ids ):
6362 x , y = self .contact_location [chan_ind , :]
@@ -241,9 +240,24 @@ def _qt_widen_narrow(self, factor_ratio):
241240 self ._qt_refresh (keep_range = True )
242241
243242 def _qt_heighten_shorten (self , factor_ratio ):
244- if self .mode == "geometry" :
245- self .factor_y *= factor_ratio
246- self ._qt_refresh (keep_range = True )
243+ import pyqtgraph as pg
244+ if self .mode == "geometry" :
245+ vb = self .plot1 .getViewBox ()
246+
247+ # Disable auto-range properly (must be on ViewBox!)
248+ vb .enableAutoRange (axis = pg .ViewBox .XYAxes , enable = False )
249+ vb .setAspectLocked (False )
250+
251+ # Get current ranges
252+ _ , (ymin , ymax ) = vb .viewRange ()
253+
254+ # Scale Y only
255+ yrange = ymax - ymin
256+ ymid = (ymin + ymax ) / 2.0
257+ new_yrange = yrange * factor_ratio
258+ ymin = ymid - new_yrange / 2.0
259+ ymax = ymid + new_yrange / 2.0
260+ vb .setYRange (ymin , ymax , padding = 0.0 )
247261
248262 def _qt_gain_zoom (self , factor_ratio ):
249263 if self .mode == "geometry" :
@@ -441,7 +455,7 @@ def _qt_refresh_mode_geometry(self, dict_visible_units, keep_range, auto_zoom):
441455 ypos = self .contact_location [common_channel_indexes , 1 ]
442456
443457 wf = template_avg
444- wf = wf * self .gain_y * self .delta_y + self . factor_y * ypos [None , :]
458+ wf = wf * self .gain_y * self .delta_y + ypos [None , :]
445459
446460 connect = np .ones (wf .shape , dtype = "bool" )
447461 connect [0 , :] = 0
@@ -584,7 +598,7 @@ def _qt_refresh_with_spikes(self):
584598 self .curve_waveforms .setData (xvect , wf_flat )
585599 elif self .mode == "geometry" :
586600 ypos = self .contact_location [common_channel_indexes , 1 ]
587- wf_plot = wf * self .gain_y * self .delta_y + self . factor_y * ypos [None , :]
601+ wf_plot = wf * self .gain_y * self .delta_y + ypos [None , :]
588602
589603 connect = np .ones (wf_plot .shape , dtype = "bool" )
590604 connect [0 , :] = 0
@@ -708,7 +722,7 @@ def _plot_waveforms_for_unit(self, waveforms, color, width, common_channel_index
708722
709723 for i in range (n_waveforms ):
710724 wf_single = waveforms [i ] # (width, n_channels)
711- wf_plot = wf_single * self .gain_y * self .delta_y + self . factor_y * ypos [None , :]
725+ wf_plot = wf_single * self .gain_y * self .delta_y + ypos [None , :]
712726
713727 connect = np .ones (wf_plot .shape , dtype = "bool" )
714728 connect [0 , :] = 0
@@ -849,7 +863,6 @@ def _panel_refresh(self, keep_range=False):
849863 # zoom factor is reset
850864 if self .settings ["auto_zoom_on_unit_selection" ]:
851865 self .factor_x = 1.0
852- self .factor_y = 1.0
853866 self .gain_y = 0.02
854867 self ._panel_refresh_mode_geometry (dict_visible_units , keep_range = keep_range )
855868 elif self .mode == "flatten" :
@@ -963,10 +976,17 @@ def _panel_gain_zoom(self, event):
963976 if modifiers ["shift" ] and modifiers ["alt" ]:
964977 self .figure_geom .toolbar .active_scroll = None
965978 if self .mode == "geometry" :
966- factor = 1.3 if event .delta > 0 else 1 / 1.3
967- self .factor_y *= factor
968- self ._panel_refresh_mode_geometry (keep_range = True )
969- self ._panel_refresh_waveforms_samples ()
979+ factor_ratio = 1.3 if event .delta > 0 else 1 / 1.3
980+ # adjust y range and keep center
981+ ymin = self .figure_geom .y_range .start
982+ ymax = self .figure_geom .y_range .end
983+ yrange = ymax - ymin
984+ ymid = 0.5 * (ymin + ymax )
985+ new_yrange = yrange * factor_ratio
986+ ymin = ymid - new_yrange / 2.
987+ ymax = ymid + new_yrange / 2.
988+ self .figure_geom .y_range .start = ymin
989+ self .figure_geom .y_range .end = ymax
970990 elif modifiers ["shift" ]:
971991 self .figure_geom .toolbar .active_scroll = self .zoom_tool
972992 elif modifiers ["alt" ]:
@@ -1022,7 +1042,7 @@ def _panel_refresh_mode_geometry(self, dict_visible_units=None, keep_range=False
10221042 ypos = self .contact_location [common_channel_indexes , 1 ]
10231043
10241044 wf = template_avg
1025- wf = wf * self .gain_y * self .delta_y + self . factor_y * ypos [None , :]
1045+ wf = wf * self .gain_y * self .delta_y + ypos [None , :]
10261046 # this disconnects each channel
10271047 wf [0 , :] = np .nan
10281048 wf [- 1 , :] = np .nan
@@ -1261,7 +1281,7 @@ def _panel_plot_waveforms_for_unit(self, waveforms, color, width, common_channel
12611281
12621282 for i in range (n_waveforms ):
12631283 wf_single = waveforms [i ] # (width, n_channels)
1264- wf_plot = wf_single * self .gain_y * self .delta_y + self . factor_y * ypos [None , :]
1284+ wf_plot = wf_single * self .gain_y * self .delta_y + ypos [None , :]
12651285
12661286 # Disconnect channels (first sample of each channel is NaN)
12671287 wf_plot [0 , :] = np .nan
0 commit comments