Return `in_view: bool` from `Viz.update_graphics()`

Allows callers to know if they should care about a particular viz
rendering call by immediately knowing if the graphics are in view. This
turns out super useful particularly when doing dynamic y-ranging overlay
calcs.
multichartz_backup
Tyler Goodlet 2023-01-22 15:45:56 -05:00
parent 59d4535bc7
commit 94cb66daf9
3 changed files with 14 additions and 5 deletions

View File

@ -658,7 +658,11 @@ class Viz(msgspec.Struct): # , frozen=True):
**kwargs,
) -> pg.GraphicsObject:
) -> tuple[
bool,
tuple[int, int],
pg.GraphicsObject,
]:
'''
Read latest datums from shm and render to (incrementally)
render to graphics.
@ -688,8 +692,9 @@ class Viz(msgspec.Struct): # , frozen=True):
not in_view.size
or not render
):
# print('exiting early')
# print(f'{self.name} not in view (exiting early)')
return (
False,
(ivl, ivr),
graphics,
)
@ -810,6 +815,7 @@ class Viz(msgspec.Struct): # , frozen=True):
if not out:
log.warning(f'{self.name} failed to render!?')
return (
False,
(ivl, ivr),
graphics,
)
@ -865,6 +871,7 @@ class Viz(msgspec.Struct): # , frozen=True):
self._in_ds = r._in_ds
return (
True,
(ivl, ivr),
graphics,
)
@ -1053,7 +1060,9 @@ class Viz(msgspec.Struct): # , frozen=True):
l_reset = r_reset - rl_diff
else:
raise RuntimeError(f'Unknown view state {vl} -> {vr}')
log.warning(f'Unknown view state {vl} -> {vr}')
# return
# raise RuntimeError(f'Unknown view state {vl} -> {vr}')
else:
# maintain the l->r view distance

View File

@ -551,7 +551,7 @@ def graphics_update_cycle(
(liv and do_px_step)
or trigger_all
):
i_read_range, _ = main_viz.update_graphics()
_, i_read_range, _ = main_viz.update_graphics()
profiler('`Viz.update_graphics()` call')
(

View File

@ -707,7 +707,7 @@ async def open_vlm_displays(
last_val_sticky.update_from_data(-1, value)
_, vlm_curve = vlm_viz.update_graphics()
_, _, vlm_curve = vlm_viz.update_graphics()
# size view to data once at outset
vlm_chart.view._set_yrange(