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() return self.ctrl.clipToViewCheck.isChecked()
def updateDecimation(self): def updateDecimation(self):
if self.ctrl.maxTracesCheck.isChecked(): if not self.ctrl.maxTracesCheck.isChecked():
numCurves = self.ctrl.maxTracesSpin.value() numCurves = len(self.curves)
else: else:
numCurves = -1 numCurves = self.ctrl.maxTracesSpin.value()
curves = self.curves[:] for i, curve in enumerate(self.curves):
split = len(curves) - numCurves if i < numCurves:
for curve in curves[split:]: curve.show()
if numCurves != -1: elif self.ctrl.forgetTracesCheck.isChecked():
if self.ctrl.forgetTracesCheck.isChecked(): curve.clear()
curve.clear() self.removeItem(curve)
self.removeItem(curve) else:
else: curve.hide()
curve.hide()
def updateAlpha(self, *args): def updateAlpha(self, *args):
(alpha, auto) = self.alphaState() (alpha, auto) = self.alphaState()

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import numpy as np
import pytest import pytest
import pyqtgraph as pg import pyqtgraph as pg
app = pg.mkQApp() app = pg.mkQApp()
@ -23,6 +25,21 @@ def test_PlotItem_shared_axis_items(orientation):
pi2.setAxisItems({orientation: ax1}) 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(): def test_plotitem_menu_initialize():
"""Test the menu initialization of the plotitem""" """Test the menu initialization of the plotitem"""
item = pg.PlotItem() item = pg.PlotItem()