From 3a515afccde730c44f95be1ee12dc80ad61edf1f Mon Sep 17 00:00:00 2001 From: goodboy Date: Wed, 28 Jan 2026 16:30:41 -0500 Subject: [PATCH] Use `get_fonts()`, add `show_txt` flag to gap annots Switch `.tsp._annotate.markup_gaps()` to use new `.ui._style.get_fonts()` API for font size calc on client side and add optional `show_txt: bool` flag to toggle gap duration labels (with default `False`). Also, - replace `sgn` checks with named bools: `up_gap`, `down_gap` - use `small_font.px_size - 1` for gap label font sizing - wrap text creation in `if show_txt:` block - update IPC handler to use `get_fonts()` vs direct `_font` import (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- piker/tsp/_annotate.py | 58 ++++++++++++++++++++++++----------------- piker/ui/_remote_ctl.py | 5 ++-- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/piker/tsp/_annotate.py b/piker/tsp/_annotate.py index 81c28394..7e91300f 100644 --- a/piker/tsp/_annotate.py +++ b/piker/tsp/_annotate.py @@ -30,7 +30,7 @@ import tractor from piker.data._formatters import BGM from piker.storage import log -# from piker.ui._style import _font +from piker.ui._style import get_fonts if TYPE_CHECKING: from piker.ui._remote_ctl import AnnotCtl @@ -88,6 +88,10 @@ async def markup_gaps( wdts: pl.DataFrame, gaps: pl.DataFrame, + # XXX, switch on to see txt showing a "humanized" label of each + # gap's duration. + show_txt: bool = False, + ) -> dict[int, dict]: ''' Remote annotate time-gaps in a dt-fielded ts (normally OHLC) @@ -202,6 +206,10 @@ async def markup_gaps( diff: float = cls - opn sgn: float = copysign(1, diff) + up_gap: bool = sgn == -1 + down_gap: bool = sgn == 1 + flat: bool = sgn == 0 + color: str = 'dad_blue' # TODO? mks more sense to have up/down coloring? # color: str = { @@ -233,7 +241,7 @@ async def markup_gaps( assert aid aids[aid] = rect_kwargs direction: str = ( - 'down' if sgn == 1 + 'down' if down_gap else 'up' ) # TODO! mk this a `msgspec.Struct` which we deserialize @@ -261,31 +269,33 @@ async def markup_gaps( ) # add duration label to RHS of arrow - if sgn == -1: # up-gap - anchor = (0, 0) # XXX, i dun get dese dims.. XD - else: # down-gap + if up_gap: + anchor = (0, 0) + # ^XXX? i dun get dese dims.. XD + elif down_gap: anchor = (0, 1) # XXX y, x? + else: # no-gap? + assert flat + anchor = (0, 0) # up from bottom - # ?TODO? why returning -1 !? - # [ ] use conf.toml value instead! - # - # font_size: int = _font.font.pixelSize() - 10 - # await tractor.pause() - # assert isinstance(font_size, int) - font_size = None + # use a slightly smaller font for gap label txt. + font, small_font = get_fonts() + font_size: int = small_font.px_size - 1 + assert isinstance(font_size, int) - text_aid: int = await actl.add_text( - fqme=fqme, - timeframe=timeframe, - text=gap_label, - x=iend + 1, # fallback if timestamp lookup fails - y=cls, - time=gap_time, # server-side index lookup - color=color, - anchor=anchor, - font_size=font_size, - ) - aids[text_aid] = {'text': gap_label} + if show_txt: + text_aid: int = await actl.add_text( + fqme=fqme, + timeframe=timeframe, + text=gap_label, + x=iend + 1, # fallback if timestamp lookup fails + y=cls, + time=gap_time, # server-side index lookup + color=color, + anchor=anchor, + font_size=font_size, + ) + aids[text_aid] = {'text': gap_label} # tell chart to redraw all its # graphics view layers Bo diff --git a/piker/ui/_remote_ctl.py b/piker/ui/_remote_ctl.py index b1775841..f67f80ad 100644 --- a/piker/ui/_remote_ctl.py +++ b/piker/ui/_remote_ctl.py @@ -407,8 +407,9 @@ async def serve_rc_annots( # apply font size (default to DpiAwareFont if not # provided) if font_size is None: - from ._style import _font - font_size = _font.font.pixelSize() - 3 + from ._style import get_fonts + font, font_small = get_fonts() + font_size = font_small.px_size - 1 qfont: QFont = text_item.textItem.font() qfont.setPixelSize(font_size)