Merge pull request #1270 from j9ac9k/implement-pr-403

Implement pr 403
This commit is contained in:
Ogi Moore 2020-06-24 15:56:59 -07:00 committed by GitHub
commit 43328eb053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 18 deletions

View File

@ -56,6 +56,7 @@ class AxisItem(GraphicsWidget):
'tickTextWidth': 30, ## space reserved for tick text
'tickTextHeight': 18,
'autoExpandTextSpace': True, ## automatically expand text space if needed
'autoReduceTextSpace': True,
'tickFont': None,
'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.
@ -125,6 +126,7 @@ class AxisItem(GraphicsWidget):
tickTextHeight (int) Vertical space reserved for tick text in px
autoExpandTextSpace (bool) Automatically expand text space if the tick
strings become too long.
autoReduceTextSpace (bool) Automatically shrink the axis if necessary
tickFont (QFont or None) Determines the font used for tick
values. Use None for the default font.
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
## to accomodate.
if self.orientation in ['left', 'right']:
mx = max(self.textWidth, x)
if mx > self.textWidth or mx < self.textWidth-10:
self.textWidth = mx
if self.style['autoExpandTextSpace'] is True:
self._updateWidth()
#return True ## size has changed
if self.style["autoReduceTextSpace"]:
if x > self.textWidth or x < self.textWidth - 10:
self.textWidth = x
else:
mx = max(self.textWidth, x)
if mx > self.textWidth or mx < self.textWidth - 10:
self.textWidth = mx
if self.style['autoExpandTextSpace']:
self._updateWidth()
else:
mx = max(self.textHeight, x)
if mx > self.textHeight or mx < self.textHeight-10:
self.textHeight = mx
if self.style['autoExpandTextSpace'] is True:
self._updateHeight()
#return True ## size has changed
if self.style['autoReduceTextSpace']:
if x > self.textHeight or x < self.textHeight - 10:
self.textHeight = x
else:
mx = max(self.textHeight, x)
if mx > self.textHeight or mx < self.textHeight - 10:
self.textHeight = mx
if self.style['autoExpandTextSpace']:
self._updateHeight()
def _adjustSize(self):
if self.orientation in ['left', 'right']:
@ -350,7 +359,7 @@ class AxisItem(GraphicsWidget):
if self.fixedHeight is None:
if not self.style['showValues']:
h = 0
elif self.style['autoExpandTextSpace'] is True:
elif self.style['autoExpandTextSpace']:
h = self.textHeight
else:
h = self.style['tickTextHeight']
@ -381,7 +390,7 @@ class AxisItem(GraphicsWidget):
if self.fixedWidth is None:
if not self.style['showValues']:
w = 0
elif self.style['autoExpandTextSpace'] is True:
elif self.style['autoExpandTextSpace']:
w = self.textWidth
else:
w = self.style['tickTextWidth']
@ -1001,6 +1010,7 @@ class AxisItem(GraphicsWidget):
#textHeight = self.style['tickTextHeight'] ## space allocated for horizontal text
textSize2 = 0
lastTextSize2 = 0
textRects = []
textSpecs = [] ## list of draw
@ -1062,6 +1072,8 @@ class AxisItem(GraphicsWidget):
break
if finished:
break
lastTextSize2 = textSize2
#spacing, values = tickLevels[best]
#strings = self.tickStrings(values, self.scale, spacing)
@ -1097,7 +1109,7 @@ class AxisItem(GraphicsWidget):
profiler('compute text')
## update max text size if needed.
self._updateMaxTextSize(textSize2)
self._updateMaxTextSize(lastTextSize2)
return (axisSpec, tickSpecs, textSpecs)

View File

@ -21,19 +21,19 @@ def test_ErrorBarItem_defer_data():
app.processEvents()
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)
app.processEvents()
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
err.setData(x=None, y=None)
app.processEvents()
r_clear_ebi = plot.viewRect()
assert r_clear_ebi == r_no_ebi
assert r_clear_ebi.height() == r_empty_ebi.height()
plot.close()