From 33df4f99274de0de690c9a9eb60edcc8ab4e9dca Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 22 Jan 2023 15:45:56 -0500 Subject: [PATCH] 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. --- piker/ui/_dataviz.py | 15 ++++++++++++--- piker/ui/_display.py | 2 +- piker/ui/_fsp.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/piker/ui/_dataviz.py b/piker/ui/_dataviz.py index a417a475..a024b3b5 100644 --- a/piker/ui/_dataviz.py +++ b/piker/ui/_dataviz.py @@ -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 diff --git a/piker/ui/_display.py b/piker/ui/_display.py index 64c0b271..66f3679f 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -557,7 +557,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') ( diff --git a/piker/ui/_fsp.py b/piker/ui/_fsp.py index e3a6cfef..2e2e76c1 100644 --- a/piker/ui/_fsp.py +++ b/piker/ui/_fsp.py @@ -707,7 +707,7 @@ async def open_vlm_displays( last_val_sticky.update_from_data(-1, value) - _, vlm_curve = vlm_chart.update_graphics_from_flow( + _, _, vlm_curve = vlm_chart.update_graphics_from_flow( 'volume', )