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