Drop `.group_maxmin()`

We ended up doing groups maxmin sorting at the interaction layer (new
the view box) and thus this method is no longer needed, though it was
the reference for the code now in `ChartView.interact_graphics_cycle()`.

Further this adds a `remove_axes: bool` arg to `.insert_plotitem()`
which can be used to drop axis entries from the inserted pi (though it
doesn't seem like we really ever need that?) and does the removal in
a separate loop to avoid removing axes before they are registered in
`ComposedGridLayout._pi2axes`.
log_linearized_curve_overlays
Tyler Goodlet 2023-01-21 17:58:10 -05:00
parent 0591cb09f6
commit 7e421ba57b
1 changed files with 20 additions and 98 deletions

View File

@ -115,6 +115,7 @@ class ComposedGridLayout:
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0) layout.setSpacing(0)
layout.setMinimumWidth(0)
if name in ('top', 'bottom'): if name in ('top', 'bottom'):
orient = Qt.Vertical orient = Qt.Vertical
@ -124,7 +125,11 @@ class ComposedGridLayout:
layout.setOrientation(orient) layout.setOrientation(orient)
self.insert_plotitem(0, pi) self.insert_plotitem(
0,
pi,
remove_axes=False,
)
# insert surrounding linear layouts into the parent pi's layout # insert surrounding linear layouts into the parent pi's layout
# such that additional axes can be appended arbitrarily without # such that additional axes can be appended arbitrarily without
@ -139,7 +144,9 @@ class ComposedGridLayout:
assert linlayout.itemAt(0) is axis assert linlayout.itemAt(0) is axis
# XXX: see comment in ``.insert_plotitem()``... # XXX: see comment in ``.insert_plotitem()``...
# our `PlotItem.removeAxis()` does this internally.
# pi.layout.removeItem(axis) # pi.layout.removeItem(axis)
pi.layout.addItem(linlayout, *index) pi.layout.addItem(linlayout, *index)
layout = pi.layout.itemAt(*index) layout = pi.layout.itemAt(*index)
assert layout is linlayout assert layout is linlayout
@ -164,6 +171,8 @@ class ComposedGridLayout:
index: int, index: int,
plotitem: PlotItem, plotitem: PlotItem,
remove_axes: bool = False,
) -> tuple[int, list[AxisItem]]: ) -> tuple[int, list[AxisItem]]:
''' '''
Place item at index by inserting all axes into the grid Place item at index by inserting all axes into the grid
@ -205,13 +214,6 @@ class ComposedGridLayout:
): ):
continue continue
# XXX: Remove old axis?
# No, turns out we don't need this?
# DON'T UNLINK IT since we need the original ``ViewBox`` to
# still drive it with events/handlers B)
# popped = plotitem.removeAxis(name, unlink=False)
# assert axis is popped
# invert insert index for layouts which are # invert insert index for layouts which are
# not-left-to-right, top-to-bottom insert oriented # not-left-to-right, top-to-bottom insert oriented
insert_index = index insert_index = index
@ -224,6 +226,16 @@ class ComposedGridLayout:
self._register_item(index, plotitem) self._register_item(index, plotitem)
if remove_axes:
for name, axis_info in plotitem.axes.copy().items():
axis = axis_info['item']
# XXX: Remove old axis?
# No, turns out we don't need this?
# DON'T UNLINK IT since we need the original ``ViewBox`` to
# still drive it with events/handlers B)
popped = plotitem.removeAxis(name, unlink=False)
assert axis is popped
return (index, inserted_axes) return (index, inserted_axes)
def append_plotitem( def append_plotitem(
@ -577,93 +589,3 @@ class PlotItemOverlay:
# ''' # '''
# ... # ...
def group_maxmin(
self,
focus_around: str | None = None,
force_min: float | None = None,
) -> tuple[
float, # mn
float, # mx
float, # max range in % terms of highest sigma plot's y-range
PlotItem, # front/selected plot
]:
'''
Overlay "group" maxmin sorting.
Assumes all named flows are in the same co-domain and thus can
be sorted as one set.
Iterates all the named flows and calls the chart api to find
their range values and return.
TODO: really we should probably have a more built-in API for
this?
'''
# TODO:
# - use this in the ``.ui._fsp`` mutli-maxmin stuff
# -
# force 0 to always be in view
group_mx: float = 0
group_mn: float = 0
mx_up_rng: float = 0
mn_down_rng: float = 0
pis2ranges: dict[
PlotItem,
tuple[float, float],
] = {}
for pi in self.overlays:
# TODO: can we remove this from the widget
# and place somewhere more related to UX/Viz?
# name = pi.name
# chartw = pi.chart_widget
viz = pi.viz
# viz = chartw._vizs[name]
out = viz.maxmin()
if out is None:
return None
(
(x_start, x_stop),
read_slc,
(ymn, ymx),
) = out
arr = viz.shm.array
y_start = arr[read_slc.start - 1]
y_stop = arr[read_slc.stop - 1]
if viz.is_ohlc:
y_start = y_start['open']
y_stop = y_stop['close']
else:
y_start = y_start[viz.name]
y_stop = y_stop[viz.name]
# update max for group
up_rng = (ymx - y_start) / y_start
down_rng = (y_stop - ymn) / y_stop
# compute directional (up/down) y-range % swing/dispersion
mx_up_rng = max(mx_up_rng, up_rng)
mn_down_rng = min(mn_down_rng, down_rng)
pis2ranges[pi] = (ymn, ymx)
group_mx = max(group_mx, ymx)
if force_min is None:
group_mn = min(group_mn, ymn)
return (
group_mn if force_min is None else force_min,
group_mx,
mn_down_rng,
mx_up_rng,
pis2ranges,
)