Drop remaining usage of `ChartPlotWidget.default_view()`
Instead delegate directly to `Viz.default_view()` throughout charting startup and interaction handlers. Also add a `ChartPlotWidget.reset_graphics_caches()` context mngr which resets all managed graphics object's cacheing modes on enter and restores them on exit for simplified use in interaction handling code.storage_cli
parent
d32382f831
commit
80af431c2a
|
@ -19,6 +19,10 @@ High level chart-widget apis.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from contextlib import (
|
||||||
|
contextmanager as cm,
|
||||||
|
ExitStack,
|
||||||
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
Iterator,
|
Iterator,
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
|
@ -257,7 +261,9 @@ class GodWidget(QWidget):
|
||||||
# last had the xlast in view, if so then shift so it's
|
# last had the xlast in view, if so then shift so it's
|
||||||
# still in view, if the user was viewing history then
|
# still in view, if the user was viewing history then
|
||||||
# do nothing yah?
|
# do nothing yah?
|
||||||
self.rt_linked.chart.default_view()
|
self.rt_linked.chart.main_viz.default_view(
|
||||||
|
do_min_bars=True,
|
||||||
|
)
|
||||||
|
|
||||||
# if a history chart instance is already up then
|
# if a history chart instance is already up then
|
||||||
# set the search widget as its sidepane.
|
# set the search widget as its sidepane.
|
||||||
|
@ -811,11 +817,17 @@ class LinkedSplits(QWidget):
|
||||||
self.chart.sidepane.setMinimumWidth(sp_w)
|
self.chart.sidepane.setMinimumWidth(sp_w)
|
||||||
|
|
||||||
|
|
||||||
# TODO: we should really drop using this type and instead just
|
# TODO: a general rework of this widget-interface:
|
||||||
# write our own wrapper around `PlotItem`..
|
# - we should really drop using this type and instead just lever our
|
||||||
|
# own override of `PlotItem`..
|
||||||
|
# - possibly rename to class -> MultiChart(pg.PlotWidget):
|
||||||
|
# where the widget is responsible for containing management
|
||||||
|
# harness for multi-Viz "view lists" and their associated mode-panes
|
||||||
|
# (fsp chain, order ctl, feed queue-ing params, actor ctl, etc).
|
||||||
|
|
||||||
class ChartPlotWidget(pg.PlotWidget):
|
class ChartPlotWidget(pg.PlotWidget):
|
||||||
'''
|
'''
|
||||||
``GraphicsView`` subtype containing a ``.plotItem: PlotItem`` as well
|
``PlotWidget`` subtype containing a ``.plotItem: PlotItem`` as well
|
||||||
as a `.pi_overlay: PlotItemOverlay`` which helps manage and overlay flow
|
as a `.pi_overlay: PlotItemOverlay`` which helps manage and overlay flow
|
||||||
graphics view multiple compose view boxes.
|
graphics view multiple compose view boxes.
|
||||||
|
|
||||||
|
@ -1005,32 +1017,6 @@ class ChartPlotWidget(pg.PlotWidget):
|
||||||
# )
|
# )
|
||||||
return line_end, marker_right, r_axis_x
|
return line_end, marker_right, r_axis_x
|
||||||
|
|
||||||
def default_view(
|
|
||||||
self,
|
|
||||||
bars_from_y: int = int(616 * 3/8),
|
|
||||||
y_offset: int = 0,
|
|
||||||
do_ds: bool = True,
|
|
||||||
|
|
||||||
) -> None:
|
|
||||||
'''
|
|
||||||
Set the view box to the "default" startup view of the scene.
|
|
||||||
|
|
||||||
'''
|
|
||||||
viz = self.get_viz(self.name)
|
|
||||||
|
|
||||||
if not viz:
|
|
||||||
log.warning(f'`Viz` for {self.name} not loaded yet?')
|
|
||||||
return
|
|
||||||
|
|
||||||
viz.default_view(
|
|
||||||
bars_from_y,
|
|
||||||
y_offset,
|
|
||||||
do_ds,
|
|
||||||
)
|
|
||||||
|
|
||||||
if do_ds:
|
|
||||||
self.linked.graphics_cycle()
|
|
||||||
|
|
||||||
def increment_view(
|
def increment_view(
|
||||||
self,
|
self,
|
||||||
datums: int = 1,
|
datums: int = 1,
|
||||||
|
@ -1321,3 +1307,30 @@ class ChartPlotWidget(pg.PlotWidget):
|
||||||
|
|
||||||
def iter_vizs(self) -> Iterator[Viz]:
|
def iter_vizs(self) -> Iterator[Viz]:
|
||||||
return iter(self._vizs.values())
|
return iter(self._vizs.values())
|
||||||
|
|
||||||
|
@cm
|
||||||
|
def reset_graphics_caches(self) -> None:
|
||||||
|
'''
|
||||||
|
Reset all managed ``Viz`` (flow) graphics objects
|
||||||
|
Qt cache modes (to ``NoCache`` mode) on enter and
|
||||||
|
restore on exit.
|
||||||
|
|
||||||
|
'''
|
||||||
|
with ExitStack() as stack:
|
||||||
|
for viz in self.iter_vizs():
|
||||||
|
stack.enter_context(
|
||||||
|
viz.graphics.reset_cache(),
|
||||||
|
)
|
||||||
|
|
||||||
|
# also reset any downsampled alt-graphics objects which
|
||||||
|
# might be active.
|
||||||
|
dsg = viz.ds_graphics
|
||||||
|
if dsg:
|
||||||
|
stack.enter_context(
|
||||||
|
dsg.reset_cache(),
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
print("RESETTING ALL")
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
stack.close()
|
||||||
|
|
|
@ -419,7 +419,7 @@ async def graphics_update_loop(
|
||||||
ds.vlm_chart = vlm_chart
|
ds.vlm_chart = vlm_chart
|
||||||
ds.vlm_sticky = vlm_sticky
|
ds.vlm_sticky = vlm_sticky
|
||||||
|
|
||||||
fast_chart.default_view()
|
fast_chart.main_viz.default_view()
|
||||||
|
|
||||||
# ds.hist_vars.update({
|
# ds.hist_vars.update({
|
||||||
# 'i_last_append': 0,
|
# 'i_last_append': 0,
|
||||||
|
@ -1446,7 +1446,7 @@ async def display_symbol_data(
|
||||||
for fqsn, flume in feed.flumes.items():
|
for fqsn, flume in feed.flumes.items():
|
||||||
|
|
||||||
# size view to data prior to order mode init
|
# size view to data prior to order mode init
|
||||||
rt_chart.default_view()
|
rt_chart.main_viz.default_view()
|
||||||
rt_linked.graphics_cycle()
|
rt_linked.graphics_cycle()
|
||||||
|
|
||||||
# TODO: look into this because not sure why it was
|
# TODO: look into this because not sure why it was
|
||||||
|
@ -1457,7 +1457,7 @@ async def display_symbol_data(
|
||||||
# determine if auto-range adjustements should be made.
|
# determine if auto-range adjustements should be made.
|
||||||
# rt_linked.subplots.pop('volume', None)
|
# rt_linked.subplots.pop('volume', None)
|
||||||
|
|
||||||
hist_chart.default_view()
|
hist_chart.main_viz.default_view()
|
||||||
hist_linked.graphics_cycle()
|
hist_linked.graphics_cycle()
|
||||||
|
|
||||||
godwidget.resize_all()
|
godwidget.resize_all()
|
||||||
|
@ -1500,10 +1500,10 @@ async def display_symbol_data(
|
||||||
|
|
||||||
# default view adjuments and sidepane alignment
|
# default view adjuments and sidepane alignment
|
||||||
# as final default UX touch.
|
# as final default UX touch.
|
||||||
rt_chart.default_view()
|
rt_chart.main_viz.default_view()
|
||||||
await trio.sleep(0)
|
await trio.sleep(0)
|
||||||
|
|
||||||
hist_chart.default_view()
|
hist_chart.main_viz.default_view()
|
||||||
hist_viz = hist_chart.get_viz(fqsn)
|
hist_viz = hist_chart.get_viz(fqsn)
|
||||||
await trio.sleep(0)
|
await trio.sleep(0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue