Merge pull request #861 from ixjlyons/errorbaritem-set-path
Set path attr in case ErrorBarItem initialized without data
This commit is contained in:
commit
172120106d
@ -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()
|
||||
|
||||
|
||||
|
||||
|
37
pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py
Normal file
37
pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py
Normal 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
|
Loading…
Reference in New Issue
Block a user