Add `.ui._pathops` module
Starts a module for grouping together all our `QPainterpath` related generation and data format operations for creation of fast curve graphics. To start, drops `FastAppendCurve.downsample()` and moves it to a new `._pathops.xy_downsample()`.pre_flow
parent
3bf907c10f
commit
ce68e612de
|
@ -34,10 +34,11 @@ from PyQt5.QtCore import (
|
||||||
|
|
||||||
from .._profile import pg_profile_enabled, ms_slower_then
|
from .._profile import pg_profile_enabled, ms_slower_then
|
||||||
from ._style import hcolor
|
from ._style import hcolor
|
||||||
from ._compression import (
|
# from ._compression import (
|
||||||
# ohlc_to_m4_line,
|
# # ohlc_to_m4_line,
|
||||||
ds_m4,
|
# ds_m4,
|
||||||
)
|
# )
|
||||||
|
from ._pathops import xy_downsample
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,32 +175,6 @@ class FastAppendCurve(pg.GraphicsObject):
|
||||||
QLineF(lbar, 0, rbar, 0)
|
QLineF(lbar, 0, rbar, 0)
|
||||||
).length()
|
).length()
|
||||||
|
|
||||||
def downsample(
|
|
||||||
self,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
px_width,
|
|
||||||
uppx,
|
|
||||||
|
|
||||||
) -> tuple[np.ndarray, np.ndarray]:
|
|
||||||
|
|
||||||
# downsample whenever more then 1 pixels per datum can be shown.
|
|
||||||
# always refresh data bounds until we get diffing
|
|
||||||
# working properly, see above..
|
|
||||||
bins, x, y = ds_m4(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
px_width=px_width,
|
|
||||||
uppx=uppx,
|
|
||||||
# log_scale=bool(uppx)
|
|
||||||
)
|
|
||||||
x = np.broadcast_to(x[:, None], y.shape)
|
|
||||||
# x = (x + np.array([-0.43, 0, 0, 0.43])).flatten()
|
|
||||||
x = (x + np.array([-0.5, 0, 0, 0.5])).flatten()
|
|
||||||
y = y.flatten()
|
|
||||||
|
|
||||||
return x, y
|
|
||||||
|
|
||||||
def update_from_array(
|
def update_from_array(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
|
@ -396,7 +371,8 @@ class FastAppendCurve(pg.GraphicsObject):
|
||||||
self._in_ds = False
|
self._in_ds = False
|
||||||
|
|
||||||
elif should_ds and uppx and px_width > 1:
|
elif should_ds and uppx and px_width > 1:
|
||||||
x_out, y_out = self.downsample(
|
|
||||||
|
x_out, y_out = xy_downsample(
|
||||||
x_out,
|
x_out,
|
||||||
y_out,
|
y_out,
|
||||||
px_width,
|
px_width,
|
||||||
|
@ -461,7 +437,7 @@ class FastAppendCurve(pg.GraphicsObject):
|
||||||
)
|
)
|
||||||
|
|
||||||
# if should_ds:
|
# if should_ds:
|
||||||
# new_x, new_y = self.downsample(
|
# new_x, new_y = xy_downsample(
|
||||||
# new_x,
|
# new_x,
|
||||||
# new_y,
|
# new_y,
|
||||||
# px_width,
|
# px_width,
|
||||||
|
|
|
@ -789,37 +789,6 @@ class Flow(msgspec.Struct): # , frozen=True):
|
||||||
return graphics
|
return graphics
|
||||||
|
|
||||||
|
|
||||||
def xy_downsample(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
px_width,
|
|
||||||
uppx,
|
|
||||||
|
|
||||||
x_spacer: float = 0.5,
|
|
||||||
|
|
||||||
) -> tuple[np.ndarray, np.ndarray]:
|
|
||||||
|
|
||||||
# downsample whenever more then 1 pixels per datum can be shown.
|
|
||||||
# always refresh data bounds until we get diffing
|
|
||||||
# working properly, see above..
|
|
||||||
bins, x, y = ds_m4(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
px_width=px_width,
|
|
||||||
uppx=uppx,
|
|
||||||
log_scale=bool(uppx)
|
|
||||||
)
|
|
||||||
|
|
||||||
# flatten output to 1d arrays suitable for path-graphics generation.
|
|
||||||
x = np.broadcast_to(x[:, None], y.shape)
|
|
||||||
x = (x + np.array(
|
|
||||||
[-x_spacer, 0, 0, x_spacer]
|
|
||||||
)).flatten()
|
|
||||||
y = y.flatten()
|
|
||||||
|
|
||||||
return x, y
|
|
||||||
|
|
||||||
|
|
||||||
class Renderer(msgspec.Struct):
|
class Renderer(msgspec.Struct):
|
||||||
|
|
||||||
flow: Flow
|
flow: Flow
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
# piker: trading gear for hackers
|
||||||
|
# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0)
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
Super fast ``QPainterPath`` generation related operator routines.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
# from numba import njit, float64, int64 # , optional
|
||||||
|
# import pyqtgraph as pg
|
||||||
|
# from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
# from PyQt5.QtCore import QLineF, QPointF
|
||||||
|
|
||||||
|
from ._compression import (
|
||||||
|
# ohlc_flatten,
|
||||||
|
ds_m4,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def xy_downsample(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
px_width,
|
||||||
|
uppx,
|
||||||
|
|
||||||
|
x_spacer: float = 0.5,
|
||||||
|
|
||||||
|
) -> tuple[np.ndarray, np.ndarray]:
|
||||||
|
|
||||||
|
# downsample whenever more then 1 pixels per datum can be shown.
|
||||||
|
# always refresh data bounds until we get diffing
|
||||||
|
# working properly, see above..
|
||||||
|
bins, x, y = ds_m4(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
px_width=px_width,
|
||||||
|
uppx=uppx,
|
||||||
|
# log_scale=bool(uppx)
|
||||||
|
)
|
||||||
|
|
||||||
|
# flatten output to 1d arrays suitable for path-graphics generation.
|
||||||
|
x = np.broadcast_to(x[:, None], y.shape)
|
||||||
|
x = (x + np.array(
|
||||||
|
[-x_spacer, 0, 0, x_spacer]
|
||||||
|
)).flatten()
|
||||||
|
y = y.flatten()
|
||||||
|
|
||||||
|
return x, y
|
Loading…
Reference in New Issue