Use `Viz` over charts where possible in display loop
Since `ChartPlotWidget.update_graphics_from_flow()` is more or less just a call to `Viz.update_graphics()` try to call that directly where possible. Changes include: - calling the viz in the display state specific `maxmin()`. - passing a viz instance to each `ChartView._set_yrange()` call (in prep of explicit group auto-ranging); not that this input is unused in the method for now. - drop `bars_range` var passing since we don't use it.overlays_interaction_latency_tuning
parent
97bb3b48da
commit
934b32c342
|
@ -90,7 +90,6 @@ log = get_logger(__name__)
|
|||
def chart_maxmin(
|
||||
chart: ChartPlotWidget,
|
||||
fqsn: str,
|
||||
# ohlcv_shm: ShmArray,
|
||||
vlm_chart: ChartPlotWidget | None = None,
|
||||
|
||||
) -> tuple[
|
||||
|
@ -106,13 +105,18 @@ def chart_maxmin(
|
|||
|
||||
'''
|
||||
main_viz = chart.get_viz(chart.name)
|
||||
last_bars_range = main_viz.bars_range()
|
||||
out = chart.maxmin(name=fqsn)
|
||||
out = main_viz.maxmin()
|
||||
|
||||
if out is None:
|
||||
return (last_bars_range, 0, 0, 0)
|
||||
return (0, 0, 0)
|
||||
|
||||
mn, mx = out
|
||||
(
|
||||
ixrng,
|
||||
read_slc,
|
||||
mxmn,
|
||||
) = out
|
||||
|
||||
mn, mx = mxmn
|
||||
|
||||
mx_vlm_in_view = 0
|
||||
|
||||
|
@ -125,10 +129,9 @@ def chart_maxmin(
|
|||
_, mx_vlm_in_view = out
|
||||
|
||||
return (
|
||||
last_bars_range,
|
||||
mx,
|
||||
max(mn, 0), # presuming price can't be negative?
|
||||
mx_vlm_in_view,
|
||||
mx_vlm_in_view, # vlm max
|
||||
)
|
||||
|
||||
|
||||
|
@ -226,7 +229,7 @@ async def increment_history_view(
|
|||
do_append
|
||||
and liv
|
||||
):
|
||||
hist_viz.plot.vb._set_yrange()
|
||||
hist_viz.plot.vb._set_yrange(viz=hist_viz)
|
||||
|
||||
# check if tread-in-place x-shift is needed
|
||||
if should_tread:
|
||||
|
@ -313,9 +316,7 @@ async def graphics_update_loop(
|
|||
fqsn,
|
||||
vlm_chart,
|
||||
)
|
||||
last_bars_range: tuple[float, float]
|
||||
(
|
||||
last_bars_range,
|
||||
last_mx,
|
||||
last_mn,
|
||||
last_mx_vlm,
|
||||
|
@ -502,12 +503,11 @@ def graphics_update_cycle(
|
|||
# TODO: we should only run mxmn when we know
|
||||
# an update is due via ``do_append`` above.
|
||||
(
|
||||
brange,
|
||||
mx_in_view,
|
||||
mn_in_view,
|
||||
mx_vlm_in_view,
|
||||
) = ds.maxmin()
|
||||
l, lbar, rbar, r = brange
|
||||
|
||||
mx = mx_in_view + tick_margin
|
||||
mn = mn_in_view - tick_margin
|
||||
profiler('`ds.maxmin()` call')
|
||||
|
@ -524,14 +524,12 @@ def graphics_update_cycle(
|
|||
):
|
||||
chart.update_graphics_from_flow(
|
||||
fqsn,
|
||||
# chart.name,
|
||||
# do_append=do_append,
|
||||
)
|
||||
main_viz.draw_last(array_key=fqsn)
|
||||
|
||||
hist_chart.update_graphics_from_flow(
|
||||
fqsn,
|
||||
# chart.name,
|
||||
# do_append=do_append,
|
||||
)
|
||||
|
||||
|
@ -546,7 +544,7 @@ def graphics_update_cycle(
|
|||
or trigger_all
|
||||
):
|
||||
chart.increment_view(datums=append_diff)
|
||||
main_viz.plot.vb._set_yrange()
|
||||
main_viz.plot.vb._set_yrange(viz=main_viz)
|
||||
|
||||
# NOTE: since vlm and ohlc charts are axis linked now we don't
|
||||
# need the double increment request?
|
||||
|
@ -696,7 +694,7 @@ def graphics_update_cycle(
|
|||
is_1m=True,
|
||||
)
|
||||
if hist_liv:
|
||||
hist_viz.plot.vb._set_yrange()
|
||||
hist_viz.plot.vb._set_yrange(viz=hist_viz)
|
||||
|
||||
# XXX: update this every draw cycle to make
|
||||
varz['last_mx'], varz['last_mn'] = mx, mn
|
||||
|
@ -711,7 +709,6 @@ def graphics_update_cycle(
|
|||
and not viz.is_ohlc
|
||||
):
|
||||
update_fsp_chart(
|
||||
chart,
|
||||
viz,
|
||||
curve_name,
|
||||
array_key=curve_name,
|
||||
|
@ -794,7 +791,6 @@ def graphics_update_cycle(
|
|||
# and curve_name != fqsn
|
||||
):
|
||||
update_fsp_chart(
|
||||
vlm_chart,
|
||||
viz,
|
||||
curve_name,
|
||||
array_key=curve_name,
|
||||
|
@ -806,7 +802,7 @@ def graphics_update_cycle(
|
|||
# resizing from last quote?)
|
||||
fvb = viz.plot.vb
|
||||
fvb._set_yrange(
|
||||
name=curve_name,
|
||||
viz=viz,
|
||||
)
|
||||
|
||||
elif (
|
||||
|
|
|
@ -78,7 +78,6 @@ def has_vlm(ohlcv: ShmArray) -> bool:
|
|||
|
||||
|
||||
def update_fsp_chart(
|
||||
chart: ChartPlotWidget,
|
||||
viz,
|
||||
graphics_name: str,
|
||||
array_key: Optional[str],
|
||||
|
@ -101,18 +100,14 @@ def update_fsp_chart(
|
|||
# update graphics
|
||||
# NOTE: this does a length check internally which allows it
|
||||
# staying above the last row check below..
|
||||
chart.update_graphics_from_flow(
|
||||
graphics_name,
|
||||
array_key=array_key or graphics_name,
|
||||
**kwargs,
|
||||
)
|
||||
viz.update_graphics()
|
||||
|
||||
# XXX: re: ``array_key``: fsp func names must be unique meaning we
|
||||
# can't have duplicates of the underlying data even if multiple
|
||||
# sub-charts reference it under different 'named charts'.
|
||||
|
||||
# read from last calculated value and update any label
|
||||
last_val_sticky = chart.plotItem.getAxis(
|
||||
last_val_sticky = viz.plot.getAxis(
|
||||
'right')._stickies.get(graphics_name)
|
||||
if last_val_sticky:
|
||||
last = last_row[array_key]
|
||||
|
|
|
@ -45,6 +45,7 @@ from . import _event
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from ._chart import ChartPlotWidget
|
||||
from ._dataviz import Viz
|
||||
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
@ -728,6 +729,7 @@ class ChartView(ViewBox):
|
|||
*,
|
||||
|
||||
yrange: Optional[tuple[float, float]] = None,
|
||||
viz: Viz | None = None,
|
||||
|
||||
# NOTE: this value pairs (more or less) with L1 label text
|
||||
# height offset from from the bid/ask lines.
|
||||
|
|
Loading…
Reference in New Issue