Correct id-based keying of scatter plot pixmap cache (#1564)
* Correct id-based keying of scatter plot pixmap cache Note: naively using the id function results in non-unique keys. Alternatively, we could serialize the Qt objects and use these in the key. This would provide protection from the user mutating these later, but at a cost to performance. * Make id attribute private * Access class variable instead of instance
This commit is contained in:
parent
44454358f6
commit
aed2382e38
@ -5,6 +5,7 @@ try:
|
||||
from itertools import imap
|
||||
except ImportError:
|
||||
imap = map
|
||||
import itertools
|
||||
import numpy as np
|
||||
import weakref
|
||||
from ..Qt import QtGui, QtCore, QT_LIB
|
||||
@ -161,6 +162,8 @@ class SymbolAtlas(object):
|
||||
pm = atlas.pixmap
|
||||
|
||||
"""
|
||||
_idGenerator = itertools.count()
|
||||
|
||||
def __init__(self):
|
||||
self._data = np.zeros((0, 0, 4), dtype=np.ubyte) # numpy array of atlas image
|
||||
self._coords = {}
|
||||
@ -224,13 +227,16 @@ class SymbolAtlas(object):
|
||||
squareness=1.0 if n == 0 else 2 * w * h / (w**2 + h**2))
|
||||
|
||||
def _keys(self, styles):
|
||||
def getId(obj):
|
||||
try:
|
||||
return obj._id
|
||||
except AttributeError:
|
||||
obj._id = next(SymbolAtlas._idGenerator)
|
||||
return obj._id
|
||||
|
||||
return [
|
||||
(
|
||||
symbol if isinstance(symbol, (str, int)) else f"{symbol.boundingRect()} + {symbol.elementCount()} elements",
|
||||
size,
|
||||
(pen.style(), pen.capStyle(), pen.joinStyle()),
|
||||
(brush.color().rgba(), brush.style())
|
||||
) for symbol, size, pen, brush in styles
|
||||
(symbol if isinstance(symbol, (str, int)) else getId(symbol), size, getId(pen), getId(brush))
|
||||
for symbol, size, pen, brush in styles
|
||||
]
|
||||
|
||||
def _itemData(self, keys):
|
||||
|
Loading…
Reference in New Issue
Block a user