show and hide properly for maxTraces; +test (#1764)

This commit is contained in:
Martin Chase 2021-05-05 17:08:04 -07:00 committed by GitHub
parent cafe079910
commit fa1be1e5bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 13 deletions

View File

@ -1003,20 +1003,19 @@ class PlotItem(GraphicsWidget):
return self.ctrl.clipToViewCheck.isChecked()
def updateDecimation(self):
if self.ctrl.maxTracesCheck.isChecked():
numCurves = self.ctrl.maxTracesSpin.value()
if not self.ctrl.maxTracesCheck.isChecked():
numCurves = len(self.curves)
else:
numCurves = -1
curves = self.curves[:]
split = len(curves) - numCurves
for curve in curves[split:]:
if numCurves != -1:
if self.ctrl.forgetTracesCheck.isChecked():
curve.clear()
self.removeItem(curve)
else:
curve.hide()
numCurves = self.ctrl.maxTracesSpin.value()
for i, curve in enumerate(self.curves):
if i < numCurves:
curve.show()
elif self.ctrl.forgetTracesCheck.isChecked():
curve.clear()
self.removeItem(curve)
else:
curve.hide()
def updateAlpha(self, *args):
(alpha, auto) = self.alphaState()

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
import numpy as np
import pytest
import pyqtgraph as pg
app = pg.mkQApp()
@ -23,6 +25,21 @@ def test_PlotItem_shared_axis_items(orientation):
pi2.setAxisItems({orientation: ax1})
def test_PlotItem_maxTraces():
item = pg.PlotItem()
curve1 = pg.PlotDataItem(np.random.normal(size=10))
item.addItem(curve1)
assert curve1.isVisible(), f"{curve1} should be visible"
item.ctrl.maxTracesCheck.setChecked(True)
item.ctrl.maxTracesSpin.setValue(0)
assert not curve1.isVisible(), f"{curve1} should not be visible"
item.ctrl.maxTracesCheck.setChecked(False)
assert curve1.isVisible(), f"{curve1} should be visible"
def test_plotitem_menu_initialize():
"""Test the menu initialization of the plotitem"""
item = pg.PlotItem()