Commit a7b0bbb3 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Fixed AxisItem ignoring setWidth when label is displayed

parent c1f5c1bf
...@@ -62,6 +62,11 @@ class AxisItem(GraphicsWidget): ...@@ -62,6 +62,11 @@ class AxisItem(GraphicsWidget):
self.textWidth = 30 ## Keeps track of maximum width / height of tick text self.textWidth = 30 ## Keeps track of maximum width / height of tick text
self.textHeight = 18 self.textHeight = 18
# If the user specifies a width / height, remember that setting
# indefinitely.
self.fixedWidth = None
self.fixedHeight = None
self.labelText = '' self.labelText = ''
self.labelUnits = '' self.labelUnits = ''
self.labelUnitPrefix='' self.labelUnitPrefix=''
...@@ -219,9 +224,9 @@ class AxisItem(GraphicsWidget): ...@@ -219,9 +224,9 @@ class AxisItem(GraphicsWidget):
#self.drawLabel = show #self.drawLabel = show
self.label.setVisible(show) self.label.setVisible(show)
if self.orientation in ['left', 'right']: if self.orientation in ['left', 'right']:
self.setWidth() self._updateWidth()
else: else:
self.setHeight() self._updateHeight()
if self.autoSIPrefix: if self.autoSIPrefix:
self.updateAutoSIPrefix() self.updateAutoSIPrefix()
...@@ -291,54 +296,80 @@ class AxisItem(GraphicsWidget): ...@@ -291,54 +296,80 @@ class AxisItem(GraphicsWidget):
if mx > self.textWidth or mx < self.textWidth-10: if mx > self.textWidth or mx < self.textWidth-10:
self.textWidth = mx self.textWidth = mx
if self.style['autoExpandTextSpace'] is True: if self.style['autoExpandTextSpace'] is True:
self.setWidth() self._updateWidth()
#return True ## size has changed #return True ## size has changed
else: else:
mx = max(self.textHeight, x) mx = max(self.textHeight, x)
if mx > self.textHeight or mx < self.textHeight-10: if mx > self.textHeight or mx < self.textHeight-10:
self.textHeight = mx self.textHeight = mx
if self.style['autoExpandTextSpace'] is True: if self.style['autoExpandTextSpace'] is True:
self.setHeight() self._updateHeight()
#return True ## size has changed #return True ## size has changed
def _adjustSize(self): def _adjustSize(self):
if self.orientation in ['left', 'right']: if self.orientation in ['left', 'right']:
self.setWidth() self._updateWidth()
else: else:
self.setHeight() self._updateHeight()
def setHeight(self, h=None): def setHeight(self, h=None):
"""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 not self.style['showValues']: If *height* is None, then the value will be determined automatically
h = 0 based on the size of the tick text."""
elif self.style['autoExpandTextSpace'] is True: self.fixedHeight = h
h = self.textHeight self._updateHeight()
def _updateHeight(self):
if not self.isVisible():
h = 0
else:
if self.fixedHeight is None:
if not self.style['showValues']:
h = 0
elif self.style['autoExpandTextSpace'] is True:
h = self.textHeight
else:
h = self.style['tickTextHeight']
h += self.style['tickTextOffset'][1] if self.style['showValues'] else 0
h += max(0, self.style['tickLength'])
if self.label.isVisible():
h += self.label.boundingRect().height() * 0.8
else: else:
h = self.style['tickTextHeight'] h = self.fixedHeight
h += self.style['tickTextOffset'][1] if self.style['showValues'] else 0
h += max(0, self.style['tickLength'])
if self.label.isVisible():
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 not self.style['showValues']: If *width* is None, then the value will be determined automatically
w = 0 based on the size of the tick text."""
elif self.style['autoExpandTextSpace'] is True: self.fixedWidth = w
w = self.textWidth self._updateWidth()
def _updateWidth(self):
if not self.isVisible():
w = 0
else:
if self.fixedWidth is None:
if not self.style['showValues']:
w = 0
elif self.style['autoExpandTextSpace'] is True:
w = self.textWidth
else:
w = self.style['tickTextWidth']
w += self.style['tickTextOffset'][0] if self.style['showValues'] else 0
w += max(0, self.style['tickLength'])
if self.label.isVisible():
w += self.label.boundingRect().height() * 0.8 ## bounding rect is usually an overestimate
else: else:
w = self.style['tickTextWidth'] w = self.fixedWidth
w += self.style['tickTextOffset'][0] if self.style['showValues'] else 0
w += max(0, self.style['tickLength'])
if self.label.isVisible():
w += self.label.boundingRect().height() * 0.8 ## bounding rect is usually an overestimate
self.setMaximumWidth(w) self.setMaximumWidth(w)
self.setMinimumWidth(w) self.setMinimumWidth(w)
self.picture = None self.picture = None
...@@ -1009,19 +1040,18 @@ class AxisItem(GraphicsWidget): ...@@ -1009,19 +1040,18 @@ class AxisItem(GraphicsWidget):
profiler('draw text') profiler('draw text')
def show(self): def show(self):
GraphicsWidget.show(self)
if self.orientation in ['left', 'right']: if self.orientation in ['left', 'right']:
self.setWidth() self._updateWidth()
else: else:
self.setHeight() self._updateHeight()
GraphicsWidget.show(self)
def hide(self): def hide(self):
GraphicsWidget.hide(self)
if self.orientation in ['left', 'right']: if self.orientation in ['left', 'right']:
self.setWidth(0) self._updateWidth()
else: else:
self.setHeight(0) self._updateHeight()
GraphicsWidget.hide(self)
def wheelEvent(self, ev): def wheelEvent(self, ev):
if self.linkedView() is None: if self.linkedView() is None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment