Merge pull request #813 from danielhrisca/axisitem_tweak

AxisItem performance improvements
This commit is contained in:
Ogi Moore 2019-05-31 22:16:46 -07:00 committed by GitHub
commit e7cbc12491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ class AxisItem(GraphicsWidget):
If maxTickLength is negative, ticks point into the plot. If maxTickLength is negative, ticks point into the plot.
""" """
def __init__(self, orientation, pen=None, linkView=None, parent=None, maxTickLength=-5, showValues=True): def __init__(self, orientation, pen=None, linkView=None, parent=None, maxTickLength=-5, showValues=True, text='', units='', unitPrefix='', **args):
""" """
============== =============================================================== ============== ===============================================================
**Arguments:** **Arguments:**
@ -28,6 +28,14 @@ class AxisItem(GraphicsWidget):
to be linked to the visible range of a ViewBox. to be linked to the visible range of a ViewBox.
showValues (bool) Whether to display values adjacent to ticks showValues (bool) Whether to display values adjacent to ticks
pen (QPen) Pen used when drawing ticks. pen (QPen) Pen used when drawing ticks.
text The text (excluding units) to display on the label for this
axis.
units The units for this axis. Units should generally be given
without any scaling prefix (eg, 'V' instead of 'mV'). The
scaling prefix will be automatically prepended based on the
range of data displayed.
**args All extra keyword arguments become CSS style options for
the <span> tag which will surround the axis label and units.
============== =============================================================== ============== ===============================================================
""" """
@ -67,10 +75,10 @@ class AxisItem(GraphicsWidget):
self.fixedWidth = None self.fixedWidth = None
self.fixedHeight = None self.fixedHeight = None
self.labelText = '' self.labelText = text
self.labelUnits = '' self.labelUnits = units
self.labelUnitPrefix='' self.labelUnitPrefix = unitPrefix
self.labelStyle = {} self.labelStyle = args
self.logMode = False self.logMode = False
self.tickFont = None self.tickFont = None
@ -80,6 +88,8 @@ class AxisItem(GraphicsWidget):
self.autoSIPrefix = True self.autoSIPrefix = True
self.autoSIPrefixScale = 1.0 self.autoSIPrefixScale = 1.0
self.showLabel(False)
self.setRange(0, 1) self.setRange(0, 1)
if pen is None: if pen is None:
@ -91,8 +101,6 @@ class AxisItem(GraphicsWidget):
if linkView is not None: if linkView is not None:
self.linkToView(linkView) self.linkToView(linkView)
self.showLabel(False)
self.grid = False self.grid = False
#self.setCacheMode(self.DeviceCoordinateCache) #self.setCacheMode(self.DeviceCoordinateCache)
@ -256,11 +264,14 @@ class AxisItem(GraphicsWidget):
axis.setLabel('label text', units='V', **labelStyle) axis.setLabel('label text', units='V', **labelStyle)
""" """
show_label = False
if text is not None: if text is not None:
self.labelText = text self.labelText = text
self.showLabel() show_label = True
if units is not None: if units is not None:
self.labelUnits = units self.labelUnits = units
show_label = True
if show_label:
self.showLabel() self.showLabel()
if unitPrefix is not None: if unitPrefix is not None:
self.labelUnitPrefix = unitPrefix self.labelUnitPrefix = unitPrefix