Fixed AxisItem.__init__(showValues=False)

Merge branch 'JNevrly-showValues_fix' into develop
This commit is contained in:
Luke Campagnola 2014-03-29 11:32:52 -04:00
commit 27f7ef7205
3 changed files with 19 additions and 10 deletions

View File

@ -78,6 +78,7 @@ pyqtgraph-0.9.9 [unreleased]
- Fixed multiprocess deadlocks on windows - Fixed multiprocess deadlocks on windows
- Fixed GLGridItem.setSize - Fixed GLGridItem.setSize
- Fixed parametertree.Parameter.sigValueChanging - Fixed parametertree.Parameter.sigValueChanging
- Fixed AxisItem.__init__(showValues=False)
pyqtgraph-0.9.8 2013-11-24 pyqtgraph-0.9.8 2013-11-24

View File

@ -33,7 +33,6 @@ class AxisItem(GraphicsWidget):
GraphicsWidget.__init__(self, parent) GraphicsWidget.__init__(self, parent)
self.label = QtGui.QGraphicsTextItem(self) self.label = QtGui.QGraphicsTextItem(self)
self.showValues = showValues
self.picture = None self.picture = None
self.orientation = orientation self.orientation = orientation
if orientation not in ['left', 'right', 'top', 'bottom']: if orientation not in ['left', 'right', 'top', 'bottom']:
@ -53,7 +52,8 @@ class AxisItem(GraphicsWidget):
(2, 0.6), ## If we already have 2 ticks with text, fill no more than 60% of the axis (2, 0.6), ## If we already have 2 ticks with text, fill no more than 60% of the axis
(4, 0.4), ## If we already have 4 ticks with text, fill no more than 40% of the axis (4, 0.4), ## If we already have 4 ticks with text, fill no more than 40% of the axis
(6, 0.2), ## If we already have 6 ticks with text, fill no more than 20% of the axis (6, 0.2), ## If we already have 6 ticks with text, fill no more than 20% of the axis
] ],
'showValues': showValues,
} }
self.textWidth = 30 ## Keeps track of maximum width / height of tick text self.textWidth = 30 ## Keeps track of maximum width / height of tick text
@ -242,27 +242,31 @@ class AxisItem(GraphicsWidget):
"""Set the height of this axis reserved for ticks and tick labels. """Set the height of this axis reserved for ticks and tick labels.
The height of the axis label is automatically added.""" The height of the axis label is automatically added."""
if h is None: if h is None:
if self.style['autoExpandTextSpace'] is True: if not self.style['showValues']:
h = 0
elif self.style['autoExpandTextSpace'] is True:
h = self.textHeight h = self.textHeight
else: else:
h = self.style['tickTextHeight'] h = self.style['tickTextHeight']
h += max(0, self.tickLength) + self.style['tickTextOffset'][1] textOffset = self.style['tickTextOffset'][1] if self.style['showValues'] else 0
h += max(0, self.tickLength) + textOffset
if self.label.isVisible(): if self.label.isVisible():
h += self.label.boundingRect().height() * 0.8 h += self.label.boundingRect().height() * 0.8
self.setMaximumHeight(h) self.setMaximumHeight(h)
self.setMinimumHeight(h) self.setMinimumHeight(h)
self.picture = None self.picture = None
def setWidth(self, w=None): def setWidth(self, w=None):
"""Set the width of this axis reserved for ticks and tick labels. """Set the width of this axis reserved for ticks and tick labels.
The width of the axis label is automatically added.""" The width of the axis label is automatically added."""
if w is None: if w is None:
if self.style['autoExpandTextSpace'] is True: if not self.style['showValues']:
w = 0
elif self.style['autoExpandTextSpace'] is True:
w = self.textWidth w = self.textWidth
else: else:
w = self.style['tickTextWidth'] w = self.style['tickTextWidth']
w += max(0, self.tickLength) + self.style['tickTextOffset'][0] textOffset = self.style['tickTextOffset'][0] if self.style['showValues'] else 0
if self.label.isVisible(): if self.label.isVisible():
w += self.label.boundingRect().height() * 0.8 ## bounding rect is usually an overestimate w += self.label.boundingRect().height() * 0.8 ## bounding rect is usually an overestimate
self.setMaximumWidth(w) self.setMaximumWidth(w)
@ -775,7 +779,11 @@ class AxisItem(GraphicsWidget):
textSize2 = 0 textSize2 = 0
textRects = [] textRects = []
textSpecs = [] ## list of draw textSpecs = [] ## list of draw
textSize2 = 0
# If values are hidden, return early
if not self.style['showValues']:
return (axisSpec, tickSpecs, textSpecs)
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
if tickStrings is None: if tickStrings is None:
@ -858,7 +866,7 @@ class AxisItem(GraphicsWidget):
#p.drawText(rect, textFlags, vstr) #p.drawText(rect, textFlags, vstr)
textSpecs.append((rect, textFlags, vstr)) textSpecs.append((rect, textFlags, vstr))
profiler('compute text') profiler('compute text')
## update max text size if needed. ## update max text size if needed.
self._updateMaxTextSize(textSize2) self._updateMaxTextSize(textSize2)

View File

@ -58,7 +58,7 @@ class HistogramLUTItem(GraphicsWidget):
self.region = LinearRegionItem([0, 1], LinearRegionItem.Horizontal) self.region = LinearRegionItem([0, 1], LinearRegionItem.Horizontal)
self.region.setZValue(1000) self.region.setZValue(1000)
self.vb.addItem(self.region) self.vb.addItem(self.region)
self.axis = AxisItem('left', linkView=self.vb, maxTickLength=-10, showValues=False) self.axis = AxisItem('left', linkView=self.vb, maxTickLength=-10)
self.layout.addItem(self.axis, 0, 0) self.layout.addItem(self.axis, 0, 0)
self.layout.addItem(self.vb, 0, 1) self.layout.addItem(self.vb, 0, 1)
self.layout.addItem(self.gradient, 0, 2) self.layout.addItem(self.gradient, 0, 2)