PlotItem.showValues fixed (was not implemented before).
This commit is contained in:
parent
c8f03e828e
commit
22ecd3cc41
@ -775,92 +775,92 @@ class AxisItem(GraphicsWidget):
|
|||||||
textSize2 = 0
|
textSize2 = 0
|
||||||
textRects = []
|
textRects = []
|
||||||
textSpecs = [] ## list of draw
|
textSpecs = [] ## list of draw
|
||||||
textSize2 = 0
|
if self.showValues:
|
||||||
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:
|
||||||
spacing, values = tickLevels[i]
|
spacing, values = tickLevels[i]
|
||||||
strings = self.tickStrings(values, self.autoSIPrefixScale * self.scale, spacing)
|
strings = self.tickStrings(values, self.autoSIPrefixScale * self.scale, spacing)
|
||||||
else:
|
|
||||||
strings = tickStrings[i]
|
|
||||||
|
|
||||||
if len(strings) == 0:
|
|
||||||
continue
|
|
||||||
|
|
||||||
## ignore strings belonging to ticks that were previously ignored
|
|
||||||
for j in range(len(strings)):
|
|
||||||
if tickPositions[i][j] is None:
|
|
||||||
strings[j] = None
|
|
||||||
|
|
||||||
## Measure density of text; decide whether to draw this level
|
|
||||||
rects = []
|
|
||||||
for s in strings:
|
|
||||||
if s is None:
|
|
||||||
rects.append(None)
|
|
||||||
else:
|
else:
|
||||||
br = p.boundingRect(QtCore.QRectF(0, 0, 100, 100), QtCore.Qt.AlignCenter, asUnicode(s))
|
strings = tickStrings[i]
|
||||||
## boundingRect is usually just a bit too large
|
|
||||||
## (but this probably depends on per-font metrics?)
|
|
||||||
br.setHeight(br.height() * 0.8)
|
|
||||||
|
|
||||||
rects.append(br)
|
if len(strings) == 0:
|
||||||
textRects.append(rects[-1])
|
|
||||||
|
|
||||||
if i > 0: ## always draw top level
|
|
||||||
## measure all text, make sure there's enough room
|
|
||||||
if axis == 0:
|
|
||||||
textSize = np.sum([r.height() for r in textRects])
|
|
||||||
textSize2 = np.max([r.width() for r in textRects]) if textRects else 0
|
|
||||||
else:
|
|
||||||
textSize = np.sum([r.width() for r in textRects])
|
|
||||||
textSize2 = np.max([r.height() for r in textRects]) if textRects else 0
|
|
||||||
|
|
||||||
## If the strings are too crowded, stop drawing text now.
|
|
||||||
## We use three different crowding limits based on the number
|
|
||||||
## of texts drawn so far.
|
|
||||||
textFillRatio = float(textSize) / lengthInPixels
|
|
||||||
finished = False
|
|
||||||
for nTexts, limit in self.style['textFillLimits']:
|
|
||||||
if len(textSpecs) >= nTexts and textFillRatio >= limit:
|
|
||||||
finished = True
|
|
||||||
break
|
|
||||||
if finished:
|
|
||||||
break
|
|
||||||
|
|
||||||
#spacing, values = tickLevels[best]
|
|
||||||
#strings = self.tickStrings(values, self.scale, spacing)
|
|
||||||
for j in range(len(strings)):
|
|
||||||
vstr = strings[j]
|
|
||||||
if vstr is None: ## this tick was ignored because it is out of bounds
|
|
||||||
continue
|
continue
|
||||||
vstr = asUnicode(vstr)
|
|
||||||
x = tickPositions[i][j]
|
## ignore strings belonging to ticks that were previously ignored
|
||||||
#textRect = p.boundingRect(QtCore.QRectF(0, 0, 100, 100), QtCore.Qt.AlignCenter, vstr)
|
for j in range(len(strings)):
|
||||||
textRect = rects[j]
|
if tickPositions[i][j] is None:
|
||||||
height = textRect.height()
|
strings[j] = None
|
||||||
width = textRect.width()
|
|
||||||
#self.textHeight = height
|
## Measure density of text; decide whether to draw this level
|
||||||
offset = max(0,self.tickLength) + textOffset
|
rects = []
|
||||||
if self.orientation == 'left':
|
for s in strings:
|
||||||
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter
|
if s is None:
|
||||||
rect = QtCore.QRectF(tickStop-offset-width, x-(height/2), width, height)
|
rects.append(None)
|
||||||
elif self.orientation == 'right':
|
else:
|
||||||
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter
|
br = p.boundingRect(QtCore.QRectF(0, 0, 100, 100), QtCore.Qt.AlignCenter, asUnicode(s))
|
||||||
rect = QtCore.QRectF(tickStop+offset, x-(height/2), width, height)
|
## boundingRect is usually just a bit too large
|
||||||
elif self.orientation == 'top':
|
## (but this probably depends on per-font metrics?)
|
||||||
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignCenter|QtCore.Qt.AlignBottom
|
br.setHeight(br.height() * 0.8)
|
||||||
rect = QtCore.QRectF(x-width/2., tickStop-offset-height, width, height)
|
|
||||||
elif self.orientation == 'bottom':
|
rects.append(br)
|
||||||
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignCenter|QtCore.Qt.AlignTop
|
textRects.append(rects[-1])
|
||||||
rect = QtCore.QRectF(x-width/2., tickStop+offset, width, height)
|
|
||||||
|
if i > 0: ## always draw top level
|
||||||
#p.setPen(self.pen())
|
## measure all text, make sure there's enough room
|
||||||
#p.drawText(rect, textFlags, vstr)
|
if axis == 0:
|
||||||
textSpecs.append((rect, textFlags, vstr))
|
textSize = np.sum([r.height() for r in textRects])
|
||||||
profiler('compute text')
|
textSize2 = np.max([r.width() for r in textRects]) if textRects else 0
|
||||||
|
else:
|
||||||
## update max text size if needed.
|
textSize = np.sum([r.width() for r in textRects])
|
||||||
self._updateMaxTextSize(textSize2)
|
textSize2 = np.max([r.height() for r in textRects]) if textRects else 0
|
||||||
|
|
||||||
|
## If the strings are too crowded, stop drawing text now.
|
||||||
|
## We use three different crowding limits based on the number
|
||||||
|
## of texts drawn so far.
|
||||||
|
textFillRatio = float(textSize) / lengthInPixels
|
||||||
|
finished = False
|
||||||
|
for nTexts, limit in self.style['textFillLimits']:
|
||||||
|
if len(textSpecs) >= nTexts and textFillRatio >= limit:
|
||||||
|
finished = True
|
||||||
|
break
|
||||||
|
if finished:
|
||||||
|
break
|
||||||
|
|
||||||
|
#spacing, values = tickLevels[best]
|
||||||
|
#strings = self.tickStrings(values, self.scale, spacing)
|
||||||
|
for j in range(len(strings)):
|
||||||
|
vstr = strings[j]
|
||||||
|
if vstr is None: ## this tick was ignored because it is out of bounds
|
||||||
|
continue
|
||||||
|
vstr = asUnicode(vstr)
|
||||||
|
x = tickPositions[i][j]
|
||||||
|
#textRect = p.boundingRect(QtCore.QRectF(0, 0, 100, 100), QtCore.Qt.AlignCenter, vstr)
|
||||||
|
textRect = rects[j]
|
||||||
|
height = textRect.height()
|
||||||
|
width = textRect.width()
|
||||||
|
#self.textHeight = height
|
||||||
|
offset = max(0,self.tickLength) + textOffset
|
||||||
|
if self.orientation == 'left':
|
||||||
|
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter
|
||||||
|
rect = QtCore.QRectF(tickStop-offset-width, x-(height/2), width, height)
|
||||||
|
elif self.orientation == 'right':
|
||||||
|
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter
|
||||||
|
rect = QtCore.QRectF(tickStop+offset, x-(height/2), width, height)
|
||||||
|
elif self.orientation == 'top':
|
||||||
|
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignCenter|QtCore.Qt.AlignBottom
|
||||||
|
rect = QtCore.QRectF(x-width/2., tickStop-offset-height, width, height)
|
||||||
|
elif self.orientation == 'bottom':
|
||||||
|
textFlags = QtCore.Qt.TextDontClip|QtCore.Qt.AlignCenter|QtCore.Qt.AlignTop
|
||||||
|
rect = QtCore.QRectF(x-width/2., tickStop+offset, width, height)
|
||||||
|
|
||||||
|
#p.setPen(self.pen())
|
||||||
|
#p.drawText(rect, textFlags, vstr)
|
||||||
|
textSpecs.append((rect, textFlags, vstr))
|
||||||
|
profiler('compute text')
|
||||||
|
|
||||||
|
## update max text size if needed.
|
||||||
|
self._updateMaxTextSize(textSize2)
|
||||||
|
|
||||||
return (axisSpec, tickSpecs, textSpecs)
|
return (axisSpec, tickSpecs, textSpecs)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user