Size level line markers to dpi aware font size

readme_bumpz
Tyler Goodlet 2021-03-31 14:25:51 -04:00
parent 54d36f26f0
commit 0dfa92230d
1 changed files with 26 additions and 13 deletions

View File

@ -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