Merge pull request #861 from ixjlyons/errorbaritem-set-path

Set path attr in case ErrorBarItem initialized without data
This commit is contained in:
Ogi Moore 2019-06-09 09:23:36 -07:00 committed by GitHub
commit 172120106d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -23,6 +23,7 @@ class ErrorBarItem(GraphicsObject):
beam=None,
pen=None
)
self.setVisible(False)
self.setData(**opts)
def setData(self, **opts):
@ -45,6 +46,7 @@ class ErrorBarItem(GraphicsObject):
This method was added in version 0.9.9. For prior versions, use setOpts.
"""
self.opts.update(opts)
self.setVisible(all(self.opts[ax] is not None for ax in ['x', 'y']))
self.path = None
self.update()
self.prepareGeometryChange()
@ -59,6 +61,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 +149,4 @@ class ErrorBarItem(GraphicsObject):
self.drawPath()
return self.path.boundingRect()

View File

@ -0,0 +1,37 @@
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