diff --git a/piker/ui/_curve.py b/piker/ui/_curve.py index f22dcd14..a3287341 100644 --- a/piker/ui/_curve.py +++ b/piker/ui/_curve.py @@ -70,37 +70,17 @@ class FlowGraphic(pg.GraphicsObject): px_vecs = self.pixelVectors()[0] if px_vecs: - xs_in_px = px_vecs.x() - return round(xs_in_px) + return px_vecs.x() else: return 0 - def x_last(self) -> float: + def x_last(self) -> float | None: ''' - Return the last most x value of the last line segment. + Return the last most x value of the last line segment or if not + drawn yet, ``None``. ''' - return self._last_line.x1() - - def px_width(self) -> float: - ''' - Return the width of the view box containing - this graphic in pixel units. - - ''' - vb = self.getViewBox() - if not vb: - return 0 - - vr = self.viewRect() - vl, vr = int(vr.left()), int(vr.right()) - - return vb.mapViewToDevice( - QLineF( - vl, 0, - vr, 0, - ) - ).length() + return self._last_line.x1() if self._last_line else None class Curve(FlowGraphic): diff --git a/piker/ui/_ohlc.py b/piker/ui/_ohlc.py index 9712bb9d..de421cd2 100644 --- a/piker/ui/_ohlc.py +++ b/piker/ui/_ohlc.py @@ -126,16 +126,17 @@ class BarItems(FlowGraphic): self.path = QPainterPath() 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: + def x_last(self) -> None | float: ''' - Return the last most x value of the close line segment. + Return the last most x value of the close line segment + or if not drawn yet, ``None``. ''' - return self._last_bar_lines[-1].x2() + if self._last_bar_lines: + close_arm_line = self._last_bar_lines[-1] + return close_arm_line.x2() if close_arm_line else None + else: + return None # Qt docs: https://doc.qt.io/qt-5/qgraphicsitem.html#boundingRect def boundingRect(self):