Drop hidpi font size hacking from contents labels

status_bar
Tyler Goodlet 2021-06-04 11:30:15 -04:00
parent e924cbeb43
commit 112b3f0f07
1 changed files with 5 additions and 12 deletions

View File

@ -31,6 +31,7 @@ from .._style import (
_xaxis_at, _xaxis_at,
hcolor, hcolor,
_font, _font,
_font_small,
) )
from .._axes import YAxisLabel, XAxisLabel from .._axes import YAxisLabel, XAxisLabel
from ...log import get_logger from ...log import get_logger
@ -109,7 +110,7 @@ class LineDot(pg.CurvePoint):
return False return False
# TODO: change this into our own ``Label`` # TODO: change this into our own ``_label.Label``
class ContentsLabel(pg.LabelItem): class ContentsLabel(pg.LabelItem):
"""Label anchored to a ``ViewBox`` typically for displaying """Label anchored to a ``ViewBox`` typically for displaying
datum-wise points from the "viewed" contents. datum-wise points from the "viewed" contents.
@ -138,22 +139,14 @@ class ContentsLabel(pg.LabelItem):
justify_text: str = 'left', justify_text: str = 'left',
font_size: Optional[int] = None, font_size: Optional[int] = None,
) -> None: ) -> None:
font_size = font_size or _font.font.pixelSize()
font_size = font_size or _font_small.px_size
super().__init__( super().__init__(
justify=justify_text, justify=justify_text,
size=f'{str(font_size)}px' size=f'{str(font_size)}px'
) )
if _font._physical_dpi >= 97:
# ad-hoc scale it based on boundingRect
# TODO: need proper fix for this?
typical_br = _font._qfm.boundingRect('Qyp')
anchor_font_size = math.ceil(typical_br.height() * 1.25)
else:
anchor_font_size = font_size
# anchor to viewbox # anchor to viewbox
self.setParentItem(chart._vb) self.setParentItem(chart._vb)
chart.scene().addItem(self) chart.scene().addItem(self)
@ -165,7 +158,7 @@ class ContentsLabel(pg.LabelItem):
ydim = margins[1] ydim = margins[1]
if inspect.isfunction(margins[1]): if inspect.isfunction(margins[1]):
margins = margins[0], ydim(anchor_font_size) margins = margins[0], ydim(font_size)
self.anchor(itemPos=index, parentPos=index, offset=margins) self.anchor(itemPos=index, parentPos=index, offset=margins)