Move `ui._compression`/`._pathops` to `.data` subpkg

Since these modules no longer contain Qt specific code we might
as well include them in the data sub-package.

Also, add `IncrementalFormatter.index_field` as single point to def the
indexing field that should be used for all x-domain graphics-data
rendering.
multichartz_backup
Tyler Goodlet 2022-11-24 16:22:20 -05:00
parent 579daea013
commit f874848a79
3 changed files with 14 additions and 27 deletions

View File

@ -31,7 +31,7 @@ from numba import njit, float64, int64 # , optional
# from PyQt5 import QtGui # from PyQt5 import QtGui
# from PyQt5.QtCore import QLineF, QPointF # from PyQt5.QtCore import QLineF, QPointF
from ..data._sharedmem import ( from ._sharedmem import (
ShmArray, ShmArray,
) )
# from .._profile import pg_profile_enabled, ms_slower_then # from .._profile import pg_profile_enabled, ms_slower_then
@ -41,26 +41,11 @@ from ._compression import (
if TYPE_CHECKING: if TYPE_CHECKING:
from ._render import ( from ._render import (
Renderer,
Viz, Viz,
) )
from .._profile import Profiler from .._profile import Profiler
def by_index_and_key(
renderer: Renderer,
array: np.ndarray,
array_key: str,
vr: tuple[int, int],
) -> tuple[
np.ndarray,
np.ndarray,
np.ndarray,
]:
return array['index'], array[array_key], 'all'
class IncrementalFormatter(msgspec.Struct): class IncrementalFormatter(msgspec.Struct):
''' '''
Incrementally updating, pre-path-graphics tracking, formatter. Incrementally updating, pre-path-graphics tracking, formatter.
@ -73,6 +58,7 @@ class IncrementalFormatter(msgspec.Struct):
''' '''
shm: ShmArray shm: ShmArray
viz: Viz viz: Viz
index_field: str = 'index'
# last read from shm (usually due to an update call) # last read from shm (usually due to an update call)
_last_read: tuple[ _last_read: tuple[
@ -406,7 +392,6 @@ class IncrementalFormatter(msgspec.Struct):
self, self,
src_shm: ShmArray, src_shm: ShmArray,
data_field: str, data_field: str,
index_field: str = 'index',
) -> tuple[ ) -> tuple[
np.ndarray, # x np.ndarray, # x
@ -420,7 +405,7 @@ class IncrementalFormatter(msgspec.Struct):
''' '''
y_nd = src_shm._array[data_field].copy() y_nd = src_shm._array[data_field].copy()
x_nd = src_shm._array[index_field].copy() x_nd = src_shm._array[self.index_field].copy()
return x_nd, y_nd return x_nd, y_nd
# XXX: was ``.update_xy()`` # XXX: was ``.update_xy()``
@ -477,7 +462,7 @@ class IncrementalFormatter(msgspec.Struct):
''' '''
return ( return (
array['index'], array[self.index_field],
array[array_key], array[array_key],
# 1d connection array or style-key to # 1d connection array or style-key to
@ -511,7 +496,7 @@ class OHLCBarsFmtr(IncrementalFormatter):
# generate an flat-interpolated x-domain # generate an flat-interpolated x-domain
x_nd = ( x_nd = (
np.broadcast_to( np.broadcast_to(
ohlc_shm._array['index'][:, None], ohlc_shm._array[self.index_field][:, None],
( (
ohlc_shm._array.size, ohlc_shm._array.size,
# 4, # only ohlc # 4, # only ohlc
@ -542,6 +527,7 @@ class OHLCBarsFmtr(IncrementalFormatter):
data: np.ndarray, data: np.ndarray,
start: int64, start: int64,
bar_gap: float64 = 0.43, bar_gap: float64 = 0.43,
index_field: str = 'index',
) -> tuple[ ) -> tuple[
np.ndarray, np.ndarray,
@ -573,7 +559,7 @@ class OHLCBarsFmtr(IncrementalFormatter):
high = q['high'] high = q['high']
low = q['low'] low = q['low']
close = q['close'] close = q['close']
index = float64(q['index']) index = float64(q[index_field])
istart = i * 6 istart = i * 6
istop = istart + 6 istop = istart + 6
@ -630,6 +616,7 @@ class OHLCBarsFmtr(IncrementalFormatter):
array, array,
start, start,
bar_gap=w, bar_gap=w,
index_field=self.index_field,
) )
return x, y, c return x, y, c
@ -722,7 +709,7 @@ class StepCurveFmtr(IncrementalFormatter):
for use by path graphics generation. for use by path graphics generation.
''' '''
i = shm._array['index'].copy() i = shm._array[self.index_field].copy()
out = shm._array[data_field].copy() out = shm._array[data_field].copy()
x_out = np.broadcast_to( x_out = np.broadcast_to(

View File

@ -37,17 +37,17 @@ from ..data._sharedmem import (
ShmArray, ShmArray,
) )
from ..data.feed import Flume from ..data.feed import Flume
from .._profile import ( from ..data._pathops import (
pg_profile_enabled,
# ms_slower_then,
)
from ._pathops import (
IncrementalFormatter, IncrementalFormatter,
OHLCBarsFmtr, # Plain OHLC renderer OHLCBarsFmtr, # Plain OHLC renderer
OHLCBarsAsCurveFmtr, # OHLC converted to line OHLCBarsAsCurveFmtr, # OHLC converted to line
StepCurveFmtr, # "step" curve (like for vlm) StepCurveFmtr, # "step" curve (like for vlm)
xy_downsample, xy_downsample,
) )
from .._profile import (
pg_profile_enabled,
# ms_slower_then,
)
from ._ohlc import ( from ._ohlc import (
BarItems, BarItems,
# bar_from_ohlc_row, # bar_from_ohlc_row,