From 7a259b03ec65b3d04d4c715182b798ad9d32bac7 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 5 Jan 2023 15:13:02 -0500 Subject: [PATCH] Fix query-mode cursor labels to work with epoch-indexing --- piker/ui/_cursor.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/piker/ui/_cursor.py b/piker/ui/_cursor.py index 3172be1a..8c358c3f 100644 --- a/piker/ui/_cursor.py +++ b/piker/ui/_cursor.py @@ -198,12 +198,11 @@ class ContentsLabel(pg.LabelItem): self, name: str, - index: int, + ix: int, array: np.ndarray, ) -> None: # this being "html" is the dumbest shit :eyeroll: - first = array[0]['index'] self.setText( "i:{index}
" @@ -216,7 +215,7 @@ class ContentsLabel(pg.LabelItem): "C:{}
" "V:{}
" "wap:{}".format( - *array[index - first][ + *array[ix][ [ 'time', 'open', @@ -228,7 +227,7 @@ class ContentsLabel(pg.LabelItem): ] ], name=name, - index=index, + index=ix, ) ) @@ -236,15 +235,12 @@ class ContentsLabel(pg.LabelItem): self, name: str, - index: int, + ix: int, array: np.ndarray, ) -> None: - - first = array[0]['index'] - if index < array[-1]['index'] and index > first: - data = array[index - first][name] - self.setText(f"{name}: {data:.2f}") + data = array[ix][name] + self.setText(f"{name}: {data:.2f}") class ContentsLabels: @@ -269,17 +265,20 @@ class ContentsLabels: def update_labels( self, - index: int, + x_in: int, ) -> None: for chart, name, label, update in self._labels: viz = chart.get_viz(name) array = viz.shm.array + index = array[viz.index_field] + start = index[0] + stop = index[-1] if not ( - index >= 0 - and index < array[-1]['index'] + x_in >= start + and x_in <= stop ): # out of range print('WTF out of range?') @@ -288,7 +287,10 @@ class ContentsLabels: # call provided update func with data point try: label.show() - update(index, array) + ix = np.searchsorted(index, x_in) + if ix > len(array): + breakpoint() + update(ix, array) except IndexError: log.exception(f"Failed to update label: {name}")