From 1fa6e8d9ba34054a8986bd9e9e0c78ae51e4d79e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 7 Sep 2022 16:35:01 -0400 Subject: [PATCH] Only show slow chart xlabel when focussed --- piker/ui/_cursor.py | 35 ++++++++++++++++++++++++++--------- piker/ui/_display.py | 3 +++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/piker/ui/_cursor.py b/piker/ui/_cursor.py index 2c7bb460..a27aca8c 100644 --- a/piker/ui/_cursor.py +++ b/piker/ui/_cursor.py @@ -336,6 +336,8 @@ class Cursor(pg.GraphicsObject): self.linked = linkedsplits self.graphics: dict[str, pg.GraphicsObject] = {} + self.xaxis_label: Optional[XAxisLabel] = None + self.always_show_xlabel: bool = True self.plots: list['PlotChartWidget'] = [] # type: ignore # noqa self.active_plot = None self.digits: int = digits @@ -508,12 +510,23 @@ class Cursor(pg.GraphicsObject): self.graphics[plot]['hl'].show() self.graphics[plot]['yl'].show() - else: # Leave + if ( + not self.always_show_xlabel + and not self.xaxis_label.isVisible() + ): + self.xaxis_label.show() - # hide horiz line and y-label + # Leave: hide horiz line and y-label + else: self.graphics[plot]['hl'].hide() self.graphics[plot]['yl'].hide() + if ( + not self.always_show_xlabel + and self.xaxis_label.isVisible() + ): + self.xaxis_label.hide() + def mouseMoved( self, coords: tuple[QPointF], # noqa @@ -602,13 +615,17 @@ class Cursor(pg.GraphicsObject): left_axis_width += left.width() # map back to abs (label-local) coordinates - self.xaxis_label.update_label( - abs_pos=( - plot.mapFromView(QPointF(vl_x, iy)) - - QPointF(left_axis_width, 0) - ), - value=ix, - ) + if ( + self.always_show_xlabel + or self.xaxis_label.isVisible() + ): + self.xaxis_label.update_label( + abs_pos=( + plot.mapFromView(QPointF(vl_x, iy)) - + QPointF(left_axis_width, 0) + ), + value=ix, + ) self._datum_xy = ix, iy diff --git a/piker/ui/_display.py b/piker/ui/_display.py index 0cd21dbb..83b7119b 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -868,6 +868,9 @@ async def display_symbol_data( # to avoid internal pane creation. sidepane=False, ) + # don't show when not focussed + hist_linked.cursor.always_show_xlabel = False + hist_chart.default_view( bars_from_y=int(len(hist_ohlcv.array)), # size to data y_offset=6116*2, # push it a little away from the y-axis