Incrementally set vlm chart yrange per quote

log_linearized_curve_overlays
Tyler Goodlet 2023-02-08 17:18:29 -05:00
parent 0a939311fe
commit c646b435bf
1 changed files with 31 additions and 23 deletions

View File

@ -28,6 +28,7 @@ import time
from typing import ( from typing import (
Optional, Optional,
Any, Any,
TYPE_CHECKING,
) )
import tractor import tractor
@ -82,6 +83,9 @@ from .._profile import (
from ..log import get_logger from ..log import get_logger
from .._profile import Profiler from .._profile import Profiler
if TYPE_CHECKING:
from ._interaction import ChartView
log = get_logger(__name__) log = get_logger(__name__)
@ -185,8 +189,8 @@ class DisplayState(Struct):
'i_last': 0, 'i_last': 0,
'i_last_append': 0, 'i_last_append': 0,
'last_mx_vlm': 0, 'last_mx_vlm': 0,
'last_mx': 0, # 'last_mx': 0,
'last_mn': 0, # 'last_mn': 0,
} }
) )
hist_vars: dict[str, Any] = field( hist_vars: dict[str, Any] = field(
@ -194,8 +198,8 @@ class DisplayState(Struct):
'i_last': 0, 'i_last': 0,
'i_last_append': 0, 'i_last_append': 0,
'last_mx_vlm': 0, 'last_mx_vlm': 0,
'last_mx': 0, # 'last_mx': 0,
'last_mn': 0, # 'last_mn': 0,
} }
) )
@ -406,8 +410,8 @@ async def graphics_update_loop(
'i_last': 0, 'i_last': 0,
'i_last_append': 0, 'i_last_append': 0,
'last_mx_vlm': last_mx_vlm, 'last_mx_vlm': last_mx_vlm,
'last_mx': last_mx, # 'last_mx': last_mx,
'last_mn': last_mn, # 'last_mn': last_mn,
}, },
'globalz': globalz, 'globalz': globalz,
}) })
@ -513,7 +517,7 @@ def graphics_update_cycle(
chart = ds.chart chart = ds.chart
vlm_chart = ds.vlm_chart vlm_chart = ds.vlm_chart
varz = ds.vars # varz = ds.vars
l1 = ds.l1 l1 = ds.l1
flume = ds.flume flume = ds.flume
ohlcv = flume.rt_shm ohlcv = flume.rt_shm
@ -547,13 +551,13 @@ def graphics_update_cycle(
# - we should probably scale the view margin based on the size of # - we should probably scale the view margin based on the size of
# the true range? This way you can slap in orders outside the # the true range? This way you can slap in orders outside the
# current L1 (only) book range. # current L1 (only) book range.
main_vb = main_viz.plot.vb main_vb: ChartView = main_viz.plot.vb
this_viz = chart._vizs[fqsn] this_viz: Viz = chart._vizs[fqsn]
this_vb = this_viz.plot.vb this_vb: ChartView = this_viz.plot.vb
lmn, lmx = this_vb._yrange lmn, lmx = this_vb._yrange
mx = lmx mx: float = lmx
mn = lmn mn: float = lmn
mx_vlm_in_view = varz['last_mx_vlm'] mx_vlm_in_view: float | None = None
# update ohlc sampled price bars # update ohlc sampled price bars
if ( if (
@ -773,8 +777,8 @@ def graphics_update_cycle(
# XXX: update this every draw cycle to ensure y-axis auto-ranging # XXX: update this every draw cycle to ensure y-axis auto-ranging
# only adjusts when the in-view data co-domain actually expands or # only adjusts when the in-view data co-domain actually expands or
# contracts. # contracts.
varz['last_mn'] = mn # varz['last_mn'] = mn
varz['last_mx'] = mx # varz['last_mx'] = mx
# TODO: a similar, only-update-full-path-on-px-step approach for all # TODO: a similar, only-update-full-path-on-px-step approach for all
# fsp overlays and vlm stuff.. # fsp overlays and vlm stuff..
@ -820,8 +824,9 @@ def graphics_update_cycle(
# TODO: can we unify this with the above loop? # TODO: can we unify this with the above loop?
if vlm_chart: if vlm_chart:
vlm_vizs = vlm_chart._vizs vlm_vizs = vlm_chart._vizs
main_vlm_viz = vlm_vizs['volume'] main_vlm_viz = vlm_vizs['volume']
main_vlm_vb = main_vlm_viz.plot.vb
(_, vlm_ymx) = vlm_yrange = main_vlm_vb._yrange
# always update y-label # always update y-label
ds.vlm_sticky.update_from_data( ds.vlm_sticky.update_from_data(
@ -859,16 +864,19 @@ def graphics_update_cycle(
profiler('`main_vlm_viz.update_graphics()`') profiler('`main_vlm_viz.update_graphics()`')
if ( if (
mx_vlm_in_view != varz['last_mx_vlm'] mx_vlm_in_view
and mx_vlm_in_view != vlm_ymx
): ):
varz['last_mx_vlm'] = mx_vlm_in_view # in this case we want to scale all overlays in the
# sub-chart but only incrementally update the vlm since
# TODO: incr maxmin update as pass into below.. # we already calculated the new range above.
# vlm_yr = (0, mx_vlm_in_view * 1.375) # TODO: in theory we can incrementally update all
# overlays as well though it will require iteration of
# them here in the display loop right?
main_vlm_viz.plot.vb.interact_graphics_cycle( main_vlm_viz.plot.vb.interact_graphics_cycle(
do_overlay_scaling=False, do_overlay_scaling=True,
do_linked_charts=False, do_linked_charts=False,
yranges={main_vlm_viz: vlm_yrange},
) )
profiler('`vlm_chart.view.interact_graphics_cycle()`') profiler('`vlm_chart.view.interact_graphics_cycle()`')