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.multichartz_backup
parent
fad518a61a
commit
81ccc14c98
|
@ -88,7 +88,6 @@ log = get_logger(__name__)
|
||||||
def chart_maxmin(
|
def chart_maxmin(
|
||||||
chart: ChartPlotWidget,
|
chart: ChartPlotWidget,
|
||||||
fqsn: str,
|
fqsn: str,
|
||||||
# ohlcv_shm: ShmArray,
|
|
||||||
vlm_chart: ChartPlotWidget | None = None,
|
vlm_chart: ChartPlotWidget | None = None,
|
||||||
|
|
||||||
) -> tuple[
|
) -> tuple[
|
||||||
|
@ -104,13 +103,18 @@ def chart_maxmin(
|
||||||
|
|
||||||
'''
|
'''
|
||||||
main_viz = chart.get_viz(chart.name)
|
main_viz = chart.get_viz(chart.name)
|
||||||
last_bars_range = main_viz.bars_range()
|
out = main_viz.maxmin()
|
||||||
out = chart.maxmin(name=fqsn)
|
|
||||||
|
|
||||||
if out is None:
|
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
|
mx_vlm_in_view = 0
|
||||||
|
|
||||||
|
@ -123,10 +127,9 @@ def chart_maxmin(
|
||||||
_, mx_vlm_in_view = out
|
_, mx_vlm_in_view = out
|
||||||
|
|
||||||
return (
|
return (
|
||||||
last_bars_range,
|
|
||||||
mx,
|
mx,
|
||||||
max(mn, 0), # presuming price can't be negative?
|
max(mn, 0), # presuming price can't be negative?
|
||||||
mx_vlm_in_view,
|
mx_vlm_in_view, # vlm max
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,7 +223,7 @@ async def increment_history_view(
|
||||||
do_append
|
do_append
|
||||||
and liv
|
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
|
# check if tread-in-place x-shift is needed
|
||||||
if should_tread:
|
if should_tread:
|
||||||
|
@ -307,9 +310,7 @@ async def graphics_update_loop(
|
||||||
fqsn,
|
fqsn,
|
||||||
vlm_chart,
|
vlm_chart,
|
||||||
)
|
)
|
||||||
last_bars_range: tuple[float, float]
|
|
||||||
(
|
(
|
||||||
last_bars_range,
|
|
||||||
last_mx,
|
last_mx,
|
||||||
last_mn,
|
last_mn,
|
||||||
last_mx_vlm,
|
last_mx_vlm,
|
||||||
|
@ -496,12 +497,11 @@ def graphics_update_cycle(
|
||||||
# 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_append`` above.
|
||||||
(
|
(
|
||||||
brange,
|
|
||||||
mx_in_view,
|
mx_in_view,
|
||||||
mn_in_view,
|
mn_in_view,
|
||||||
mx_vlm_in_view,
|
mx_vlm_in_view,
|
||||||
) = ds.maxmin()
|
) = ds.maxmin()
|
||||||
l, lbar, rbar, r = brange
|
|
||||||
mx = mx_in_view + tick_margin
|
mx = mx_in_view + tick_margin
|
||||||
mn = mn_in_view - tick_margin
|
mn = mn_in_view - tick_margin
|
||||||
profiler('`ds.maxmin()` call')
|
profiler('`ds.maxmin()` call')
|
||||||
|
@ -518,14 +518,12 @@ def graphics_update_cycle(
|
||||||
):
|
):
|
||||||
chart.update_graphics_from_flow(
|
chart.update_graphics_from_flow(
|
||||||
fqsn,
|
fqsn,
|
||||||
# chart.name,
|
|
||||||
# do_append=do_append,
|
# do_append=do_append,
|
||||||
)
|
)
|
||||||
main_viz.draw_last(array_key=fqsn)
|
main_viz.draw_last(array_key=fqsn)
|
||||||
|
|
||||||
hist_chart.update_graphics_from_flow(
|
hist_chart.update_graphics_from_flow(
|
||||||
fqsn,
|
fqsn,
|
||||||
# chart.name,
|
|
||||||
# do_append=do_append,
|
# do_append=do_append,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -540,7 +538,7 @@ def graphics_update_cycle(
|
||||||
or trigger_all
|
or trigger_all
|
||||||
):
|
):
|
||||||
chart.increment_view(datums=append_diff)
|
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
|
# NOTE: since vlm and ohlc charts are axis linked now we don't
|
||||||
# need the double increment request?
|
# need the double increment request?
|
||||||
|
@ -690,7 +688,7 @@ def graphics_update_cycle(
|
||||||
is_1m=True,
|
is_1m=True,
|
||||||
)
|
)
|
||||||
if hist_liv:
|
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
|
# XXX: update this every draw cycle to make
|
||||||
varz['last_mx'], varz['last_mn'] = mx, mn
|
varz['last_mx'], varz['last_mn'] = mx, mn
|
||||||
|
@ -705,7 +703,6 @@ def graphics_update_cycle(
|
||||||
and not viz.is_ohlc
|
and not viz.is_ohlc
|
||||||
):
|
):
|
||||||
update_fsp_chart(
|
update_fsp_chart(
|
||||||
chart,
|
|
||||||
viz,
|
viz,
|
||||||
curve_name,
|
curve_name,
|
||||||
array_key=curve_name,
|
array_key=curve_name,
|
||||||
|
@ -788,7 +785,6 @@ def graphics_update_cycle(
|
||||||
# and curve_name != fqsn
|
# and curve_name != fqsn
|
||||||
):
|
):
|
||||||
update_fsp_chart(
|
update_fsp_chart(
|
||||||
vlm_chart,
|
|
||||||
viz,
|
viz,
|
||||||
curve_name,
|
curve_name,
|
||||||
array_key=curve_name,
|
array_key=curve_name,
|
||||||
|
@ -800,7 +796,7 @@ def graphics_update_cycle(
|
||||||
# resizing from last quote?)
|
# resizing from last quote?)
|
||||||
fvb = viz.plot.vb
|
fvb = viz.plot.vb
|
||||||
fvb._set_yrange(
|
fvb._set_yrange(
|
||||||
name=curve_name,
|
viz=viz,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif (
|
elif (
|
||||||
|
|
|
@ -78,7 +78,6 @@ def has_vlm(ohlcv: ShmArray) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def update_fsp_chart(
|
def update_fsp_chart(
|
||||||
chart: ChartPlotWidget,
|
|
||||||
viz,
|
viz,
|
||||||
graphics_name: str,
|
graphics_name: str,
|
||||||
array_key: Optional[str],
|
array_key: Optional[str],
|
||||||
|
@ -101,18 +100,14 @@ def update_fsp_chart(
|
||||||
# update graphics
|
# update graphics
|
||||||
# NOTE: this does a length check internally which allows it
|
# NOTE: this does a length check internally which allows it
|
||||||
# staying above the last row check below..
|
# staying above the last row check below..
|
||||||
chart.update_graphics_from_flow(
|
viz.update_graphics()
|
||||||
graphics_name,
|
|
||||||
array_key=array_key or graphics_name,
|
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
# XXX: re: ``array_key``: fsp func names must be unique meaning we
|
# XXX: re: ``array_key``: fsp func names must be unique meaning we
|
||||||
# can't have duplicates of the underlying data even if multiple
|
# can't have duplicates of the underlying data even if multiple
|
||||||
# sub-charts reference it under different 'named charts'.
|
# sub-charts reference it under different 'named charts'.
|
||||||
|
|
||||||
# read from last calculated value and update any label
|
# 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)
|
'right')._stickies.get(graphics_name)
|
||||||
if last_val_sticky:
|
if last_val_sticky:
|
||||||
last = last_row[array_key]
|
last = last_row[array_key]
|
||||||
|
|
|
@ -45,6 +45,7 @@ from . import _event
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ._chart import ChartPlotWidget
|
from ._chart import ChartPlotWidget
|
||||||
|
from ._dataviz import Viz
|
||||||
|
|
||||||
|
|
||||||
log = get_logger(__name__)
|
log = get_logger(__name__)
|
||||||
|
@ -728,6 +729,7 @@ class ChartView(ViewBox):
|
||||||
*,
|
*,
|
||||||
|
|
||||||
yrange: Optional[tuple[float, float]] = None,
|
yrange: Optional[tuple[float, float]] = None,
|
||||||
|
viz: Viz | None = None,
|
||||||
|
|
||||||
# NOTE: this value pairs (more or less) with L1 label text
|
# NOTE: this value pairs (more or less) with L1 label text
|
||||||
# height offset from from the bid/ask lines.
|
# height offset from from the bid/ask lines.
|
||||||
|
|
Loading…
Reference in New Issue