Skip to content

Commit

Permalink
Merge pull request #452 from pikers/l1_compaction
Browse files Browse the repository at this point in the history
Compact L1 labels
  • Loading branch information
goodboy authored Feb 13, 2023
2 parents 31fc2d7 + cee6321 commit 42d2f9e
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 155 deletions.
3 changes: 3 additions & 0 deletions piker/ui/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ def _indexes_to_timestrs(
times = array['time']
i_0, i_l = times[0], times[-1]

# edge cases
if (
not indexes
or
(indexes[0] < i_0
and indexes[-1] < i_l)
or
Expand Down
11 changes: 6 additions & 5 deletions piker/ui/_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,6 @@ class ChartPlotWidget(pg.PlotWidget):
sig_mouse_leave = QtCore.pyqtSignal(object)
sig_mouse_enter = QtCore.pyqtSignal(object)

_l1_labels: L1Labels = None

mode_name: str = 'view'

# TODO: can take a ``background`` color setting - maybe there's
Expand Down Expand Up @@ -986,13 +984,15 @@ def marker_right_points(
'''
# TODO: compute some sensible maximum value here
# and use a humanized scheme to limit to that length.
l1_len = self._max_l1_line_len
from ._l1 import L1Label
l1_len = abs(L1Label._x_br_offset)
ryaxis = self.getAxis('right')

r_axis_x = ryaxis.pos().x()
up_to_l1_sc = r_axis_x - l1_len
marker_right = up_to_l1_sc - (1.375 * 2 * marker_size)
line_end = marker_right - (6/16 * marker_size)
# line_end = marker_right - (6/16 * marker_size)
line_end = marker_right - marker_size

# print(
# f'r_axis_x: {r_axis_x}\n'
Expand Down Expand Up @@ -1231,7 +1231,8 @@ def draw_curve(
# (we need something that avoids clutter on x-axis).
axis.add_sticky(
pi=pi,
bg_color=color,
fg_color='black',
# bg_color=color,
digits=digits,
)

Expand Down
6 changes: 3 additions & 3 deletions piker/ui/_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(

plot: ChartPlotWidget, # type: ingore # noqa
pos=None,
color: str = 'default_light',
color: str = 'bracket',

) -> None:
# scale from dpi aware font size
Expand Down Expand Up @@ -349,7 +349,7 @@ def __init__(
# XXX: not sure why these are instance variables?
# It's not like we can change them on the fly..?
self.pen = pg.mkPen(
color=hcolor('default'),
color=hcolor('bracket'),
style=QtCore.Qt.DashLine,
)
self.lines_pen = pg.mkPen(
Expand All @@ -365,7 +365,7 @@ def __init__(
self._lw = self.pixelWidth() * self.lines_pen.width()

# xhair label's color name
self.label_color: str = 'default'
self.label_color: str = 'bracket'

self._y_label_update: bool = True

Expand Down
23 changes: 22 additions & 1 deletion piker/ui/_dataviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ def render_baritems(
)


_sample_rates: set[float] = {1, 60}


class Viz(msgspec.Struct): # , frozen=True):
'''
(Data) "Visualization" compound type which wraps a real-time
Expand Down Expand Up @@ -284,15 +287,33 @@ def index_step(
reset: bool = False,

) -> float:

# attempt to dectect the best step size by scanning a sample of
# the source data.
if self._index_step is None:

index = self.shm.array[self.index_field]
isample = index[:16]
mxdiff = np.diff(isample).max()

mxdiff: None | float = None
for step in np.diff(isample):
if step in _sample_rates:
if (
mxdiff is not None
and step != mxdiff
):
raise ValueError(
f'Multiple step sizes detected? {mxdiff}, {step}'
)
mxdiff = step

self._index_step = max(mxdiff, 1)
if (
mxdiff < 1
or 1 < mxdiff < 60
):
# TODO: remove this once we're sure the above scan loop
# is rock solid.
breakpoint()

return self._index_step
Expand Down
Loading

0 comments on commit 42d2f9e

Please sign in to comment.