TOSQUASH: 2dc706aa (.default_view w time)

pre_viz_calls
Tyler Goodlet 2022-11-29 13:44:34 -05:00
parent ea368496eb
commit 7e3a1720fc
1 changed files with 33 additions and 61 deletions

View File

@ -810,6 +810,8 @@ 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
# write our own wrapper around `PlotItem`..
class ChartPlotWidget(pg.PlotWidget): class ChartPlotWidget(pg.PlotWidget):
''' '''
``GraphicsView`` subtype containing a single ``PlotItem``. ``GraphicsView`` subtype containing a single ``PlotItem``.
@ -921,7 +923,7 @@ class ChartPlotWidget(pg.PlotWidget):
# show background grid # show background grid
self.showGrid(x=False, y=True, alpha=0.3) self.showGrid(x=False, y=True, alpha=0.3)
self.cv.enable_auto_yrange() # self.cv.enable_auto_yrange()
self.pi_overlay: PlotItemOverlay = PlotItemOverlay(self.plotItem) self.pi_overlay: PlotItemOverlay = PlotItemOverlay(self.plotItem)
@ -1012,21 +1014,17 @@ class ChartPlotWidget(pg.PlotWidget):
log.warning(f'`Viz` for {self.name} not loaded yet?') log.warning(f'`Viz` for {self.name} not loaded yet?')
return return
renderer = viz._src_r
if renderer is None:
return
( (
start, _,
l, l,
datum_start, datum_start,
datum_stop, datum_stop,
r, r,
stop, _,
) = viz.datums_range() ) = viz.datums_range()
array = viz.shm.array array = viz.shm.array
index_field = renderer.fmtr.index_field index_field = viz.index_field
if index_field == 'time': if index_field == 'time':
vr = viz.plot.viewRect() vr = viz.plot.viewRect()
@ -1043,21 +1041,20 @@ class ChartPlotWidget(pg.PlotWidget):
iv_arr = array[mask] iv_arr = array[mask]
index = iv_arr['index'] index = iv_arr['index']
else:
index = array['index']
# these must be array-index-ints (hence the slice from time # these must be array-index-ints (hence the slice from time
# above). # above).
x_start, x_stop = index[0], index[-1] x_start, x_stop = index[0], index[-1]
l, lbar, rbar, r = viz.bars_range()
view: ChartView = viz.plot.vb view: ChartView = viz.plot.vb
if ( if (
rbar < 0 datum_stop < 0
or l < x_start or l < x_start
or l < 0 or l < 0
or (rbar - lbar) < 6 or (datum_stop - datum_start) < 6
): ):
# TODO: set fixed bars count on screen that approx includes as
# many bars as possible before a downsample line is shown.
begin = x_stop - bars_from_y begin = x_stop - bars_from_y
view.setXRange( view.setXRange(
min=begin, min=begin,
@ -1065,29 +1062,35 @@ class ChartPlotWidget(pg.PlotWidget):
padding=0, padding=0,
) )
# re-get range # re-get range
l, lbar, rbar, r = viz.bars_range() l, datum_start, datum_stop, r = viz.bars_range()
# we get the L1 spread label "length" in view coords # we get the L1 spread label "length" in view coords
# terms now that we've scaled either by user control # terms now that we've scaled either by user control
# or to the default set of bars as per the immediate block # or to the default set of bars as per the immediate block
# above. # above.
debug_msg = (
f'x_stop: {x_stop}\n'
)
if not y_offset: if not y_offset:
marker_pos, l1_len = self.pre_l1_xs() marker_pos, l1_len = self.pre_l1_xs()
end = x_stop + l1_len + 1 end = x_stop + l1_len + 1
debug_msg += (
f'marker pos: {marker_pos}\n'
f'l1 len: {l1_len}\n'
)
else: else:
end = x_stop + y_offset + 1 end = x_stop + y_offset + 1
begin = end - (r - l) begin = end - (r - l)
# for debugging debug_msg += (
print(
# f'bars range: {brange}\n'
f'x_stop: {x_stop}\n'
f'marker pos: {marker_pos}\n'
f'l1 len: {l1_len}\n'
f'begin: {begin}\n'
f'end: {end}\n' f'end: {end}\n'
f'begin: {begin}\n'
) )
print(debug_msg)
# remove any custom user yrange setttings # remove any custom user yrange setttings
if self._static_yrange == 'axis': if self._static_yrange == 'axis':
@ -1361,35 +1364,6 @@ class ChartPlotWidget(pg.PlotWidget):
**kwargs, **kwargs,
) )
# def _label_h(self, yhigh: float, ylow: float) -> float:
# # compute contents label "height" in view terms
# # to avoid having data "contents" overlap with them
# if self._labels:
# label = self._labels[self.name][0]
# rect = label.itemRect()
# tl, br = rect.topLeft(), rect.bottomRight()
# vb = self.plotItem.vb
# try:
# # on startup labels might not yet be rendered
# top, bottom = (vb.mapToView(tl).y(), vb.mapToView(br).y())
# # XXX: magic hack, how do we compute exactly?
# label_h = (top - bottom) * 0.42
# except np.linalg.LinAlgError:
# label_h = 0
# else:
# label_h = 0
# # print(f'label height {self.name}: {label_h}')
# if label_h > yhigh - ylow:
# label_h = 0
# print(f"bounds (ylow, yhigh): {(ylow, yhigh)}")
# TODO: pretty sure we can just call the cursor # TODO: pretty sure we can just call the cursor
# directly not? i don't wee why we need special "signal proxies" # directly not? i don't wee why we need special "signal proxies"
# for this lul.. # for this lul..
@ -1426,22 +1400,20 @@ class ChartPlotWidget(pg.PlotWidget):
# TODO: here we should instead look up the ``Viz.shm.array`` # TODO: here we should instead look up the ``Viz.shm.array``
# and read directly from shm to avoid copying to memory first # and read directly from shm to avoid copying to memory first
# and then reading it again here. # and then reading it again here.
flow_key = name or self.name viz_key = name or self.name
viz = self._vizs.get(flow_key) viz = self._vizs.get(viz_key)
if ( if viz is None:
viz is None log.error(f"viz {viz_key} doesn't exist in chart {self.name} !?")
):
log.error(f"viz {flow_key} doesn't exist in chart {self.name} !?")
key = res = 0, 0 key = res = 0, 0
else: else:
( (
first, _,
l, l,
lbar, lbar,
rbar, rbar,
r, r,
last, _,
) = bars_range or viz.datums_range() ) = bars_range or viz.datums_range()
profiler(f'{self.name} got bars range') profiler(f'{self.name} got bars range')
@ -1453,7 +1425,7 @@ class ChartPlotWidget(pg.PlotWidget):
res is None res is None
): ):
log.warning( log.warning(
f"{flow_key} no mxmn for bars_range => {key} !?" f"{viz_key} no mxmn for bars_range => {key} !?"
) )
res = 0, 0 res = 0, 0
if not self._on_screen: if not self._on_screen:
@ -1461,7 +1433,7 @@ class ChartPlotWidget(pg.PlotWidget):
self._on_screen = True self._on_screen = True
profiler(f'yrange mxmn: {key} -> {res}') profiler(f'yrange mxmn: {key} -> {res}')
# print(f'{flow_key} yrange mxmn: {key} -> {res}') # print(f'{viz_key} yrange mxmn: {key} -> {res}')
return res return res
def get_viz( def get_viz(