bugfixes for scatterplot boundary miss

added method for setting axis tick font
This commit is contained in:
Luke Campagnola 2013-01-24 13:47:05 -05:00
parent d75850e324
commit 899663c6ca
3 changed files with 31 additions and 9 deletions

View File

@ -58,13 +58,14 @@ class AxisItem(GraphicsWidget):
self.labelUnitPrefix='' self.labelUnitPrefix=''
self.labelStyle = {} self.labelStyle = {}
self.logMode = False self.logMode = False
self.tickFont = None
self.textHeight = 18 self.textHeight = 18
self.tickLength = maxTickLength self.tickLength = maxTickLength
self._tickLevels = None ## used to override the automatic ticking system with explicit ticks self._tickLevels = None ## used to override the automatic ticking system with explicit ticks
self.scale = 1.0 self.scale = 1.0
self.autoScale = True self.autoScale = True
self.setRange(0, 1) self.setRange(0, 1)
self.setPen(pen) self.setPen(pen)
@ -72,12 +73,12 @@ class AxisItem(GraphicsWidget):
self._linkedView = None self._linkedView = None
if linkView is not None: if linkView is not None:
self.linkToView(linkView) self.linkToView(linkView)
self.showLabel(False) self.showLabel(False)
self.grid = False self.grid = False
#self.setCacheMode(self.DeviceCoordinateCache) #self.setCacheMode(self.DeviceCoordinateCache)
def close(self): def close(self):
self.scene().removeItem(self.label) self.scene().removeItem(self.label)
self.label = None self.label = None
@ -100,6 +101,14 @@ class AxisItem(GraphicsWidget):
self.picture = None self.picture = None
self.update() self.update()
def setTickFont(self, font):
self.tickFont = font
self.picture = None
self.prepareGeometryChange()
## Need to re-allocate space depending on font size?
self.update()
def resizeEvent(self, ev=None): def resizeEvent(self, ev=None):
#s = self.size() #s = self.size()
@ -287,14 +296,21 @@ class AxisItem(GraphicsWidget):
if linkedView is None or self.grid is False: if linkedView is None or self.grid is False:
rect = self.mapRectFromParent(self.geometry()) rect = self.mapRectFromParent(self.geometry())
## extend rect if ticks go in negative direction ## extend rect if ticks go in negative direction
## also extend to account for text that flows past the edges
if self.orientation == 'left': if self.orientation == 'left':
rect.setRight(rect.right() - min(0,self.tickLength)) #rect.setRight(rect.right() - min(0,self.tickLength))
#rect.setTop(rect.top() - 15)
#rect.setBottom(rect.bottom() + 15)
rect = rect.adjusted(0, -15, -min(0,self.tickLength), 15)
elif self.orientation == 'right': elif self.orientation == 'right':
rect.setLeft(rect.left() + min(0,self.tickLength)) #rect.setLeft(rect.left() + min(0,self.tickLength))
rect = rect.adjusted(min(0,self.tickLength), -15, 0, 15)
elif self.orientation == 'top': elif self.orientation == 'top':
rect.setBottom(rect.bottom() - min(0,self.tickLength)) #rect.setBottom(rect.bottom() - min(0,self.tickLength))
rect = rect.adjusted(-15, 0, 15, -min(0,self.tickLength))
elif self.orientation == 'bottom': elif self.orientation == 'bottom':
rect.setTop(rect.top() + min(0,self.tickLength)) #rect.setTop(rect.top() + min(0,self.tickLength))
rect = rect.adjusted(-15, min(0,self.tickLength), 15, 0)
return rect return rect
else: else:
return self.mapRectFromParent(self.geometry()) | linkedView.mapRectToItem(self, linkedView.boundingRect()) return self.mapRectFromParent(self.geometry()) | linkedView.mapRectToItem(self, linkedView.boundingRect())
@ -623,6 +639,9 @@ class AxisItem(GraphicsWidget):
prof.mark('draw ticks') prof.mark('draw ticks')
## Draw text until there is no more room (or no more text) ## Draw text until there is no more room (or no more text)
if self.tickFont is not None:
p.setFont(self.tickFont)
textRects = [] textRects = []
for i in range(len(tickLevels)): for i in range(len(tickLevels)):
## Get the list of strings to display for this level ## Get the list of strings to display for this level

View File

@ -202,7 +202,7 @@ class GraphicsItem(object):
## check global cache ## check global cache
key = (dt.m11(), dt.m21(), dt.m31(), dt.m12(), dt.m22(), dt.m32(), dt.m31(), dt.m32()) key = (dt.m11(), dt.m21(), dt.m31(), dt.m12(), dt.m22(), dt.m32(), dt.m31(), dt.m32())
pv = self._pixelVectorGlobalCache.get(key, None) pv = self._pixelVectorGlobalCache.get(key, None)
if pv is not None: if direction is None and pv is not None:
self._pixelVectorCache = [dt, pv] self._pixelVectorCache = [dt, pv]
return tuple(map(Point,pv)) ## return a *copy* return tuple(map(Point,pv)) ## return a *copy*

View File

@ -620,9 +620,12 @@ class ScatterPlotItem(GraphicsObject):
if frac >= 1.0: if frac >= 1.0:
## increase size of bounds based on spot size and pen width ## increase size of bounds based on spot size and pen width
px = self.pixelLength(Point(1, 0) if ax == 0 else Point(0, 1)) ## determine length of pixel along this axis #px = self.pixelLength(Point(1, 0) if ax == 0 else Point(0, 1)) ## determine length of pixel along this axis
px = self.pixelVectors()[ax]
if px is None: if px is None:
px = 0 px = 0
else:
px = px.length()
minIndex = np.argmin(d) minIndex = np.argmin(d)
maxIndex = np.argmax(d) maxIndex = np.argmax(d)
minVal = d[minIndex] minVal = d[minIndex]