commit
43328eb053
@ -56,6 +56,7 @@ class AxisItem(GraphicsWidget):
|
|||||||
'tickTextWidth': 30, ## space reserved for tick text
|
'tickTextWidth': 30, ## space reserved for tick text
|
||||||
'tickTextHeight': 18,
|
'tickTextHeight': 18,
|
||||||
'autoExpandTextSpace': True, ## automatically expand text space if needed
|
'autoExpandTextSpace': True, ## automatically expand text space if needed
|
||||||
|
'autoReduceTextSpace': True,
|
||||||
'tickFont': None,
|
'tickFont': None,
|
||||||
'stopAxisAtTick': (False, False), ## whether axis is drawn to edge of box or to last tick
|
'stopAxisAtTick': (False, False), ## whether axis is drawn to edge of box or to last tick
|
||||||
'textFillLimits': [ ## how much of the axis to fill up with tick text, maximally.
|
'textFillLimits': [ ## how much of the axis to fill up with tick text, maximally.
|
||||||
@ -125,6 +126,7 @@ class AxisItem(GraphicsWidget):
|
|||||||
tickTextHeight (int) Vertical space reserved for tick text in px
|
tickTextHeight (int) Vertical space reserved for tick text in px
|
||||||
autoExpandTextSpace (bool) Automatically expand text space if the tick
|
autoExpandTextSpace (bool) Automatically expand text space if the tick
|
||||||
strings become too long.
|
strings become too long.
|
||||||
|
autoReduceTextSpace (bool) Automatically shrink the axis if necessary
|
||||||
tickFont (QFont or None) Determines the font used for tick
|
tickFont (QFont or None) Determines the font used for tick
|
||||||
values. Use None for the default font.
|
values. Use None for the default font.
|
||||||
stopAxisAtTick (tuple: (bool min, bool max)) If True, the axis
|
stopAxisAtTick (tuple: (bool min, bool max)) If True, the axis
|
||||||
@ -314,19 +316,26 @@ class AxisItem(GraphicsWidget):
|
|||||||
## changed; we use this to decide whether the item needs to be resized
|
## changed; we use this to decide whether the item needs to be resized
|
||||||
## to accomodate.
|
## to accomodate.
|
||||||
if self.orientation in ['left', 'right']:
|
if self.orientation in ['left', 'right']:
|
||||||
mx = max(self.textWidth, x)
|
if self.style["autoReduceTextSpace"]:
|
||||||
if mx > self.textWidth or mx < self.textWidth-10:
|
if x > self.textWidth or x < self.textWidth - 10:
|
||||||
self.textWidth = mx
|
self.textWidth = x
|
||||||
if self.style['autoExpandTextSpace'] is True:
|
else:
|
||||||
self._updateWidth()
|
mx = max(self.textWidth, x)
|
||||||
#return True ## size has changed
|
if mx > self.textWidth or mx < self.textWidth - 10:
|
||||||
|
self.textWidth = mx
|
||||||
|
if self.style['autoExpandTextSpace']:
|
||||||
|
self._updateWidth()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
mx = max(self.textHeight, x)
|
if self.style['autoReduceTextSpace']:
|
||||||
if mx > self.textHeight or mx < self.textHeight-10:
|
if x > self.textHeight or x < self.textHeight - 10:
|
||||||
self.textHeight = mx
|
self.textHeight = x
|
||||||
if self.style['autoExpandTextSpace'] is True:
|
else:
|
||||||
self._updateHeight()
|
mx = max(self.textHeight, x)
|
||||||
#return True ## size has changed
|
if mx > self.textHeight or mx < self.textHeight - 10:
|
||||||
|
self.textHeight = mx
|
||||||
|
if self.style['autoExpandTextSpace']:
|
||||||
|
self._updateHeight()
|
||||||
|
|
||||||
def _adjustSize(self):
|
def _adjustSize(self):
|
||||||
if self.orientation in ['left', 'right']:
|
if self.orientation in ['left', 'right']:
|
||||||
@ -350,7 +359,7 @@ class AxisItem(GraphicsWidget):
|
|||||||
if self.fixedHeight is None:
|
if self.fixedHeight is None:
|
||||||
if not self.style['showValues']:
|
if not self.style['showValues']:
|
||||||
h = 0
|
h = 0
|
||||||
elif self.style['autoExpandTextSpace'] is True:
|
elif self.style['autoExpandTextSpace']:
|
||||||
h = self.textHeight
|
h = self.textHeight
|
||||||
else:
|
else:
|
||||||
h = self.style['tickTextHeight']
|
h = self.style['tickTextHeight']
|
||||||
@ -381,7 +390,7 @@ class AxisItem(GraphicsWidget):
|
|||||||
if self.fixedWidth is None:
|
if self.fixedWidth is None:
|
||||||
if not self.style['showValues']:
|
if not self.style['showValues']:
|
||||||
w = 0
|
w = 0
|
||||||
elif self.style['autoExpandTextSpace'] is True:
|
elif self.style['autoExpandTextSpace']:
|
||||||
w = self.textWidth
|
w = self.textWidth
|
||||||
else:
|
else:
|
||||||
w = self.style['tickTextWidth']
|
w = self.style['tickTextWidth']
|
||||||
@ -1001,6 +1010,7 @@ class AxisItem(GraphicsWidget):
|
|||||||
#textHeight = self.style['tickTextHeight'] ## space allocated for horizontal text
|
#textHeight = self.style['tickTextHeight'] ## space allocated for horizontal text
|
||||||
|
|
||||||
textSize2 = 0
|
textSize2 = 0
|
||||||
|
lastTextSize2 = 0
|
||||||
textRects = []
|
textRects = []
|
||||||
textSpecs = [] ## list of draw
|
textSpecs = [] ## list of draw
|
||||||
|
|
||||||
@ -1063,6 +1073,8 @@ class AxisItem(GraphicsWidget):
|
|||||||
if finished:
|
if finished:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
lastTextSize2 = textSize2
|
||||||
|
|
||||||
#spacing, values = tickLevels[best]
|
#spacing, values = tickLevels[best]
|
||||||
#strings = self.tickStrings(values, self.scale, spacing)
|
#strings = self.tickStrings(values, self.scale, spacing)
|
||||||
# Determine exactly where tick text should be drawn
|
# Determine exactly where tick text should be drawn
|
||||||
@ -1097,7 +1109,7 @@ class AxisItem(GraphicsWidget):
|
|||||||
profiler('compute text')
|
profiler('compute text')
|
||||||
|
|
||||||
## update max text size if needed.
|
## update max text size if needed.
|
||||||
self._updateMaxTextSize(textSize2)
|
self._updateMaxTextSize(lastTextSize2)
|
||||||
|
|
||||||
return (axisSpec, tickSpecs, textSpecs)
|
return (axisSpec, tickSpecs, textSpecs)
|
||||||
|
|
||||||
|
@ -21,19 +21,19 @@ def test_ErrorBarItem_defer_data():
|
|||||||
app.processEvents()
|
app.processEvents()
|
||||||
r_empty_ebi = plot.viewRect()
|
r_empty_ebi = plot.viewRect()
|
||||||
|
|
||||||
assert r_no_ebi == r_empty_ebi
|
assert r_no_ebi.height() == r_empty_ebi.height()
|
||||||
|
|
||||||
err.setData(x=x, y=x, bottom=x, top=x)
|
err.setData(x=x, y=x, bottom=x, top=x)
|
||||||
app.processEvents()
|
app.processEvents()
|
||||||
r_ebi = plot.viewRect()
|
r_ebi = plot.viewRect()
|
||||||
|
|
||||||
assert r_empty_ebi != r_ebi
|
assert r_ebi.height() > r_empty_ebi.height()
|
||||||
|
|
||||||
# unset data, ErrorBarItem disappears and view rect goes back to original
|
# unset data, ErrorBarItem disappears and view rect goes back to original
|
||||||
err.setData(x=None, y=None)
|
err.setData(x=None, y=None)
|
||||||
app.processEvents()
|
app.processEvents()
|
||||||
r_clear_ebi = plot.viewRect()
|
r_clear_ebi = plot.viewRect()
|
||||||
|
|
||||||
assert r_clear_ebi == r_no_ebi
|
assert r_clear_ebi.height() == r_empty_ebi.height()
|
||||||
|
|
||||||
plot.close()
|
plot.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user