Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions datalab/gui/plugins/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
self.items: list = []
self._plot_kind: str | None = None
self._plot_signature: tuple | None = None
self._value_range: tuple[float, float] | None = None

splitter = QW.QSplitter(QC.Qt.Horizontal)
self._stage = QW.QWidget()
Expand Down Expand Up @@ -226,7 +227,14 @@ def render(self, frame: InstrumentFrame) -> None:
plot.do_autoscale(replot=False)
if kind == "curve" and frame.value_range is not None:
plot.set_axis_limits("left", *frame.value_range)
elif kind == "curve" and frame.value_range != self._value_range:
# Like a new V/div on a scope: Y follows, the X zoom is kept
if frame.value_range is None:
plot.do_autoscale(replot=False, axis_id=plot.get_axis_id("left"))
else:
plot.set_axis_limits("left", *frame.value_range)
self._plot_signature = signature
self._value_range = frame.value_range
self.summary_label.setText(frame.summary)
plot.replot()

Expand Down
19 changes: 18 additions & 1 deletion datalab/tests/features/plugins/plugin_tools_app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import numpy as np
import pytest
from qtpy import QtWidgets as QW
from sigima.objects import create_image
from sigima.objects import create_image, create_signal

from datalab.config import Conf
from datalab.gui.main import DLMainWindow
from datalab.gui.plugins.instrument import InstrumentWindow
from datalab.plugins import PluginRegistry
from datalab.plugins.instruments import InstrumentFrame
from datalab.tests import datalab_test_app_context
from datalab.tests.features.plugins.plugin_test_dataset import temporary_plugin_dir

Expand Down Expand Up @@ -167,6 +168,22 @@ def test_plugin_tools_in_menus_and_instrument_window(
assert window.summary_label.text().startswith("Frame")
assert window.plotwidget.plot.get_axis_limits("left") == (-2.0, 2.0)

# A new value range with the same X axis updates Y and keeps the X zoom
plot = window.plotwidget.plot
x = np.linspace(0.0, 1.0, 11)
plot.set_axis_limits("bottom", 0.2, 0.6)
window.render(
InstrumentFrame((create_signal("Live", x, x),), value_range=(-5, 5))
)
assert plot.get_axis_limits("left") == (-5.0, 5.0)
assert plot.get_axis_limits("bottom") == (0.2, 0.6)
window.render(InstrumentFrame((create_signal("Live", x, x),)))
assert plot.get_axis_limits("left")[1] < 5.0
assert plot.get_axis_limits("bottom") == (0.2, 0.6)
wider = np.linspace(0.0, 2.0, 11)
window.render(InstrumentFrame((create_signal("Live", wider, wider),)))
assert plot.get_axis_limits("bottom")[1] >= 2.0

window.live_button.setChecked(True)
assert window._live_timer.isActive() # pylint: disable=protected-access
window.live_button.setChecked(False)
Expand Down
Loading