Make `FlowGraphic.x_last()` be optionally `None`

In the case where the last-datum-graphic hasn't been created yet, simply
return a `None` from this method so the caller can choose to ignore the
output. Further, drop `.px_width()` since it makes more sense defined on
`Viz` as well as the previously commented `BarItems.x_uppx()` method.
Also, don't round the `.x_uppx()` output since it can then be used when
< 1 to do x-domain scaling during high zoom usage.
multichartz
Tyler Goodlet 2022-12-28 01:20:55 -05:00
parent de3fd9edbe
commit ead2e1ed1f
2 changed files with 13 additions and 32 deletions

View File

@ -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):

View File

@ -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):