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.
epoch_indexing_and_dataviz_layer
Tyler Goodlet 2022-12-28 01:20:55 -05:00
parent c1988c4d8d
commit 340045af77
2 changed files with 13 additions and 32 deletions

View File

@ -70,37 +70,17 @@ class FlowGraphic(pg.GraphicsObject):
px_vecs = self.pixelVectors()[0] px_vecs = self.pixelVectors()[0]
if px_vecs: if px_vecs:
xs_in_px = px_vecs.x() return px_vecs.x()
return round(xs_in_px)
else: else:
return 0 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() return self._last_line.x1() if self._last_line else None
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()
class Curve(FlowGraphic): class Curve(FlowGraphic):

View File

@ -126,16 +126,17 @@ class BarItems(FlowGraphic):
self.path = QPainterPath() self.path = QPainterPath()
self._last_bar_lines: tuple[QLineF, ...] | None = None self._last_bar_lines: tuple[QLineF, ...] | None = None
# def x_uppx(self) -> int: def x_last(self) -> None | float:
# # 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 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 # Qt docs: https://doc.qt.io/qt-5/qgraphicsitem.html#boundingRect
def boundingRect(self): def boundingRect(self):