Base axis text offset on dpi-aware font size

readme_bumpz
Tyler Goodlet 2021-03-31 14:24:39 -04:00
parent 3bd87caf4b
commit 3f7d9c5c15
1 changed files with 15 additions and 15 deletions

View File

@ -18,8 +18,8 @@
Chart axes graphics and behavior.
"""
from typing import List, Tuple, Optional
from math import floor
import pandas as pd
import pyqtgraph as pg
@ -51,13 +51,24 @@ class Axis(pg.AxisItem):
self.linked_charts = linked_charts
self._min_tick = min_tick
self._dpi_font = _font
self.setTickFont(_font.font)
font_size = self._dpi_font.font.pixelSize()
if self.orientation in ('bottom',):
text_offset = floor(0.25 * font_size)
elif self.orientation in ('left', 'right'):
text_offset = floor(font_size / 2)
self.setStyle(**{
'textFillLimits': [(0, 0.5)],
'tickFont': _font.font,
'tickFont': self._dpi_font.font,
# offset of text *away from* axis line in px
'tickTextOffset': 6,
# use approx. half the font pixel size (height)
'tickTextOffset': text_offset,
})
self.setTickFont(_font.font)
@ -79,17 +90,6 @@ class Axis(pg.AxisItem):
class PriceAxis(Axis):
def __init__(
self,
*args,
**kwargs,
) -> None:
super().__init__(*args, **kwargs)
self.setStyle(**{
# offset of text *away from* axis line in px
'tickTextOffset': 9,
})
def size_to_values(self) -> None:
self.setWidth(self.typical_br.width())
@ -457,7 +457,7 @@ class YAxisLabel(AxisLabel):
path = QtGui.QPainterPath()
h = self.rect.height()
path.moveTo(0, 0)
path.lineTo(-x_offset - 4, h/2.)
path.lineTo(-x_offset - h/4, h/2.)
path.lineTo(0, h)
path.closeSubpath()
self.path = path