avoid calling setLabel repeatedly for AxisItem

This commit is contained in:
danielhrisca 2019-01-16 16:43:04 +02:00
parent 2e69b9c5e6
commit b575b56edf

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
@ -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