From 73089e561299e03da270868ad16647b9c62cad29 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 7 Mar 2023 20:40:21 -0500 Subject: [PATCH] Always show a minimum bars during startup This is particularly more "good looking" when we boot with a pair that doesn't have historical 1s OHLC and thus the fast chart is empty from outset. In this case it's a lot nicer to be already zoomed to a comfortable preset number of "datums in view" even when the history isn't yet filled in. Adjusts the chart display `Viz.default_view()` startup to explicitly ensure this happens via the `do_min_bars=True` flag B) --- piker/ui/_dataviz.py | 26 ++++++++++++++++++++------ piker/ui/_display.py | 20 +++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/piker/ui/_dataviz.py b/piker/ui/_dataviz.py index 2672cab0..d70deb34 100644 --- a/piker/ui/_dataviz.py +++ b/piker/ui/_dataviz.py @@ -1082,12 +1082,10 @@ class Viz(Struct): data_diff = last_datum - first_datum rl_diff = vr - vl rescale_to_data: bool = False - # new_uppx: float = 1 if rl_diff > data_diff: rescale_to_data = True rl_diff = data_diff - new_uppx: float = data_diff / self.px_width() # orient by offset from the y-axis including # space to compensate for the L1 labels. @@ -1097,14 +1095,28 @@ class Viz(Struct): offset = l1_offset if rescale_to_data: + new_uppx: float = data_diff / self.px_width() offset = (offset / uppx) * new_uppx else: offset = (y_offset * step) + uppx*step + # NOTE: if we are in the midst of start-up and a bunch of + # widgets are spawning/rendering concurrently, it's likely the + # label size above `l1_offset` won't have yet fully rendered. + # Here we try to compensate for that ensure at least a static + # bar gap between the last datum and the y-axis. + if ( + do_min_bars + and offset <= (6 * step) + ): + offset = 6 * step + # align right side of view to the rightmost datum + the selected # offset from above. - r_reset = (self.graphics.x_last() or last_datum) + offset + r_reset = ( + self.graphics.x_last() or last_datum + ) + offset # no data is in view so check for the only 2 sane cases: # - entire view is LEFT of data @@ -1129,7 +1141,6 @@ class Viz(Struct): else: log.warning(f'Unknown view state {vl} -> {vr}') return - else: # maintain the l->r view distance l_reset = r_reset - rl_diff @@ -1138,7 +1149,11 @@ class Viz(Struct): do_min_bars and (r_reset - l_reset) < min_bars_from_y ): - l_reset = r_reset - min_bars_from_y + l_reset = ( + (r_reset + offset) + - + min_bars_from_y * step + ) # remove any custom user yrange setttings if chartw._static_yrange == 'axis': @@ -1152,7 +1167,6 @@ class Viz(Struct): if do_ds: view.interact_graphics_cycle() - view.interact_graphics_cycle() def incr_info( self, diff --git a/piker/ui/_display.py b/piker/ui/_display.py index 1ff9c4dc..3da33809 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -416,7 +416,9 @@ async def graphics_update_loop( ds.vlm_chart = vlm_chart ds.vlm_sticky = vlm_sticky - fast_chart.main_viz.default_view() + fast_chart.main_viz.default_view( + do_min_bars=True, + ) # ds.hist_vars.update({ # 'i_last_append': 0, @@ -1456,7 +1458,9 @@ async def display_symbol_data( for fqsn, flume in feed.flumes.items(): # size view to data prior to order mode init - rt_chart.main_viz.default_view() + rt_chart.main_viz.default_view( + do_min_bars=True, + ) rt_linked.graphics_cycle() # TODO: look into this because not sure why it was @@ -1467,7 +1471,9 @@ async def display_symbol_data( # determine if auto-range adjustements should be made. # rt_linked.subplots.pop('volume', None) - hist_chart.main_viz.default_view() + hist_chart.main_viz.default_view( + do_min_bars=True, + ) hist_linked.graphics_cycle() godwidget.resize_all() @@ -1510,10 +1516,14 @@ async def display_symbol_data( # default view adjuments and sidepane alignment # as final default UX touch. - rt_chart.main_viz.default_view() + rt_chart.main_viz.default_view( + do_min_bars=True, + ) await trio.sleep(0) - hist_chart.main_viz.default_view() + hist_chart.main_viz.default_view( + do_min_bars=True, + ) hist_viz = hist_chart.get_viz(fqsn) await trio.sleep(0)