Further label and axis sizing tweaks for hidpi

bar_select
Tyler Goodlet 2020-09-29 12:28:54 -04:00
parent e524ee9045
commit 8276b02f92
4 changed files with 28 additions and 50 deletions

View File

@ -29,7 +29,7 @@ class PriceAxis(pg.AxisItem):
}) })
self.setLabel(**{'font-size': '10pt'}) self.setLabel(**{'font-size': '10pt'})
self.setTickFont(_font) self.setTickFont(_font)
self.setWidth(50) self.setWidth(40)
# XXX: drop for now since it just eats up h space # XXX: drop for now since it just eats up h space

View File

@ -15,7 +15,10 @@ from ._axes import (
) )
from ._graphics import CrossHair, BarItems from ._graphics import CrossHair, BarItems
from ._axes import YSticky from ._axes import YSticky
from ._style import _xaxis_at, _min_points_to_show, hcolor from ._style import (
_xaxis_at, _min_points_to_show, hcolor,
CHART_MARGINS,
)
from ..data._source import Symbol from ..data._source import Symbol
from .. import brokers from .. import brokers
from .. import data from .. import data
@ -31,9 +34,6 @@ from .. import fsp
log = get_logger(__name__) log = get_logger(__name__)
# margins
CHART_MARGINS = (0, 0, 5, 3)
class ChartSpace(QtGui.QWidget): class ChartSpace(QtGui.QWidget):
"""High level widget which contains layouts for organizing """High level widget which contains layouts for organizing
@ -135,13 +135,16 @@ class LinkedSplitCharts(QtGui.QWidget):
linked_charts=self linked_charts=self
) )
if _xaxis_at == 'bottom': # if _xaxis_at == 'bottom':
self.xaxis.setStyle(showValues=False) # self.xaxis.setStyle(showValues=False)
else: # # self.xaxis.hide()
self.xaxis_ind.setStyle(showValues=False) # else:
# self.xaxis_ind.setStyle(showValues=False)
# self.xaxis.hide()
self.splitter = QtGui.QSplitter(QtCore.Qt.Vertical) self.splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
self.splitter.setHandleWidth(5) self.splitter.setMidLineWidth(3)
self.splitter.setHandleWidth(0)
self.layout = QtGui.QVBoxLayout(self) self.layout = QtGui.QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setContentsMargins(0, 0, 0, 0)
@ -187,6 +190,8 @@ class LinkedSplitCharts(QtGui.QWidget):
) )
# add crosshair graphic # add crosshair graphic
self.chart.addItem(self._ch) self.chart.addItem(self._ch)
if _xaxis_at == 'bottom':
self.chart.hideAxis('bottom')
# style? # style?
self.chart.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain) self.chart.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
@ -226,8 +231,9 @@ class LinkedSplitCharts(QtGui.QWidget):
cpw.name = name cpw.name = name
cpw.plotItem.vb.linked_charts = self cpw.plotItem.vb.linked_charts = self
cpw.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain) cpw.setFrameStyle(QtGui.QFrame.StyledPanel) # | QtGui.QFrame.Plain)
cpw.getPlotItem().setContentsMargins(*CHART_MARGINS) cpw.getPlotItem().setContentsMargins(*CHART_MARGINS)
cpw.hideButtons()
# link chart x-axis to main quotes chart # link chart x-axis to main quotes chart
cpw.setXLink(self.chart) cpw.setXLink(self.chart)
@ -285,7 +291,6 @@ class ChartPlotWidget(pg.PlotWidget):
background=hcolor('papas_special'), background=hcolor('papas_special'),
# parent=None, # parent=None,
# plotItem=None, # plotItem=None,
# useOpenGL=True,
**kwargs **kwargs
) )
self._array = array # readonly view of data self._array = array # readonly view of data
@ -431,10 +436,11 @@ class ChartPlotWidget(pg.PlotWidget):
size='4pt', size='4pt',
) )
label.setParentItem(self._vb) label.setParentItem(self._vb)
# label.setParentItem(self.getPlotItem())
if overlay: if overlay:
# position bottom left if an overlay # position bottom left if an overlay
label.anchor(itemPos=(0, 1), parentPos=(0, 1), offset=(0, 25)) label.anchor(itemPos=(0, 1), parentPos=(0, 1), offset=(0, 14))
self._overlays[name] = curve self._overlays[name] = curve
label.show() label.show()
@ -512,6 +518,14 @@ class ChartPlotWidget(pg.PlotWidget):
begin = 0 - extra begin = 0 - extra
end = len(self._array) - 1 + extra end = len(self._array) - 1 + extra
# XXX: test code for only rendering lines for the bars in view.
# This turns out to be very very poor perf when scaling out to
# many bars (think > 1k) on screen.
# name = self.name
# bars = self._graphics[self.name]
# bars.draw_lines(
# istart=max(lbar, l), iend=min(rbar, r), just_history=True)
# bars_len = rbar - lbar # bars_len = rbar - lbar
# log.trace( # log.trace(
# f"\nl: {l}, lbar: {lbar}, rbar: {rbar}, r: {r}\n" # f"\nl: {l}, lbar: {lbar}, rbar: {rbar}, r: {r}\n"
@ -701,12 +715,12 @@ async def chart_from_quotes(
# faster then msgs arrive.. needs some tinkering and # faster then msgs arrive.. needs some tinkering and
# testing # testing
array = ohlcv.array array = ohlcv.array
last = array[-1]
chart.update_from_array( chart.update_from_array(
chart.name, chart.name,
array, array,
) )
# update sticky(s) # update sticky(s)
last = array[-1]
last_price_sticky.update_from_data(*last[['index', 'close']]) last_price_sticky.update_from_data(*last[['index', 'close']])
chart._set_yrange() chart._set_yrange()

View File

@ -13,41 +13,6 @@ from PyQt5.QtCore import QLineF
from ._style import _xaxis_at, hcolor from ._style import _xaxis_at, hcolor
from ._axes import YAxisLabel, XAxisLabel from ._axes import YAxisLabel, XAxisLabel
def rec2array(
rec: np.ndarray,
fields: List[str] = None
) -> np.ndarray:
"""Convert record array to std array.
Taken from:
https://github.com/scikit-hep/root_numpy/blob/master/root_numpy/_utils.py#L20
"""
simplify = False
if fields is None:
fields = rec.dtype.names
elif isinstance(fields, str):
fields = [fields]
simplify = True
# Creates a copy and casts all data to the same type
arr = np.dstack([rec[field] for field in fields])
# Check for array-type fields. If none, then remove outer dimension.
# Only need to check first field since np.dstack will anyway raise an
# exception if the shapes don't match
# np.dstack will also fail if fields is an empty list
if not rec.dtype[fields[0]].shape:
arr = arr[0]
if simplify:
# remove last dimension (will be of size 1)
arr = arr.reshape(arr.shape[:-1])
return arr
# TODO: # TODO:
# - checkout pyqtgraph.PlotCurveItem.setCompositionMode # - checkout pyqtgraph.PlotCurveItem.setCompositionMode

View File

@ -13,7 +13,6 @@ _i3_rgba = QtGui.QColor.fromRgbF(*[0.14]*3 + [1])
# splitter widget config # splitter widget config
_xaxis_at = 'bottom' _xaxis_at = 'bottom'
# charting config # charting config
_min_points_to_show = 3 _min_points_to_show = 3
CHART_MARGINS = (0, 0, 2, 2) CHART_MARGINS = (0, 0, 2, 2)