Tweak axis text offset and margins

vwap_backup
Tyler Goodlet 2020-11-16 17:39:14 -05:00
parent 80845024da
commit 757f02e6f7
1 changed files with 12 additions and 10 deletions

View File

@ -51,6 +51,8 @@ class Axis(pg.AxisItem):
self.setStyle(**{ self.setStyle(**{
'textFillLimits': [(0, 0.666)], 'textFillLimits': [(0, 0.666)],
'tickFont': _font.font, 'tickFont': _font.font,
# offset of text *away from* axis line in px
'tickTextOffset': 2,
}) })
self.setTickFont(_font.font) self.setTickFont(_font.font)
@ -88,11 +90,10 @@ class PriceAxis(Axis):
# print(f'digits: {digits}') # print(f'digits: {digits}')
return [ return [
('{value:,.{digits}f}') ('{value:,.{digits}f}').format(
.format( digits=digits,
digits=digits, value=v,
value=v, ).replace(',', ' ') for v in vals
).replace(',', ' ') for v in vals
] ]
@ -104,10 +105,11 @@ class DynamicDateAxis(Axis):
60: '%H:%M', 60: '%H:%M',
30: '%H:%M:%S', 30: '%H:%M:%S',
5: '%H:%M:%S', 5: '%H:%M:%S',
1: '%H:%M:%S',
} }
def resize(self) -> None: def resize(self) -> None:
self.setHeight(self.typical_br.height() + 3) self.setHeight(self.typical_br.height() + 1)
def _indexes_to_timestrs( def _indexes_to_timestrs(
self, self,
@ -228,6 +230,7 @@ class AxisLabel(pg.GraphicsObject):
class XAxisLabel(AxisLabel): class XAxisLabel(AxisLabel):
_w_margin = 4
text_flags = ( text_flags = (
QtCore.Qt.TextDontClip QtCore.Qt.TextDontClip
@ -255,14 +258,13 @@ class XAxisLabel(AxisLabel):
w = self.boundingRect().width() w = self.boundingRect().width()
self.setPos(QPointF( self.setPos(QPointF(
abs_pos.x() - w / 2 - offset, abs_pos.x() - w / 2 - offset,
0, 1,
)) ))
self.update() self.update()
class YAxisLabel(AxisLabel): class YAxisLabel(AxisLabel):
_h_margin = 3 _h_margin = 2
# _w_margin = 1
text_flags = ( text_flags = (
# QtCore.Qt.AlignLeft # QtCore.Qt.AlignLeft
@ -289,7 +291,7 @@ class YAxisLabel(AxisLabel):
br = self.boundingRect() br = self.boundingRect()
h = br.height() h = br.height()
self.setPos(QPointF( self.setPos(QPointF(
0, 1,
abs_pos.y() - h / 2 - offset abs_pos.y() - h / 2 - offset
)) ))
self.update() self.update()