From 1140178b9d83f8f2c703d477784898f06fa9ad29 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 29 Nov 2022 13:44:34 -0500 Subject: [PATCH] TOSQUASH: 2dc706aa (.default_view w time) --- piker/ui/_chart.py | 94 ++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 61 deletions(-) diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index dd273758..1db354bf 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -810,6 +810,8 @@ class LinkedSplits(QWidget): 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): ''' ``GraphicsView`` subtype containing a single ``PlotItem``. @@ -921,7 +923,7 @@ class ChartPlotWidget(pg.PlotWidget): # show background grid 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) @@ -1012,21 +1014,17 @@ class ChartPlotWidget(pg.PlotWidget): log.warning(f'`Viz` for {self.name} not loaded yet?') return - renderer = viz._src_r - if renderer is None: - return - ( - start, + _, l, datum_start, datum_stop, r, - stop, + _, ) = viz.datums_range() array = viz.shm.array - index_field = renderer.fmtr.index_field + index_field = viz.index_field if index_field == 'time': vr = viz.plot.viewRect() @@ -1043,21 +1041,20 @@ class ChartPlotWidget(pg.PlotWidget): iv_arr = array[mask] index = iv_arr['index'] + else: + index = array['index'] + # these must be array-index-ints (hence the slice from time # above). x_start, x_stop = index[0], index[-1] - l, lbar, rbar, r = viz.bars_range() view: ChartView = viz.plot.vb if ( - rbar < 0 + datum_stop < 0 or l < x_start 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 view.setXRange( min=begin, @@ -1065,29 +1062,35 @@ class ChartPlotWidget(pg.PlotWidget): padding=0, ) # 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 # terms now that we've scaled either by user control # or to the default set of bars as per the immediate block # above. + debug_msg = ( + f'x_stop: {x_stop}\n' + ) + if not y_offset: marker_pos, l1_len = self.pre_l1_xs() end = x_stop + l1_len + 1 + + debug_msg += ( + f'marker pos: {marker_pos}\n' + f'l1 len: {l1_len}\n' + ) + else: end = x_stop + y_offset + 1 begin = end - (r - l) - # for debugging - 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' + debug_msg += ( f'end: {end}\n' + f'begin: {begin}\n' ) + print(debug_msg) # remove any custom user yrange setttings if self._static_yrange == 'axis': @@ -1361,35 +1364,6 @@ class ChartPlotWidget(pg.PlotWidget): **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 # directly not? i don't wee why we need special "signal proxies" # for this lul.. @@ -1426,22 +1400,20 @@ class ChartPlotWidget(pg.PlotWidget): # TODO: here we should instead look up the ``Viz.shm.array`` # and read directly from shm to avoid copying to memory first # and then reading it again here. - flow_key = name or self.name - viz = self._vizs.get(flow_key) - if ( - viz is None - ): - log.error(f"viz {flow_key} doesn't exist in chart {self.name} !?") + viz_key = name or self.name + viz = self._vizs.get(viz_key) + if viz is None: + log.error(f"viz {viz_key} doesn't exist in chart {self.name} !?") key = res = 0, 0 else: ( - first, + _, l, lbar, rbar, r, - last, + _, ) = bars_range or viz.datums_range() profiler(f'{self.name} got bars range') @@ -1453,7 +1425,7 @@ class ChartPlotWidget(pg.PlotWidget): res is None ): log.warning( - f"{flow_key} no mxmn for bars_range => {key} !?" + f"{viz_key} no mxmn for bars_range => {key} !?" ) res = 0, 0 if not self._on_screen: @@ -1461,7 +1433,7 @@ class ChartPlotWidget(pg.PlotWidget): self._on_screen = True profiler(f'yrange mxmn: {key} -> {res}') - # print(f'{flow_key} yrange mxmn: {key} -> {res}') + # print(f'{viz_key} yrange mxmn: {key} -> {res}') return res def get_viz(