From e252f702534746ea96d6a0ff90b987a1f4970023 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 7 Dec 2022 12:22:07 -0500 Subject: [PATCH] Add `.x_last()` meth to flow graphics --- piker/ui/_curve.py | 9 ++++++++- piker/ui/_ohlc.py | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/piker/ui/_curve.py b/piker/ui/_curve.py index ad415031..cb696257 100644 --- a/piker/ui/_curve.py +++ b/piker/ui/_curve.py @@ -133,7 +133,7 @@ class Curve(pg.GraphicsObject): # self.last_step_pen = pg.mkPen(hcolor(color), width=2) self.last_step_pen = pg.mkPen(pen, width=2) - self._last_line = QLineF() + self._last_line: QLineF = QLineF() # flat-top style histogram-like discrete curve # self._step_mode: bool = step_mode @@ -182,6 +182,13 @@ class Curve(pg.GraphicsObject): else: return 0 + def x_last(self) -> float: + ''' + Return the last most x value of the last line segment. + + ''' + return self._last_line.x2() + def px_width(self) -> float: vb = self.getViewBox() diff --git a/piker/ui/_ohlc.py b/piker/ui/_ohlc.py index 9a37bbfa..a7e36146 100644 --- a/piker/ui/_ohlc.py +++ b/piker/ui/_ohlc.py @@ -114,12 +114,20 @@ class BarItems(pg.GraphicsObject): self.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache) self.path = QPainterPath() - self._last_bar_lines: Optional[tuple[QLineF, ...]] = None + + self._last_bar_lines: tuple[QLineF, ...] | None = None def x_uppx(self) -> int: # we expect the downsample curve report this. return 0 + def x_last(self) -> float: + ''' + Return the last most x value of the close line segment. + + ''' + return self._last_bar_lines[-1].x2() + # Qt docs: https://doc.qt.io/qt-5/qgraphicsitem.html#boundingRect def boundingRect(self): # profiler = Profiler(