From 482c46acd03c78d8a47384c235299fb460c176d5 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 11 Mar 2022 14:49:45 -0500 Subject: [PATCH] Limit real-time chart updates in "big data" cases - the chart's uppx (units-per-pixel) is > 4 (i.e. zoomed out a lot) - don't shift the chart (to keep the most recent step in view) if the last datum isn't in view (aka the user is probably looking at history) --- piker/ui/_display.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/piker/ui/_display.py b/piker/ui/_display.py index b761b881..72273a80 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -319,13 +319,13 @@ def graphics_update_cycle( # are diffed on each draw cycle anyway; so updates to the # "curve" length is already automatic. + # compute the first available graphic's x-units-per-pixel + xpx = vlm_chart.view.xs_in_px() + # print(r) + # increment the view position by the sample offset. i_step = ohlcv.index i_diff = i_step - vars['i_last'] - if i_diff > 0: - chart.increment_view( - steps=i_diff, - ) vars['i_last'] = i_step ( @@ -341,11 +341,12 @@ def graphics_update_cycle( liv = r > i_step # the last datum is in view # don't real-time "shift" the curve to the - # left under the following conditions: + # left unless we get one of the following: if ( ( i_diff > 0 # no new sample step - and liv + and xpx < 4 # chart is zoomed out very far + and r >= i_step # the last datum isn't in view ) or trigger_all ): @@ -354,7 +355,11 @@ def graphics_update_cycle( # and then iff update curves and shift? chart.increment_view(steps=i_diff) - if vlm_chart: + if ( + vlm_chart + # if zoomed out alot don't update the last "bar" + and xpx < 4 + ): vlm_chart.update_curve_from_array('volume', array) ds.vlm_sticky.update_from_data(*array[-1][['index', 'volume']]) @@ -426,10 +431,12 @@ def graphics_update_cycle( # for typ, tick in reversed(lasts.items()): # update ohlc sampled price bars - chart.update_ohlc_from_array( - chart.name, - array, - ) + + if xpx < 4 or i_diff > 0: + chart.update_ohlc_from_array( + chart.name, + array, + ) # iterate in FIFO order per frame for typ, tick in lasts.items():