From fc0a03d597b386abb2d822183730725a7df8bd00 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 9 Sep 2020 10:47:08 -0400 Subject: [PATCH] Handle OHLC *and* signal indexing --- piker/ui/_axes.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/piker/ui/_axes.py b/piker/ui/_axes.py index 2a705a53..46f64b5d 100644 --- a/piker/ui/_axes.py +++ b/piker/ui/_axes.py @@ -186,7 +186,10 @@ class XAxisLabel(AxisLabel): data: float, # data for text offset: int = 0 # if have margins, k? ) -> None: - self.label_str = self.parent._indexes_to_timestrs([int(data)])[0] + timestrs = self.parent._indexes_to_timestrs([int(data)]) + if not timestrs.any(): + return + self.label_str = timestrs[0] width = self.boundingRect().width() new_pos = QPointF(abs_pos.x() - width / 2 - offset, 0) self.setPos(new_pos) @@ -241,8 +244,20 @@ class YSticky(YAxisLabel): chart.sigRangeChanged.connect(self.update_on_resize) def update_on_resize(self, vr, r): - # TODO: figure out how to generalize across data schema - self.update_from_data(*self._chart._array[-1][['index', 'close']]) + # TODO: add an `.index` to the array data-buffer layer + # and make this way less shitty... + a = self._chart._array + fields = a.dtype.fields + if fields and 'index' in fields: + index, last = a[-1][['index', 'close']] + else: + # non-ohlc case + index = len(a) - 1 + last = a[-1] + self.update_from_data( + index, + last, + ) def update_from_data( self,