scatterplot spots are clickable again

This commit is contained in:
Luke Campagnola 2012-10-16 20:54:42 -04:00
parent 5ce8d09aa0
commit 3a0d599d70

View File

@ -223,7 +223,7 @@ class ScatterPlotItem(GraphicsObject):
self.fragments = None # fragment specification for pxmode; updated every time the view changes. self.fragments = None # fragment specification for pxmode; updated every time the view changes.
self.fragmentAtlas = SymbolAtlas() self.fragmentAtlas = SymbolAtlas()
self.data = np.empty(0, dtype=[('x', float), ('y', float), ('size', float), ('symbol', object), ('pen', object), ('brush', object), ('data', object), ('fragCoords', object)]) self.data = np.empty(0, dtype=[('x', float), ('y', float), ('size', float), ('symbol', object), ('pen', object), ('brush', object), ('data', object), ('fragCoords', object), ('item', object)])
self.bounds = [None, None] ## caches data bounds self.bounds = [None, None] ## caches data bounds
self._maxSpotWidth = 0 ## maximum size of the scale-variant portion of all spots self._maxSpotWidth = 0 ## maximum size of the scale-variant portion of all spots
self._maxSpotPxWidth = 0 ## maximum size of the scale-invariant portion of all spots self._maxSpotPxWidth = 0 ## maximum size of the scale-invariant portion of all spots
@ -681,6 +681,9 @@ class ScatterPlotItem(GraphicsObject):
def points(self): def points(self):
for rec in self.data:
if rec['item'] is None:
rec['item'] = SpotItem(rec, self)
return self.data['item'] return self.data['item']
def pointsAt(self, pos): def pointsAt(self, pos):
@ -704,8 +707,8 @@ class ScatterPlotItem(GraphicsObject):
#else: #else:
#print "No hit:", (x, y), (sx, sy) #print "No hit:", (x, y), (sx, sy)
#print " ", (sx-s2x, sy-s2y), (sx+s2x, sy+s2y) #print " ", (sx-s2x, sy-s2y), (sx+s2x, sy+s2y)
pts.sort(lambda a,b: cmp(b.zValue(), a.zValue())) #pts.sort(lambda a,b: cmp(b.zValue(), a.zValue()))
return pts return pts[::-1]
def mouseClickEvent(self, ev): def mouseClickEvent(self, ev):
@ -722,100 +725,105 @@ class ScatterPlotItem(GraphicsObject):
ev.ignore() ev.ignore()
#class SpotItem(GraphicsItem): class SpotItem(object):
#""" """
#Class referring to individual spots in a scatter plot. Class referring to individual spots in a scatter plot.
#These can be retrieved by calling ScatterPlotItem.points() or These can be retrieved by calling ScatterPlotItem.points() or
#by connecting to the ScatterPlotItem's click signals. by connecting to the ScatterPlotItem's click signals.
#""" """
#def __init__(self, data, plot): def __init__(self, data, plot):
#GraphicsItem.__init__(self, register=False) #GraphicsItem.__init__(self, register=False)
#self._data = data self._data = data
#self._plot = plot self._plot = plot
##self._viewBox = None
##self._viewWidget = None
#self.setParentItem(plot) #self.setParentItem(plot)
#self.setPos(QtCore.QPointF(data['x'], data['y'])) #self.setPos(QtCore.QPointF(data['x'], data['y']))
#self.updateItem() #self.updateItem()
#def data(self): def data(self):
#"""Return the user data associated with this spot.""" """Return the user data associated with this spot."""
#return self._data['data'] return self._data['data']
#def size(self): def size(self):
#"""Return the size of this spot. """Return the size of this spot.
#If the spot has no explicit size set, then return the ScatterPlotItem's default size instead.""" If the spot has no explicit size set, then return the ScatterPlotItem's default size instead."""
#if self._data['size'] == -1: if self._data['size'] == -1:
#return self._plot.opts['size'] return self._plot.opts['size']
#else: else:
#return self._data['size'] return self._data['size']
#def setSize(self, size): def pos(self):
#"""Set the size of this spot. return Point(self._data['x'], self._data['y'])
#If the size is set to -1, then the ScatterPlotItem's default size
#will be used instead."""
#self._data['size'] = size
#self.updateItem()
#def symbol(self): def setSize(self, size):
#"""Return the symbol of this spot. """Set the size of this spot.
#If the spot has no explicit symbol set, then return the ScatterPlotItem's default symbol instead. If the size is set to -1, then the ScatterPlotItem's default size
#""" will be used instead."""
#symbol = self._data['symbol'] self._data['size'] = size
#if symbol is None: self.updateItem()
#symbol = self._plot.opts['symbol']
#try:
#n = int(symbol)
#symbol = list(Symbols.keys())[n % len(Symbols)]
#except:
#pass
#return symbol
#def setSymbol(self, symbol): def symbol(self):
#"""Set the symbol for this spot. """Return the symbol of this spot.
#If the symbol is set to '', then the ScatterPlotItem's default symbol will be used instead.""" If the spot has no explicit symbol set, then return the ScatterPlotItem's default symbol instead.
#self._data['symbol'] = symbol """
#self.updateItem() symbol = self._data['symbol']
if symbol is None:
symbol = self._plot.opts['symbol']
try:
n = int(symbol)
symbol = list(Symbols.keys())[n % len(Symbols)]
except:
pass
return symbol
def setSymbol(self, symbol):
"""Set the symbol for this spot.
If the symbol is set to '', then the ScatterPlotItem's default symbol will be used instead."""
self._data['symbol'] = symbol
self.updateItem()
#def pen(self): def pen(self):
#pen = self._data['pen'] pen = self._data['pen']
#if pen is None: if pen is None:
#pen = self._plot.opts['pen'] pen = self._plot.opts['pen']
#return fn.mkPen(pen) return fn.mkPen(pen)
#def setPen(self, *args, **kargs): def setPen(self, *args, **kargs):
#"""Set the outline pen for this spot""" """Set the outline pen for this spot"""
#pen = fn.mkPen(*args, **kargs) pen = fn.mkPen(*args, **kargs)
#self._data['pen'] = pen self._data['pen'] = pen
#self.updateItem() self.updateItem()
#def resetPen(self): def resetPen(self):
#"""Remove the pen set for this spot; the scatter plot's default pen will be used instead.""" """Remove the pen set for this spot; the scatter plot's default pen will be used instead."""
#self._data['pen'] = None ## Note this is NOT the same as calling setPen(None) self._data['pen'] = None ## Note this is NOT the same as calling setPen(None)
#self.updateItem() self.updateItem()
#def brush(self): def brush(self):
#brush = self._data['brush'] brush = self._data['brush']
#if brush is None: if brush is None:
#brush = self._plot.opts['brush'] brush = self._plot.opts['brush']
#return fn.mkBrush(brush) return fn.mkBrush(brush)
#def setBrush(self, *args, **kargs): def setBrush(self, *args, **kargs):
#"""Set the fill brush for this spot""" """Set the fill brush for this spot"""
#brush = fn.mkBrush(*args, **kargs) brush = fn.mkBrush(*args, **kargs)
#self._data['brush'] = brush self._data['brush'] = brush
#self.updateItem() self.updateItem()
#def resetBrush(self): def resetBrush(self):
#"""Remove the brush set for this spot; the scatter plot's default brush will be used instead.""" """Remove the brush set for this spot; the scatter plot's default brush will be used instead."""
#self._data['brush'] = None ## Note this is NOT the same as calling setBrush(None) self._data['brush'] = None ## Note this is NOT the same as calling setBrush(None)
#self.updateItem() self.updateItem()
#def setData(self, data): def setData(self, data):
#"""Set the user-data associated with this spot""" """Set the user-data associated with this spot"""
#self._data['data'] = data self._data['data'] = data
def updateItem(self):
self._data['fragCoords'] = None
self._plot.updateSpots([self._data])
self._plot.invalidate()
#class PixmapSpotItem(SpotItem, QtGui.QGraphicsPixmapItem): #class PixmapSpotItem(SpotItem, QtGui.QGraphicsPixmapItem):
#def __init__(self, data, plot): #def __init__(self, data, plot):