From fa1be1e5bf50c9da27cc9473b04f2399319dc324 Mon Sep 17 00:00:00 2001 From: Martin Chase Date: Wed, 5 May 2021 17:08:04 -0700 Subject: [PATCH] show and hide properly for maxTraces; +test (#1764) --- pyqtgraph/graphicsItems/PlotItem/PlotItem.py | 25 +++++++++---------- .../PlotItem/tests/test_PlotItem.py | 17 +++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py index 8da9ba39..c7d47631 100644 --- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py @@ -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() diff --git a/pyqtgraph/graphicsItems/PlotItem/tests/test_PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/tests/test_PlotItem.py index 83d2531d..9c464ffd 100644 --- a/pyqtgraph/graphicsItems/PlotItem/tests/test_PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/tests/test_PlotItem.py @@ -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()