From c976bff40c5ce6b0b2e98fdd3de7b99ac5a77a6a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 15 Mar 2022 09:11:12 -0400 Subject: [PATCH] Add `ChartPlotWidget.in_view()` shm-compatible array slicer --- piker/ui/_chart.py | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index 0eb1f3eb..5956459d 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -374,12 +374,15 @@ class LinkedSplits(QWidget): ''' ln = len(self.subplots) + # proportion allocated to consumer subcharts if not prop: - # proportion allocated to consumer subcharts - if ln < 2: - prop = 1/3 - elif ln >= 2: - prop = 3/8 + prop = 3/8*5/8 + + # if ln < 2: + # prop = 3/8*5/8 + + # elif ln >= 2: + # prop = 3/8 major = 1 - prop min_h_ind = int((self.height() * prop) / ln) @@ -842,7 +845,7 @@ class ChartPlotWidget(pg.PlotWidget): log.warning(f'array for {self.name} not loaded yet?') return - begin = xlast - _bars_to_left_in_follow_mode + begin = xlast - 1000 end = xlast + _bars_from_right_in_follow_mode # remove any custom user yrange setttings @@ -856,6 +859,11 @@ class ChartPlotWidget(pg.PlotWidget): padding=0, ) view._set_yrange() + self.view.maybe_downsample_graphics() + try: + self.linked.graphics_cycle() + except: + pass def increment_view( self, @@ -1001,12 +1009,6 @@ class ChartPlotWidget(pg.PlotWidget): # on data reads and makes graphics rendering no faster # clipToView=True, - # TODO: see how this handles with custom ohlcv bars graphics - # and/or if we can implement something similar for OHLC graphics - # autoDownsample=True, - # downsample=60, - # downsampleMethod='subsample', - **pdi_kwargs, ) @@ -1196,6 +1198,23 @@ class ChartPlotWidget(pg.PlotWidget): else: return ohlc['index'][-1] + def in_view( + self, + array: np.ndarray, + + ) -> np.ndarray: + ''' + Slice an input struct array providing only datums + "in view" of this chart. + + ''' + l, lbar, rbar, r = self.bars_range() + ifirst = array[0]['index'] + # slice data by offset from the first index + # available in the passed datum set. + start = lbar - ifirst + return array[lbar - ifirst:(rbar - ifirst) + 1] + def maxmin( self, name: Optional[str] = None,