Use symbol id for a key in SymbolAtlas
Add test on a custom symbol for ScatterPlotItem. In PyQt5 QPainterPath is not hashable anymore which causes SymbolAtlas to fail accept it as a custom symbol, use id instead.
This commit is contained in:
parent
85695b659c
commit
b6838eb8c4
@ -126,7 +126,7 @@ class SymbolAtlas(object):
|
||||
keyi = None
|
||||
sourceRecti = None
|
||||
for i, rec in enumerate(opts):
|
||||
key = (rec[3], rec[2], id(rec[4]), id(rec[5])) # TODO: use string indexes?
|
||||
key = (id(rec[3]), rec[2], id(rec[4]), id(rec[5])) # TODO: use string indexes?
|
||||
if key == keyi:
|
||||
sourceRect[i] = sourceRecti
|
||||
else:
|
||||
@ -136,6 +136,7 @@ class SymbolAtlas(object):
|
||||
newRectSrc = QtCore.QRectF()
|
||||
newRectSrc.pen = rec['pen']
|
||||
newRectSrc.brush = rec['brush']
|
||||
newRectSrc.symbol = rec[3]
|
||||
self.symbolMap[key] = newRectSrc
|
||||
self.atlasValid = False
|
||||
sourceRect[i] = newRectSrc
|
||||
@ -151,7 +152,7 @@ class SymbolAtlas(object):
|
||||
images = []
|
||||
for key, sourceRect in self.symbolMap.items():
|
||||
if sourceRect.width() == 0:
|
||||
img = renderSymbol(key[0], key[1], sourceRect.pen, sourceRect.brush)
|
||||
img = renderSymbol(sourceRect.symbol, key[1], sourceRect.pen, sourceRect.brush)
|
||||
images.append(img) ## we only need this to prevent the images being garbage collected immediately
|
||||
arr = fn.imageToArray(img, copy=False, transpose=False)
|
||||
else:
|
||||
|
@ -1,3 +1,4 @@
|
||||
from pyqtgraph.Qt import QtGui, QtCore
|
||||
import pyqtgraph as pg
|
||||
import numpy as np
|
||||
app = pg.mkQApp()
|
||||
@ -10,6 +11,13 @@ def test_scatterplotitem():
|
||||
# set view range equal to its bounding rect.
|
||||
# This causes plots to look the same regardless of pxMode.
|
||||
plot.setRange(rect=plot.boundingRect())
|
||||
|
||||
# test SymbolAtlas accepts custom symbol
|
||||
s = pg.ScatterPlotItem()
|
||||
symbol = QtGui.QPainterPath()
|
||||
symbol.addEllipse(QtCore.QRectF(-0.5, -0.5, 1, 1))
|
||||
s.addPoints([{'pos': [0,0], 'data': 1, 'symbol': symbol}])
|
||||
|
||||
for i, pxMode in enumerate([True, False]):
|
||||
for j, useCache in enumerate([True, False]):
|
||||
s = pg.ScatterPlotItem()
|
||||
|
Loading…
Reference in New Issue
Block a user