Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filling correction for Fillbetweenitem #2971

Merged
merged 3 commits into from Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyqtgraph/examples/FillBetweenItem.py
Expand Up @@ -20,7 +20,8 @@
mn = mx = np.zeros(len(x))
curves = [win.plot(x=x, y=np.zeros(len(x)), pen='k') for i in range(4)]
brushes = [0.5, (100, 100, 255), 0.5]
fills = [pg.FillBetweenItem(curves[i], curves[i+1], brushes[i]) for i in range(3)]
fills = [pg.FillBetweenItem(curves[0], curves[3], brushes[0]),
pg.FillBetweenItem(curves[1], curves[2], brushes[1])]
for f in fills:
win.addItem(f)

Expand Down
12 changes: 8 additions & 4 deletions pyqtgraph/graphicsItems/FillBetweenItem.py
Expand Up @@ -23,7 +23,7 @@ def __init__(self, curve1=None, curve2=None, brush=None, pen=None):
self.updatePath()

def setBrush(self, *args, **kwds):
"""Change the fill brush. Acceps the same arguments as pg.mkBrush()"""
"""Change the fill brush. Accepts the same arguments as pg.mkBrush()"""
QtWidgets.QGraphicsPathItem.setBrush(self, fn.mkBrush(*args, **kwds))

def setPen(self, *args, **kwds):
Expand Down Expand Up @@ -55,7 +55,6 @@ def setCurves(self, curve1, curve2):

def curveChanged(self):
self.updatePath()

def updatePath(self):
if self.curves is None:
self.setPath(QtGui.QPainterPath())
Expand All @@ -69,14 +68,19 @@ def updatePath(self):

path = QtGui.QPainterPath()
transform = QtGui.QTransform()

ps1 = paths[0].toSubpathPolygons(transform)
ps2 = paths[1].toReversed().toSubpathPolygons(transform)
ps2.reverse()

if len(ps1) == 0 or len(ps2) == 0:
self.setPath(QtGui.QPainterPath())
return


for p1, p2 in zip(ps1, ps2):
path.addPolygon(p1 + p2)
intersection = p1.intersected(p2)
if not intersection.isEmpty():
for i in range(intersection.size()):
path.lineTo(intersection.at(i))
ixjlyons marked this conversation as resolved.
Show resolved Hide resolved
path.addPolygon(p1 + p2)
self.setPath(path)