Add level line flag to allow tracking its marker x-position
							parent
							
								
									ad2100fe3f
								
							
						
					
					
						commit
						44c6f6dfda
					
				|  | @ -117,6 +117,7 @@ class LevelMarker(QGraphicsPathItem): | ||||||
| 
 | 
 | ||||||
|         self.get_level = get_level |         self.get_level = get_level | ||||||
|         self._on_paint = on_paint |         self._on_paint = on_paint | ||||||
|  | 
 | ||||||
|         self.scene_x = lambda: chart.marker_right_points()[1] |         self.scene_x = lambda: chart.marker_right_points()[1] | ||||||
|         self.level: float = 0 |         self.level: float = 0 | ||||||
|         self.keep_in_view = keep_in_view |         self.keep_in_view = keep_in_view | ||||||
|  | @ -152,11 +153,7 @@ class LevelMarker(QGraphicsPathItem): | ||||||
|     def w(self) -> float: |     def w(self) -> float: | ||||||
|         return self.path_br().width() |         return self.path_br().width() | ||||||
| 
 | 
 | ||||||
|     def position_in_view( |     def position_in_view(self) -> None: | ||||||
|         self, |  | ||||||
|         # level: float, |  | ||||||
| 
 |  | ||||||
|     ) -> None: |  | ||||||
|         ''' |         ''' | ||||||
|         Show a pp off-screen indicator for a level label. |         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 |         elif level < ymn:  # pin to bottom of view | ||||||
| 
 |  | ||||||
|             self.setPos( |             self.setPos( | ||||||
|                 QPointF( |                 QPointF( | ||||||
|                     x, |                     x, | ||||||
|  | @ -240,11 +236,12 @@ def qgo_draw_markers( | ||||||
|     right_offset: float, |     right_offset: float, | ||||||
| 
 | 
 | ||||||
| ) -> 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 |     removing the view transform for the painter, drawing the markers | ||||||
|     in scene coords, then restoring the view coords. |     in scene coords, then restoring the view coords. | ||||||
| 
 | 
 | ||||||
|     """ |     ''' | ||||||
|     # paint markers in native coordinate system |     # paint markers in native coordinate system | ||||||
|     orig_tr = p.transform() |     orig_tr = p.transform() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -85,6 +85,7 @@ class LevelLine(pg.InfiniteLine): | ||||||
|         self._marker = None |         self._marker = None | ||||||
|         self.only_show_markers_on_hover = only_show_markers_on_hover |         self.only_show_markers_on_hover = only_show_markers_on_hover | ||||||
|         self.show_markers: bool = True  # presuming the line is hovered at init |         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" |         # should line go all the way to far end or leave a "margin" | ||||||
|         # space for other graphics (eg. L1 book) |         # space for other graphics (eg. L1 book) | ||||||
|  | @ -329,7 +330,7 @@ class LevelLine(pg.InfiniteLine): | ||||||
|         from pg.. |         from pg.. | ||||||
| 
 | 
 | ||||||
|         ''' |         ''' | ||||||
|         p.setRenderHint(p.Antialiasing) |         # p.setRenderHint(p.Antialiasing) | ||||||
| 
 | 
 | ||||||
|         # these are in viewbox coords |         # these are in viewbox coords | ||||||
|         vb_left, vb_right = self._endPoints |         vb_left, vb_right = self._endPoints | ||||||
|  | @ -355,14 +356,18 @@ class LevelLine(pg.InfiniteLine): | ||||||
|         # order lines.. not sure wtf is up with that. |         # order lines.. not sure wtf is up with that. | ||||||
|         # for now we're just using it on the position line. |         # for now we're just using it on the position line. | ||||||
|         elif self._marker: |         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 |             else: | ||||||
|             # composed annotation |                 # TODO: make this label update part of a scene-aware-marker | ||||||
|             self._marker.setPos( |                 # composed annotation | ||||||
|                 QPointF(marker_right, self.scene_y()) |                 self._marker.setPos( | ||||||
|             ) |                     QPointF(marker_right, self.scene_y()) | ||||||
|             if hasattr(self._marker, 'label'): |                 ) | ||||||
|                 self._marker.label.update() |                 if hasattr(self._marker, 'label'): | ||||||
|  |                     self._marker.label.update() | ||||||
| 
 | 
 | ||||||
|         elif not self.use_marker_margin: |         elif not self.use_marker_margin: | ||||||
|             # basically means **don't** shorten the line with normally |             # basically means **don't** shorten the line with normally | ||||||
|  | @ -525,9 +530,10 @@ def level_line( | ||||||
|     **kwargs, |     **kwargs, | ||||||
| 
 | 
 | ||||||
| ) -> LevelLine: | ) -> 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 |     hl_color = color + '_light' if highlight_on_hover else color | ||||||
| 
 | 
 | ||||||
|     line = LevelLine( |     line = LevelLine( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue