From 899663c6ca18f8375b5089d74c19c131f58cf0ba Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Thu, 24 Jan 2013 13:47:05 -0500 Subject: [PATCH] bugfixes for scatterplot boundary miss added method for setting axis tick font --- pyqtgraph/graphicsItems/AxisItem.py | 33 +++++++++++++++++----- pyqtgraph/graphicsItems/GraphicsItem.py | 2 +- pyqtgraph/graphicsItems/ScatterPlotItem.py | 5 +++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index aba5fa8c..8d8ed11b 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -58,13 +58,14 @@ class AxisItem(GraphicsWidget): self.labelUnitPrefix='' self.labelStyle = {} self.logMode = False + self.tickFont = None self.textHeight = 18 self.tickLength = maxTickLength self._tickLevels = None ## used to override the automatic ticking system with explicit ticks self.scale = 1.0 self.autoScale = True - + self.setRange(0, 1) self.setPen(pen) @@ -72,12 +73,12 @@ class AxisItem(GraphicsWidget): self._linkedView = None if linkView is not None: self.linkToView(linkView) - + self.showLabel(False) self.grid = False #self.setCacheMode(self.DeviceCoordinateCache) - + def close(self): self.scene().removeItem(self.label) self.label = None @@ -100,6 +101,14 @@ class AxisItem(GraphicsWidget): self.picture = None 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): #s = self.size() @@ -287,14 +296,21 @@ class AxisItem(GraphicsWidget): if linkedView is None or self.grid is False: rect = self.mapRectFromParent(self.geometry()) ## extend rect if ticks go in negative direction + ## also extend to account for text that flows past the edges 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': - 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': - 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': - 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 else: return self.mapRectFromParent(self.geometry()) | linkedView.mapRectToItem(self, linkedView.boundingRect()) @@ -623,6 +639,9 @@ class AxisItem(GraphicsWidget): prof.mark('draw ticks') ## Draw text until there is no more room (or no more text) + if self.tickFont is not None: + p.setFont(self.tickFont) + textRects = [] for i in range(len(tickLevels)): ## Get the list of strings to display for this level diff --git a/pyqtgraph/graphicsItems/GraphicsItem.py b/pyqtgraph/graphicsItems/GraphicsItem.py index 94615fe3..75e72177 100644 --- a/pyqtgraph/graphicsItems/GraphicsItem.py +++ b/pyqtgraph/graphicsItems/GraphicsItem.py @@ -202,7 +202,7 @@ class GraphicsItem(object): ## check global cache key = (dt.m11(), dt.m21(), dt.m31(), dt.m12(), dt.m22(), dt.m32(), dt.m31(), dt.m32()) pv = self._pixelVectorGlobalCache.get(key, None) - if pv is not None: + if direction is None and pv is not None: self._pixelVectorCache = [dt, pv] return tuple(map(Point,pv)) ## return a *copy* diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index 0b422596..d606cfdf 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -620,9 +620,12 @@ class ScatterPlotItem(GraphicsObject): if frac >= 1.0: ## 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: px = 0 + else: + px = px.length() minIndex = np.argmin(d) maxIndex = np.argmax(d) minVal = d[minIndex]