From 8195fae289ebf172596fdafbe8d49e08c741feaa Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 15 Apr 2022 18:47:45 -0400 Subject: [PATCH] Add a `trigger_all` arg to update cycle func; allows hard history updates --- piker/ui/_chart.py | 6 ++++-- piker/ui/_display.py | 35 +++++++++++++++++++++++++++++------ piker/ui/_fsp.py | 9 +++++++-- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index 79abf215..3fcaae07 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -356,9 +356,11 @@ class LinkedSplits(QWidget): self._symbol: Symbol = None - def graphics_cycle(self) -> None: + def graphics_cycle(self, **kwargs) -> None: from . import _display - return _display.graphics_update_cycle(self.display_state) + ds = self.display_state + if ds: + return _display.graphics_update_cycle(ds, **kwargs) @property def symbol(self) -> Symbol: diff --git a/piker/ui/_display.py b/piker/ui/_display.py index ae6d0c77..1cb13f52 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -290,6 +290,7 @@ async def graphics_update_loop( def graphics_update_cycle( ds: DisplayState, wap_in_history: bool = False, + trigger_all: bool = False, # flag used by prepend history updates ) -> None: @@ -307,10 +308,6 @@ def graphics_update_cycle( tick_margin = vars['tick_margin'] for sym, quote in ds.quotes.items(): - brange, mx_in_view, mn_in_view, mx_vlm_in_view = ds.maxmin() - l, lbar, rbar, r = brange - mx = mx_in_view + tick_margin - mn = mn_in_view - tick_margin # NOTE: vlm may be written by the ``brokerd`` backend # event though a tick sample is not emitted. @@ -333,13 +330,39 @@ def graphics_update_cycle( ) vars['i_last'] = i_step + ( + brange, + mx_in_view, + mn_in_view, + mx_vlm_in_view, + ) = ds.maxmin() + + l, lbar, rbar, r = brange + mx = mx_in_view + tick_margin + mn = mn_in_view - tick_margin + liv = r > i_step # the last datum is in view + + # don't real-time "shift" the curve to the + # left under the following conditions: + if ( + ( + i_diff > 0 # no new sample step + and liv + ) + or trigger_all + ): + # TODO: we should track and compute whether the last + # pixel in a curve should show new data based on uppx + # and then iff update curves and shift? + chart.increment_view(steps=i_diff) + if vlm_chart: vlm_chart.update_curve_from_array('volume', array) ds.vlm_sticky.update_from_data(*array[-1][['index', 'volume']]) if ( - mx_vlm_in_view != vars['last_mx_vlm'] - or mx_vlm_in_view > vars['last_mx_vlm'] + mx_vlm_in_view > vars['last_mx_vlm'] + or trigger_all ): # print(f'mx vlm: {last_mx_vlm} -> {mx_vlm_in_view}') vlm_chart.view._set_yrange( diff --git a/piker/ui/_fsp.py b/piker/ui/_fsp.py index 678b5d8e..a1193327 100644 --- a/piker/ui/_fsp.py +++ b/piker/ui/_fsp.py @@ -50,7 +50,6 @@ from ._forms import ( mk_form, open_form_input_handling, ) -from . import _display from ..fsp._api import maybe_mk_fsp_shm, Fsp from ..fsp import cascade from ..fsp._volume import ( @@ -442,7 +441,13 @@ class FspAdmin: async with stream.subscribe() as stream: async for msg in stream: if msg == 'update': - self.linked.graphics_cycle() + # if the chart isn't hidden try to update + # the data on screen. + if not self.linked.isHidden(): + log.info(f'Re-syncing graphics for fsp: {ns_path}') + self.linked.graphics_cycle(trigger_all=True) + else: + log.info(f'recved unexpected fsp engine msg: {msg}') await complete.wait()