Plot tab: axis-selective wheel zoom (X default, Shift+wheel for Y)
Add PlotViewBox subclassing pg.ViewBox. Overrides wheelEvent to route plain scroll to the X axis and Shift+scroll to the Y axis, both centred on the cursor position. Passed as viewBox= to every PlotWidget so the behaviour applies uniformly across all 8 plots. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -390,6 +390,16 @@ class TimeAxisItem(pg.AxisItem):
|
|||||||
return [datetime.fromtimestamp(v).strftime("%H:%M:%S") for v in values]
|
return [datetime.fromtimestamp(v).strftime("%H:%M:%S") for v in values]
|
||||||
|
|
||||||
|
|
||||||
|
class PlotViewBox(pg.ViewBox):
|
||||||
|
"""ViewBox with axis-selective wheel zoom: plain wheel → X, Shift+wheel → Y."""
|
||||||
|
def wheelEvent(self, ev, axis=None):
|
||||||
|
if ev.modifiers() & Qt.ShiftModifier:
|
||||||
|
axis = 1 # Y only
|
||||||
|
else:
|
||||||
|
axis = 0 # X only
|
||||||
|
super().wheelEvent(ev, axis=axis)
|
||||||
|
|
||||||
|
|
||||||
class PlotTooltip(QWidget):
|
class PlotTooltip(QWidget):
|
||||||
"""Floating value readout that follows the crosshair cursor."""
|
"""Floating value readout that follows the crosshair cursor."""
|
||||||
def __init__(self, parent: QWidget):
|
def __init__(self, parent: QWidget):
|
||||||
@@ -523,6 +533,7 @@ class PlotTab(QWidget):
|
|||||||
pw = pg.PlotWidget(
|
pw = pg.PlotWidget(
|
||||||
background="#12121e",
|
background="#12121e",
|
||||||
axisItems={"bottom": TimeAxisItem(orientation="bottom")},
|
axisItems={"bottom": TimeAxisItem(orientation="bottom")},
|
||||||
|
viewBox=PlotViewBox(),
|
||||||
)
|
)
|
||||||
pw.showGrid(x=True, y=True, alpha=0.3)
|
pw.showGrid(x=True, y=True, alpha=0.3)
|
||||||
pw.addLegend(offset=(0, 0), labelTextSize="8pt")
|
pw.addLegend(offset=(0, 0), labelTextSize="8pt")
|
||||||
|
|||||||
Reference in New Issue
Block a user