Skip to content

Commit b8cb0da

Browse files
committed
Add auto scale toggle to curve update test
1 parent c86b697 commit b8cb0da

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

plotpy/tests/features/test_data_update_curve.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ def get_data(variable_size: bool) -> tuple[np.ndarray, np.ndarray]:
4747
class CurveUpdateDialog(PlotDialog):
4848
"""Dialog box for curve update"""
4949

50-
def __init__(self, title: str, variable_size: bool = False) -> None:
50+
def __init__(
51+
self, title: str, variable_size: bool = False, auto_scale: bool = True
52+
) -> None:
5153
self.variable_size = variable_size
54+
self.auto_scale = auto_scale
5255
options = PlotOptions(title="-", show_contrast=True, type="curve")
5356
super().__init__(title=title, toolbar=True, edit=False, options=options)
5457
self.resize(600, 600)
@@ -78,12 +81,23 @@ def populate_plot_layout(self) -> None:
7881
variable_size_cb.setChecked(self.variable_size)
7982
variable_size_cb.stateChanged.connect(self.toggle_variable_size)
8083
self.add_widget(variable_size_cb, 0, 2)
84+
auto_scale_cb = QW.QCheckBox("Auto scale")
85+
auto_scale_cb.setChecked(True)
86+
auto_scale_cb.stateChanged.connect(self.toggle_auto_scale)
87+
self.add_widget(auto_scale_cb, 0, 3)
8188
self.add_widget(self.plot_widget, 1, 0, 1, 0)
8289

8390
def toggle_variable_size(self, state: int) -> None:
8491
"""Toggle variable size"""
8592
self.variable_size = state == QC.Qt.Checked
8693

94+
def toggle_auto_scale(self, state: int) -> None:
95+
"""Toggle auto scale"""
96+
self.auto_scale = state == QC.Qt.Checked
97+
plot = self.get_plot()
98+
if self.auto_scale:
99+
plot.do_autoscale()
100+
87101
def start_curve_update(self) -> None:
88102
"""Start curve update"""
89103
self.timer.timeout.connect(self.update_curve)
@@ -100,7 +114,10 @@ def update_curve(self) -> None:
100114
plot = self.get_plot()
101115
self.item.set_data(data[0], data[1])
102116
plot.set_title(f"Curve update {self.counter:03d}")
103-
plot.replot()
117+
if self.auto_scale:
118+
plot.do_autoscale()
119+
else:
120+
plot.replot()
104121

105122
def closeEvent(self, event: QG.QCloseEvent) -> None:
106123
"""Close the dialog and stop the timer"""

0 commit comments

Comments
 (0)