Use `Viz.update_graphics()` throughout remainder of graphics loop where possible

multichartz_backup
Tyler Goodlet 2023-01-16 19:57:38 -05:00
parent 58d1bdc873
commit caee0130df
1 changed files with 56 additions and 49 deletions

View File

@ -208,7 +208,7 @@ async def increment_history_view(
( (
uppx, uppx,
liv, liv,
do_append, do_px_step,
i_diff_t, i_diff_t,
append_diff, append_diff,
do_rt_update, do_rt_update,
@ -220,7 +220,7 @@ async def increment_history_view(
) )
if ( if (
do_append do_px_step
and liv and liv
): ):
hist_viz.plot.vb._set_yrange(viz=hist_viz) hist_viz.plot.vb._set_yrange(viz=hist_viz)
@ -459,11 +459,11 @@ def graphics_update_cycle(
chart = ds.chart chart = ds.chart
hist_chart = ds.hist_chart hist_chart = ds.hist_chart
flume = ds.flume flume = ds.flume
sym = flume.symbol sym = flume.symbol
fqsn = sym.fqsn fqsn = sym.fqsn
main_viz = chart._vizs[fqsn] main_viz = chart._vizs[fqsn]
hist_viz = hist_chart._vizs[fqsn]
index_field = main_viz.index_field index_field = main_viz.index_field
profiler = Profiler( profiler = Profiler(
@ -487,7 +487,7 @@ def graphics_update_cycle(
( (
uppx, uppx,
liv, liv,
do_append, do_px_step,
i_diff_t, i_diff_t,
append_diff, append_diff,
do_rt_update, do_rt_update,
@ -495,7 +495,7 @@ def graphics_update_cycle(
) = main_viz.incr_info(ds=ds) ) = main_viz.incr_info(ds=ds)
# TODO: we should only run mxmn when we know # TODO: we should only run mxmn when we know
# an update is due via ``do_append`` above. # an update is due via ``do_px_step`` above.
( (
mx_in_view, mx_in_view,
mn_in_view, mn_in_view,
@ -513,18 +513,16 @@ def graphics_update_cycle(
# update ohlc sampled price bars # update ohlc sampled price bars
if ( if (
do_rt_update do_rt_update
or do_append or do_px_step
or trigger_all or trigger_all
): ):
chart.update_graphics_from_flow( main_viz.update_graphics(array_key=fqsn)
fqsn, hist_viz.draw_last(array_key=fqsn)
# do_append=do_append,
)
main_viz.draw_last(array_key=fqsn)
hist_chart.update_graphics_from_flow( else:
fqsn, main_viz.draw_last(
# do_append=do_append, array_key=fqsn,
only_last_uppx=True,
) )
# don't real-time "shift" the curve to the # don't real-time "shift" the curve to the
@ -532,7 +530,7 @@ def graphics_update_cycle(
if ( if (
( (
should_tread should_tread
and do_append and do_px_step
and liv and liv
) )
or trigger_all or trigger_all
@ -586,7 +584,7 @@ def graphics_update_cycle(
if wap_in_history: if wap_in_history:
# update vwap overlay line # update vwap overlay line
chart.update_graphics_from_flow('bar_wap') chart.get_viz('bar_wap').update_graphics()
# L1 book label-line updates # L1 book label-line updates
if typ in ('last',): if typ in ('last',):
@ -623,7 +621,8 @@ def graphics_update_cycle(
): ):
l1.bid_label.update_fields({'level': price, 'size': size}) l1.bid_label.update_fields({'level': price, 'size': size})
# check for y-autorange re-size # Y-autoranging: adjust y-axis limits based on state tracking
# of previous "last" L1 values which are in view.
lmx = varz['last_mx'] lmx = varz['last_mx']
lmn = varz['last_mn'] lmn = varz['last_mn']
mx_diff = mx - lmx mx_diff = mx - lmx
@ -633,6 +632,8 @@ def graphics_update_cycle(
mx_diff mx_diff
or mn_diff or mn_diff
): ):
# complain about out-of-range outliers which can show up
# in certain annoying feeds (like ib)..
if ( if (
abs(mx_diff) > .25 * lmx abs(mx_diff) > .25 * lmx
or or
@ -647,7 +648,8 @@ def graphics_update_cycle(
f'mx_diff: {mx_diff}\n' f'mx_diff: {mx_diff}\n'
f'mn_diff: {mn_diff}\n' f'mn_diff: {mn_diff}\n'
) )
# fast chart resize case
# FAST CHART resize case
elif ( elif (
liv liv
and not chart._static_yrange == 'axis' and not chart._static_yrange == 'axis'
@ -659,7 +661,7 @@ def graphics_update_cycle(
): ):
yr = (mn, mx) yr = (mn, mx)
# print( # print(
# f'updating y-range due to mxmn\n' # f'MAIN VIZ yrange update\n'
# f'{fqsn}: {yr}' # f'{fqsn}: {yr}'
# ) # )
@ -673,8 +675,7 @@ def graphics_update_cycle(
yrange=yr yrange=yr
) )
# check if slow chart needs a resize # SLOW CHART resize case
hist_viz = hist_chart._vizs[fqsn]
( (
_, _,
hist_liv, hist_liv,
@ -690,15 +691,16 @@ def graphics_update_cycle(
if hist_liv: if hist_liv:
hist_viz.plot.vb._set_yrange(viz=hist_viz) hist_viz.plot.vb._set_yrange(viz=hist_viz)
# XXX: update this every draw cycle to make # XXX: update this every draw cycle to ensure y-axis auto-ranging
# only adjusts when the in-view data co-domain actually expands or
# contracts.
varz['last_mx'], varz['last_mn'] = mx, mn varz['last_mx'], varz['last_mn'] = mx, mn
# run synchronous update on all linked viz # run synchronous update on all `Viz` overlays
# TODO: should the "main" (aka source) viz be special?
for curve_name, viz in chart._vizs.items(): for curve_name, viz in chart._vizs.items():
# update any overlayed fsp flows # update any overlayed fsp flows
if ( if (
# curve_name != chart.data_key
curve_name != fqsn curve_name != fqsn
and not viz.is_ohlc and not viz.is_ohlc
): ):
@ -713,21 +715,28 @@ def graphics_update_cycle(
# px column to give the user the mx/mn # px column to give the user the mx/mn
# range of that set. # range of that set.
if ( if (
liv curve_name != fqsn
# and not do_append and liv
# and not do_px_step
# and not do_rt_update # and not do_rt_update
): ):
viz.draw_last( viz.draw_last(
array_key=curve_name, array_key=curve_name,
# TODO: XXX this is currently broken for the
# `FlattenedOHLC` case since we aren't returning the
# full x/y uppx's worth of src-data from
# `draw_last_datum()` ..
only_last_uppx=True, only_last_uppx=True,
) )
# volume chart logic.. # volume chart logic..
# TODO: can we unify this with the above loop? # TODO: can we unify this with the above loop?
if vlm_chart: if vlm_chart:
# print(f"DOING VLM {fqsn}")
vlm_vizs = vlm_chart._vizs vlm_vizs = vlm_chart._vizs
main_vlm_viz = vlm_vizs['volume']
# always update y-label # always update y-label
ds.vlm_sticky.update_from_data( ds.vlm_sticky.update_from_data(
*array[-1][[ *array[-1][[
@ -739,19 +748,20 @@ def graphics_update_cycle(
if ( if (
( (
do_rt_update do_rt_update
or do_append or do_px_step
and liv and liv
) )
or trigger_all or trigger_all
): ):
# TODO: make it so this doesn't have to be called # TODO: make it so this doesn't have to be called
# once the $vlm is up? # once the $vlm is up?
vlm_chart.update_graphics_from_flow( main_vlm_viz.update_graphics(
'volume',
# UGGGh, see ``maxmin()`` impl in `._fsp` for # UGGGh, see ``maxmin()`` impl in `._fsp` for
# the overlayed plotitems... we need a better # the overlayed plotitems... we need a better
# bay to invoke a maxmin per overlay.. # bay to invoke a maxmin per overlay..
render=False, render=False,
# XXX: ^^^^ THIS IS SUPER IMPORTANT! ^^^^ # XXX: ^^^^ THIS IS SUPER IMPORTANT! ^^^^
# without this, since we disable the # without this, since we disable the
# 'volume' (units) chart after the $vlm starts # 'volume' (units) chart after the $vlm starts
@ -760,7 +770,7 @@ def graphics_update_cycle(
# connected to update accompanying overlay # connected to update accompanying overlay
# graphics.. # graphics..
) )
profiler('`vlm_chart.update_graphics_from_flow()`') profiler('`main_vlm_viz.update_graphics()`')
if ( if (
mx_vlm_in_view != varz['last_mx_vlm'] mx_vlm_in_view != varz['last_mx_vlm']
@ -768,50 +778,49 @@ def graphics_update_cycle(
vlm_yr = (0, mx_vlm_in_view * 1.375) vlm_yr = (0, mx_vlm_in_view * 1.375)
vlm_chart.view._set_yrange(yrange=vlm_yr) vlm_chart.view._set_yrange(yrange=vlm_yr)
profiler('`vlm_chart.view._set_yrange()`') profiler('`vlm_chart.view._set_yrange()`')
# print(f'mx vlm: {last_mx_vlm} -> {mx_vlm_in_view}')
varz['last_mx_vlm'] = mx_vlm_in_view varz['last_mx_vlm'] = mx_vlm_in_view
# update all downstream FSPs # update all downstream FSPs
for curve_name, viz in vlm_vizs.items(): for curve_name, viz in vlm_vizs.items():
if curve_name == 'volume':
continue
if ( if (
curve_name not in {'volume', fqsn} viz.render
and viz.render
and ( and (
liv and do_rt_update liv and do_rt_update
or do_append or do_px_step
) )
# and not viz.is_ohlc and curve_name not in {fqsn,}
# and curve_name != fqsn
): ):
update_fsp_chart( update_fsp_chart(
viz, viz,
curve_name, curve_name,
array_key=curve_name, array_key=curve_name,
# do_append=uppx < update_uppx,
# do_append=do_append,
) )
# is this even doing anything? # is this even doing anything?
# (pretty sure it's the real-time # (pretty sure it's the real-time
# resizing from last quote?) # resizing from last quote?)
fvb = viz.plot.vb fvb = viz.plot.vb
# XXX: without this we get completely
# mangled/empty vlm display subchart..
fvb._set_yrange( fvb._set_yrange(
viz=viz, viz=viz,
) )
# even if we're downsampled bigly
# draw the last datum in the final
# px column to give the user the mx/mn
# range of that set.
elif ( elif (
curve_name != 'volume' not do_px_step
and not do_append
and liv and liv
and uppx >= 1 and uppx >= 1
# even if we're downsampled bigly
# draw the last datum in the final
# px column to give the user the mx/mn
# range of that set.
): ):
# always update the last datum-element # always update the last datum-element
# graphic for all vizs # graphic for all vizs
# print(f'drawing last {viz.name}')
viz.draw_last(array_key=curve_name) viz.draw_last(array_key=curve_name)
@ -1139,7 +1148,6 @@ async def display_symbol_data(
# for zoom-interaction purposes. # for zoom-interaction purposes.
hist_chart.get_viz(fqsn).draw_last( hist_chart.get_viz(fqsn).draw_last(
array_key=fqsn, array_key=fqsn,
# only_last_uppx=True,
) )
pis.setdefault(fqsn, [None, None])[1] = hist_chart.plotItem pis.setdefault(fqsn, [None, None])[1] = hist_chart.plotItem
@ -1243,7 +1251,6 @@ async def display_symbol_data(
# for zoom-interaction purposes. # for zoom-interaction purposes.
viz.draw_last( viz.draw_last(
array_key=fqsn, array_key=fqsn,
# only_last_uppx=True,
) )
hist_pi.vb.maxmin = partial( hist_pi.vb.maxmin = partial(