diff --git a/piker/data/_compression.py b/piker/data/_compression.py index aed1d7d3bf..e6111fcab6 100644 --- a/piker/data/_compression.py +++ b/piker/data/_compression.py @@ -35,13 +35,17 @@ log = get_logger(__name__) -def hl2mxmn(ohlc: np.ndarray) -> np.ndarray: +def hl2mxmn( + ohlc: np.ndarray, + index_field: str = 'index', + +) -> np.ndarray: ''' Convert a OHLC struct-array containing 'high'/'low' columns to a "joined" max/min 1-d array. ''' - index = ohlc['index'] + index = ohlc[index_field] hls = ohlc[[ 'low', 'high', @@ -109,6 +113,7 @@ def trace_hl( def ohlc_flatten( ohlc: np.ndarray, use_mxmn: bool = True, + index_field: str = 'index', ) -> tuple[np.ndarray, np.ndarray]: ''' @@ -117,7 +122,7 @@ def ohlc_flatten( evenly (by 0.5 steps) over each index. ''' - index = ohlc['index'] + index = ohlc[index_field] if use_mxmn: # traces a line optimally over highs to lows diff --git a/piker/ui/_curve.py b/piker/ui/_curve.py index 663b328f70..8df1cda059 100644 --- a/piker/ui/_curve.py +++ b/piker/ui/_curve.py @@ -360,11 +360,12 @@ def draw_last_datum( render_data: np.ndarray, reset: bool, array_key: str, + index_field: str, ) -> None: # default line draw last call # with self.reset_cache(): - x = render_data['index'] + x = render_data[index_field] y = render_data[array_key] # draw the "current" step graphic segment so it @@ -391,10 +392,11 @@ def draw_last_datum( render_data: np.ndarray, reset: bool, array_key: str, + index_field: str, ) -> None: lasts = src_data[-2:] - x = lasts['index'] + x = lasts[index_field] y = lasts['close'] # draw the "current" step graphic segment so it @@ -421,6 +423,7 @@ def draw_last_datum( render_data: np.ndarray, reset: bool, array_key: str, + index_field: str, w: float = 0.5, @@ -429,7 +432,7 @@ def draw_last_datum( # TODO: remove this and instead place all step curve # updating into pre-path data render callbacks. # full input data - x = src_data['index'] + x = src_data[index_field] y = src_data[array_key] x_last = x[-1] @@ -458,9 +461,3 @@ def sub_paint( # p.drawLines(*tuple(filter(bool, self._last_step_lines))) # p.drawRect(self._last_step_rect) p.fillRect(self._last_step_rect, self._brush) - - # def sub_br( - # self, - # parent_br: QRectF | None = None, - # ) -> QRectF: - # return self._last_step_rect diff --git a/piker/ui/_ohlc.py b/piker/ui/_ohlc.py index 2ce23d30fe..98ffcb85ba 100644 --- a/piker/ui/_ohlc.py +++ b/piker/ui/_ohlc.py @@ -59,8 +59,8 @@ def bar_from_ohlc_row( OHLC "bar" for use in the "last datum" of a series. ''' - open, high, low, close, index = row[ - ['open', 'high', 'low', 'close', 'index']] + open, high, low, close, index = row #[fields] + # ['open', 'high', 'low', 'close', 'index']] # TODO: maybe consider using `QGraphicsLineItem` ?? # gives us a ``.boundingRect()`` on the objects which may make @@ -217,30 +217,33 @@ def draw_last_datum( render_data: np.ndarray, reset: bool, array_key: str, + index_field: str, + ) -> None: + + # relevant fields fields: list[str] = [ - 'index', 'open', 'high', 'low', 'close', - ], - - ) -> None: - - # relevant fields + index_field, + ] ohlc = src_data[fields] # last_row = ohlc[-1:] # individual values - last_row = i, o, h, l, last = ohlc[-1] + last_row = o, h, l, last, i = ohlc[-1] # times = src_data['time'] # if times[-1] - times[-2]: # breakpoint() # generate new lines objects for updatable "current bar" - self._last_bar_lines = bar_from_ohlc_row(last_row) + self._last_bar_lines = bar_from_ohlc_row( + last_row, + # fields, + ) # assert i == graphics.start_index - 1 # assert i == last_index @@ -270,4 +273,4 @@ def draw_last_datum( # because i've seen it do this to bars i - 3 back? # return ohlc['time'], ohlc['close'] - return ohlc['index'], ohlc['close'] + return ohlc[index_field], ohlc['close']