From 1ccff376773a1fb4441ef0f207a55be05b2b4efb Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 24 Jan 2022 15:14:06 -0500 Subject: [PATCH] Only update x-axis cursor if chart has a 'bottom' axis --- piker/ui/_cursor.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/piker/ui/_cursor.py b/piker/ui/_cursor.py index fd9df0f0..cac2f0b9 100644 --- a/piker/ui/_cursor.py +++ b/piker/ui/_cursor.py @@ -418,13 +418,16 @@ class Cursor(pg.GraphicsObject): # keep x-axis right below main chart plot_index = -1 if _xaxis_at == 'bottom' else 0 - self.xaxis_label = XAxisLabel( - parent=self.plots[plot_index].getAxis('bottom'), - opacity=_ch_label_opac, - bg_color=self.label_color, - ) - # place label off-screen during startup - self.xaxis_label.setPos(self.plots[0].mapFromView(QPointF(0, 0))) + # ONLY create an x-axis label for the cursor + # if this plot owns the 'bottom' axis. + if 'bottom' in plot.plotItem.axes: + self.xaxis_label = XAxisLabel( + parent=self.plots[plot_index].getAxis('bottom'), + opacity=_ch_label_opac, + bg_color=self.label_color, + ) + # place label off-screen during startup + self.xaxis_label.setPos(self.plots[0].mapFromView(QPointF(0, 0))) def add_curve_cursor( self, @@ -525,17 +528,18 @@ class Cursor(pg.GraphicsObject): for cursor in opts.get('cursors', ()): cursor.setIndex(ix) - # update the label on the bottom of the crosshair - self.xaxis_label.update_label( + # update the label on the bottom of the crosshair + if 'bottom' in plot.plotItem.axes: + self.xaxis_label.update_label( - # XXX: requires: - # https://github.com/pyqtgraph/pyqtgraph/pull/1418 - # otherwise gobbles tons of CPU.. + # XXX: requires: + # https://github.com/pyqtgraph/pyqtgraph/pull/1418 + # otherwise gobbles tons of CPU.. - # map back to abs (label-local) coordinates - abs_pos=plot.mapFromView(QPointF(ix + line_offset, iy)), - value=ix, - ) + # map back to abs (label-local) coordinates + abs_pos=plot.mapFromView(QPointF(ix + line_offset, iy)), + value=ix, + ) self._datum_xy = ix, iy