From 0dfa92230d7ccdd29cc0cd5bb2253d545997ff9e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 31 Mar 2021 14:25:51 -0400 Subject: [PATCH] Size level line markers to dpi aware font size --- piker/ui/_graphics/_lines.py | 39 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/piker/ui/_graphics/_lines.py b/piker/ui/_graphics/_lines.py index 6277bc3b..d2c5cf87 100644 --- a/piker/ui/_graphics/_lines.py +++ b/piker/ui/_graphics/_lines.py @@ -18,6 +18,7 @@ Lines for orders, alerts, L2. """ +from math import floor from typing import Tuple, Optional, List import pyqtgraph as pg @@ -27,7 +28,7 @@ from PyQt5.QtCore import QPointF from .._annotate import mk_marker, qgo_draw_markers from .._label import Label, vbr_left, right_axis -from .._style import hcolor +from .._style import hcolor, _font # TODO: probably worth investigating if we can @@ -628,11 +629,17 @@ def order_line( ) if show_markers: + font_size = _font.font.pixelSize() + + # scale marker size with dpi-aware font size + arrow_size = floor(1.375 * font_size) + alert_size = arrow_size * 0.666 + # add arrow marker on end of line nearest y-axis marker_style, marker_size = { - 'buy': ('|<', 20), - 'sell': ('>|', 20), - 'alert': ('v', 12), + 'buy': ('|<', arrow_size), + 'sell': ('>|', arrow_size), + 'alert': ('v', alert_size), }[action] # this fixes it the artifact issue! .. of course, bouding rect stuff @@ -695,7 +702,7 @@ def order_line( rlabel = line.add_label( side='right', side_of_axis='left', - x_offset=3*marker_size + 5, + x_offset=4*marker_size, fmt_str=( '{size:.{size_digits}f} ' ), @@ -739,14 +746,6 @@ def position_line( hide_xhair_on_hover=False, use_marker_margin=True, ) - if size > 0: - arrow_path = mk_marker('|<') - - elif size < 0: - arrow_path = mk_marker('>|') - - line.add_marker(arrow_path) - # hide position marker when out of view (for now) vb = line.getViewBox() @@ -775,6 +774,20 @@ def position_line( rlabel.render() rlabel.show() + # arrow marker + # scale marker size with dpi-aware font size + font_size = _font.font.pixelSize() + + # scale marker size with dpi-aware font size + arrow_size = floor(1.375 * font_size) + + if size > 0: + style = '|<' + elif size < 0: + style = '>|' + + arrow_path = mk_marker(style, size=arrow_size) + line.add_marker(arrow_path) line.set_level(level) # sanity check