Base axis text offset on dpi-aware font size
parent
3bd87caf4b
commit
3f7d9c5c15
|
@ -18,8 +18,8 @@
|
||||||
Chart axes graphics and behavior.
|
Chart axes graphics and behavior.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import List, Tuple, Optional
|
from typing import List, Tuple, Optional
|
||||||
|
from math import floor
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
@ -51,13 +51,24 @@ class Axis(pg.AxisItem):
|
||||||
|
|
||||||
self.linked_charts = linked_charts
|
self.linked_charts = linked_charts
|
||||||
self._min_tick = min_tick
|
self._min_tick = min_tick
|
||||||
|
self._dpi_font = _font
|
||||||
|
|
||||||
self.setTickFont(_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(**{
|
self.setStyle(**{
|
||||||
'textFillLimits': [(0, 0.5)],
|
'textFillLimits': [(0, 0.5)],
|
||||||
'tickFont': _font.font,
|
'tickFont': self._dpi_font.font,
|
||||||
|
|
||||||
# offset of text *away from* axis line in px
|
# 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)
|
self.setTickFont(_font.font)
|
||||||
|
@ -79,17 +90,6 @@ class Axis(pg.AxisItem):
|
||||||
|
|
||||||
class PriceAxis(Axis):
|
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:
|
def size_to_values(self) -> None:
|
||||||
self.setWidth(self.typical_br.width())
|
self.setWidth(self.typical_br.width())
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ class YAxisLabel(AxisLabel):
|
||||||
path = QtGui.QPainterPath()
|
path = QtGui.QPainterPath()
|
||||||
h = self.rect.height()
|
h = self.rect.height()
|
||||||
path.moveTo(0, 0)
|
path.moveTo(0, 0)
|
||||||
path.lineTo(-x_offset - 4, h/2.)
|
path.lineTo(-x_offset - h/4, h/2.)
|
||||||
path.lineTo(0, h)
|
path.lineTo(0, h)
|
||||||
path.closeSubpath()
|
path.closeSubpath()
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
Loading…
Reference in New Issue