Implement `tickStrings` for price axis; use float_digits()
parent
18dc809acb
commit
7be624de39
|
@ -3,14 +3,13 @@ Chart axes graphics and behavior.
|
||||||
"""
|
"""
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
# import numpy as np
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from PyQt5 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui
|
||||||
from PyQt5.QtCore import QPointF
|
from PyQt5.QtCore import QPointF
|
||||||
|
|
||||||
from ._style import _font, hcolor
|
from ._style import _font, hcolor
|
||||||
|
from ..data._source import float_digits
|
||||||
|
|
||||||
|
|
||||||
class PriceAxis(pg.AxisItem):
|
class PriceAxis(pg.AxisItem):
|
||||||
|
@ -21,7 +20,7 @@ class PriceAxis(pg.AxisItem):
|
||||||
super().__init__(orientation='right')
|
super().__init__(orientation='right')
|
||||||
self.setTickFont(_font)
|
self.setTickFont(_font)
|
||||||
self.setStyle(**{
|
self.setStyle(**{
|
||||||
'textFillLimits': [(0, 0.5)],
|
'textFillLimits': [(0, 0.666)],
|
||||||
# 'tickTextWidth': 100,
|
# 'tickTextWidth': 100,
|
||||||
# 'tickTextHeight': 20,
|
# 'tickTextHeight': 20,
|
||||||
'tickFont': _font,
|
'tickFont': _font,
|
||||||
|
@ -35,11 +34,15 @@ class PriceAxis(pg.AxisItem):
|
||||||
|
|
||||||
# XXX: drop for now since it just eats up h space
|
# XXX: drop for now since it just eats up h space
|
||||||
|
|
||||||
# def tickStrings(self, vals, scale, spacing):
|
def tickStrings(self, vals, scale, spacing):
|
||||||
# digts = max(0, np.ceil(-np.log10(spacing * scale)))
|
digits = float_digits(spacing * scale)
|
||||||
# return [
|
|
||||||
# ('{:<8,.%df}' % digts).format(v).replace(',', ' ') for v in vals
|
# print(f'vals: {vals}\nscale: {scale}\nspacing: {spacing}')
|
||||||
# ]
|
# print(f'digits: {digits}')
|
||||||
|
|
||||||
|
return [
|
||||||
|
('{:,.%df}' % digits).format(v).replace(',', ' ') for v in vals
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class DynamicDateAxis(pg.AxisItem):
|
class DynamicDateAxis(pg.AxisItem):
|
||||||
|
@ -83,7 +86,7 @@ class DynamicDateAxis(pg.AxisItem):
|
||||||
map(int, filter(lambda i: i < bars_len, indexes))
|
map(int, filter(lambda i: i < bars_len, indexes))
|
||||||
)]
|
)]
|
||||||
# TODO: **don't** have this hard coded shift to EST
|
# TODO: **don't** have this hard coded shift to EST
|
||||||
dts = pd.to_datetime(epochs, unit='s') #- 4*pd.offsets.Hour()
|
dts = pd.to_datetime(epochs, unit='s') # - 4*pd.offsets.Hour()
|
||||||
return dts.strftime(self.tick_tpl[delay])
|
return dts.strftime(self.tick_tpl[delay])
|
||||||
|
|
||||||
def tickStrings(self, values: List[float], scale, spacing):
|
def tickStrings(self, values: List[float], scale, spacing):
|
||||||
|
@ -245,7 +248,6 @@ class YSticky(YAxisLabel):
|
||||||
# TODO: add an `.index` to the array data-buffer layer
|
# TODO: add an `.index` to the array data-buffer layer
|
||||||
# and make this way less shitty...
|
# and make this way less shitty...
|
||||||
chart = self._chart
|
chart = self._chart
|
||||||
name = chart.name
|
|
||||||
a = chart._array
|
a = chart._array
|
||||||
fields = a.dtype.fields
|
fields = a.dtype.fields
|
||||||
if fields and 'close' in fields:
|
if fields and 'close' in fields:
|
||||||
|
|
Loading…
Reference in New Issue