Skip to content

Commit

Permalink
Expect index_field: str in all graphics objects
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Nov 30, 2022
1 parent 0fd38d1 commit f97cc2d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
11 changes: 8 additions & 3 deletions piker/data/_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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]:
'''
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions piker/ui/_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -421,6 +423,7 @@ def draw_last_datum(
render_data: np.ndarray,
reset: bool,
array_key: str,
index_field: str,

w: float = 0.5,

Expand All @@ -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]
Expand Down Expand Up @@ -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
25 changes: 14 additions & 11 deletions piker/ui/_ohlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']

0 comments on commit f97cc2d

Please sign in to comment.