From 44c6f6dfdad0f15e11bbd6104a5f855cfba70a96 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 13 Sep 2022 17:43:04 -0400 Subject: [PATCH] Add level line flag to allow tracking its marker x-position --- piker/ui/_annotate.py | 13 +++++-------- piker/ui/_lines.py | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/piker/ui/_annotate.py b/piker/ui/_annotate.py index 5cae0bdd..35f6d548 100644 --- a/piker/ui/_annotate.py +++ b/piker/ui/_annotate.py @@ -117,6 +117,7 @@ class LevelMarker(QGraphicsPathItem): self.get_level = get_level self._on_paint = on_paint + self.scene_x = lambda: chart.marker_right_points()[1] self.level: float = 0 self.keep_in_view = keep_in_view @@ -152,11 +153,7 @@ class LevelMarker(QGraphicsPathItem): def w(self) -> float: return self.path_br().width() - def position_in_view( - self, - # level: float, - - ) -> None: + def position_in_view(self) -> None: ''' Show a pp off-screen indicator for a level label. @@ -190,7 +187,6 @@ class LevelMarker(QGraphicsPathItem): ) elif level < ymn: # pin to bottom of view - self.setPos( QPointF( x, @@ -240,11 +236,12 @@ def qgo_draw_markers( right_offset: float, ) -> float: - """Paint markers in ``pg.GraphicsItem`` style by first + ''' + Paint markers in ``pg.GraphicsItem`` style by first removing the view transform for the painter, drawing the markers in scene coords, then restoring the view coords. - """ + ''' # paint markers in native coordinate system orig_tr = p.transform() diff --git a/piker/ui/_lines.py b/piker/ui/_lines.py index 1e20958c..033464c3 100644 --- a/piker/ui/_lines.py +++ b/piker/ui/_lines.py @@ -85,6 +85,7 @@ class LevelLine(pg.InfiniteLine): self._marker = None self.only_show_markers_on_hover = only_show_markers_on_hover self.show_markers: bool = True # presuming the line is hovered at init + self.track_marker_pos: bool = False # should line go all the way to far end or leave a "margin" # space for other graphics (eg. L1 book) @@ -329,7 +330,7 @@ class LevelLine(pg.InfiniteLine): from pg.. ''' - p.setRenderHint(p.Antialiasing) + # p.setRenderHint(p.Antialiasing) # these are in viewbox coords vb_left, vb_right = self._endPoints @@ -355,14 +356,18 @@ class LevelLine(pg.InfiniteLine): # order lines.. not sure wtf is up with that. # for now we're just using it on the position line. elif self._marker: + if self.track_marker_pos: + # make the line end at the marker's x pos + line_end = self._marker.pos().x() - # TODO: make this label update part of a scene-aware-marker - # composed annotation - self._marker.setPos( - QPointF(marker_right, self.scene_y()) - ) - if hasattr(self._marker, 'label'): - self._marker.label.update() + else: + # TODO: make this label update part of a scene-aware-marker + # composed annotation + self._marker.setPos( + QPointF(marker_right, self.scene_y()) + ) + if hasattr(self._marker, 'label'): + self._marker.label.update() elif not self.use_marker_margin: # basically means **don't** shorten the line with normally @@ -525,9 +530,10 @@ def level_line( **kwargs, ) -> LevelLine: - """Convenience routine to add a styled horizontal line to a plot. + ''' + Convenience routine to add a styled horizontal line to a plot. - """ + ''' hl_color = color + '_light' if highlight_on_hover else color line = LevelLine(