From 2817b95c93c3d953c4b7c9cdeec928f21f7f9b8c Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 3 May 2019 18:45:15 -0700 Subject: [PATCH 1/7] Set path attr in case ErrorBarItem initialized without data --- pyqtgraph/graphicsItems/ErrorBarItem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/graphicsItems/ErrorBarItem.py b/pyqtgraph/graphicsItems/ErrorBarItem.py index 986c5140..09fa97da 100644 --- a/pyqtgraph/graphicsItems/ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/ErrorBarItem.py @@ -59,6 +59,7 @@ class ErrorBarItem(GraphicsObject): x, y = self.opts['x'], self.opts['y'] if x is None or y is None: + self.path = p return beam = self.opts['beam'] @@ -146,4 +147,4 @@ class ErrorBarItem(GraphicsObject): self.drawPath() return self.path.boundingRect() - \ No newline at end of file + From 501ad4f08238b53e999c5f8e321fbd77680edcec Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Thu, 6 Jun 2019 23:45:28 -0700 Subject: [PATCH 2/7] Only set visible when ErrorBarItem has something to draw. --- pyqtgraph/graphicsItems/ErrorBarItem.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyqtgraph/graphicsItems/ErrorBarItem.py b/pyqtgraph/graphicsItems/ErrorBarItem.py index 09fa97da..4dc93a56 100644 --- a/pyqtgraph/graphicsItems/ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/ErrorBarItem.py @@ -23,6 +23,7 @@ class ErrorBarItem(GraphicsObject): beam=None, pen=None ) + self.setVisible(False) self.setData(**opts) def setData(self, **opts): @@ -44,6 +45,8 @@ class ErrorBarItem(GraphicsObject): This method was added in version 0.9.9. For prior versions, use setOpts. """ + if 'x' in opts and 'y' in opts: + self.setVisible(True) self.opts.update(opts) self.path = None self.update() From 654b76e6a360dd62c21082be8820c2020a90c049 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Thu, 6 Jun 2019 23:57:34 -0700 Subject: [PATCH 3/7] Handle setting/clearing data a little more robustly. --- pyqtgraph/graphicsItems/ErrorBarItem.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/graphicsItems/ErrorBarItem.py b/pyqtgraph/graphicsItems/ErrorBarItem.py index 4dc93a56..5e399e34 100644 --- a/pyqtgraph/graphicsItems/ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/ErrorBarItem.py @@ -45,9 +45,11 @@ class ErrorBarItem(GraphicsObject): This method was added in version 0.9.9. For prior versions, use setOpts. """ - if 'x' in opts and 'y' in opts: - self.setVisible(True) self.opts.update(opts) + if self.opts['x'] is not None and self.opts['y'] is not None: + self.setVisible(True) + else: + self.setVisible(False) self.path = None self.update() self.prepareGeometryChange() From a2fb00633aa1ae64952eb61e97df2763fdbb966b Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 7 Jun 2019 00:00:30 -0700 Subject: [PATCH 4/7] DeMorgans the logic for better readability. --- pyqtgraph/graphicsItems/ErrorBarItem.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/graphicsItems/ErrorBarItem.py b/pyqtgraph/graphicsItems/ErrorBarItem.py index 5e399e34..5d57e3db 100644 --- a/pyqtgraph/graphicsItems/ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/ErrorBarItem.py @@ -46,10 +46,10 @@ class ErrorBarItem(GraphicsObject): This method was added in version 0.9.9. For prior versions, use setOpts. """ self.opts.update(opts) - if self.opts['x'] is not None and self.opts['y'] is not None: - self.setVisible(True) - else: + if self.opts['x'] is None or self.opts['y'] is None: self.setVisible(False) + else: + self.setVisible(True) self.path = None self.update() self.prepareGeometryChange() From 1839c5ef59fd7d2f1a3671cda7c4b7e478d6a5a0 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 7 Jun 2019 13:32:25 -0700 Subject: [PATCH 5/7] More concise visibility setting logic --- pyqtgraph/graphicsItems/ErrorBarItem.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyqtgraph/graphicsItems/ErrorBarItem.py b/pyqtgraph/graphicsItems/ErrorBarItem.py index 5d57e3db..b79da6f7 100644 --- a/pyqtgraph/graphicsItems/ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/ErrorBarItem.py @@ -46,10 +46,7 @@ class ErrorBarItem(GraphicsObject): This method was added in version 0.9.9. For prior versions, use setOpts. """ self.opts.update(opts) - if self.opts['x'] is None or self.opts['y'] is None: - self.setVisible(False) - else: - self.setVisible(True) + self.setVisible(all(self.opts[ax] is not None for ax in ['x', 'y'])) self.path = None self.update() self.prepareGeometryChange() From 0c8423461274eb5567171ebf16cec93f9c617706 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Sat, 8 Jun 2019 19:57:53 -0700 Subject: [PATCH 6/7] Add a test for ErrorBarItem --- .../graphicsItems/tests/test_ErrorBarItem.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py diff --git a/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py new file mode 100644 index 00000000..8fa38153 --- /dev/null +++ b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py @@ -0,0 +1,39 @@ +import pytest +from pyqtgraph.Qt import QtGui, QtCore +import pyqtgraph as pg +import numpy as np + +app = pg.mkQApp() + + +def test_errorbaritem_defer_data(): + plot = pg.PlotWidget() + plot.show() + + # plot some data away from the origin to set the view rect + x = np.arange(5) + 10 + curve = pg.PlotCurveItem(x=x, y=x) + plot.addItem(curve) + app.processEvents() + r_no_ebi = plot.viewRect() + + # ErrorBarItem with no data shouldn't affect the view rect + err = pg.ErrorBarItem() + plot.addItem(err) + app.processEvents() + r_empty_ebi = plot.viewRect() + + assert r_no_ebi == r_empty_ebi + + err.setData(x=x, y=x, bottom=x, top=x) + app.processEvents() + r_ebi = plot.viewRect() + + assert r_empty_ebi != r_ebi + + # unset data, ErrorBarItem disappears and view rect goes back to original + err.setData(x=None, y=None) + app.processEvents() + r_clear_ebi = plot.viewRect() + + assert r_clear_ebi == r_no_ebi From c5126dc26f786e0249b757901bc9fdea7d5de2e0 Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Sun, 9 Jun 2019 09:12:01 -0700 Subject: [PATCH 7/7] Update test name. Cleanup unused imports. --- pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py index 8fa38153..4ee25e45 100644 --- a/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py @@ -1,12 +1,10 @@ -import pytest -from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import numpy as np app = pg.mkQApp() -def test_errorbaritem_defer_data(): +def test_ErrorBarItem_defer_data(): plot = pg.PlotWidget() plot.show()