From 5e98a305374a58a75ede56d24b9031cdf879c34d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 1 Sep 2022 14:26:40 -0400 Subject: [PATCH] Add simplified history incrementer consumer task --- piker/ui/_display.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/piker/ui/_display.py b/piker/ui/_display.py index e91b567c..c220a68e 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -324,10 +324,6 @@ def graphics_update_cycle( ohlcv = ds.ohlcv array = ohlcv.array - # history view chart - hist_ohlcv = ds.hist_ohlcv - hist_array = hist_ohlcv.array - vars = ds.vars tick_margin = vars['tick_margin'] @@ -925,6 +921,38 @@ async def display_symbol_data( vlm_chart, ) + async def increment_history_view(): + i_last_append = i_last = hist_ohlcv.index + + async with feed.index_stream( + int(hist_step_size_s) + ) as istream: + async for msg in istream: + + # increment the view position by the sample offset. + uppx = hist_chart.view.x_uppx() + l, lbar, rbar, r = hist_chart.bars_range() + + i_step = hist_ohlcv.index + i_diff = i_step - i_last + i_last = i_step + liv = r >= i_step + append_diff = i_step - i_last_append + do_append = (append_diff >= uppx) + + if do_append: + i_last_append = i_step + + if ( + # i_diff > 0 # no new sample step + do_append + # and uppx < 4 # chart is zoomed out very far + and liv + ): + hist_chart.increment_view(steps=i_diff) + + ln.start_soon(increment_history_view) + await trio.sleep(0) # size view to data prior to order mode init