0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

fix(plot_base): autorange takes into account only visible curves

This commit is contained in:
2025-07-11 13:33:36 +02:00
committed by Klaus Wakonig
parent ca600b057e
commit 76439866c1
5 changed files with 71 additions and 4 deletions

View File

@ -1,3 +1,5 @@
import numpy as np
from bec_widgets.widgets.plots.plot_base import PlotBase, UIMode
from .client_mocks import mocked_client
@ -126,6 +128,31 @@ def test_auto_range_x_y(qtbot, mocked_client):
assert pb.plot_item.vb.state["autoRange"][1] is False
def test_autorange_respects_visibility(qtbot, mocked_client):
"""
Autorange must consider only the curves whose .isVisible() flag is True.
"""
pb = create_widget(qtbot, PlotBase, client=mocked_client)
x = np.arange(10)
small = pb.plot_item.plot(x, x, pen=(255, 0, 0)) # 09
medium = pb.plot_item.plot(x, x * 10, pen=(0, 255, 0)) # 090
large = pb.plot_item.plot(x, x * 100, pen=(0, 0, 255)) # 0900
pb.auto_range(True)
qtbot.wait(200)
yspan_full = pb.plot_item.vb.viewRange()[1]
assert yspan_full[1] > 800, "Autorange must include the largest visible curve."
# Hide the largest curve, recompute autorange, and expect the span to shrink.
large.setVisible(False)
pb.auto_range(True)
qtbot.wait(200)
yspan_reduced = pb.plot_item.vb.viewRange()[1]
assert yspan_reduced[1] < 200, "Hidden curves must be excluded from autorange."
def test_x_log_y_log(qtbot, mocked_client):
"""
Test toggling log scale on x and y axes.