diff --git a/piker/ui/_axes.py b/piker/ui/_axes.py index 973145c1..43dc28ef 100644 --- a/piker/ui/_axes.py +++ b/piker/ui/_axes.py @@ -29,7 +29,7 @@ class PriceAxis(pg.AxisItem): }) self.setLabel(**{'font-size': '10pt'}) self.setTickFont(_font) - self.setWidth(125) + self.setWidth(50) # XXX: drop for now since it just eats up h space @@ -61,12 +61,12 @@ class DynamicDateAxis(pg.AxisItem): # default styling self.setStyle( - tickTextOffset=7, + tickTextOffset=4, textFillLimits=[(0, 0.70)], # TODO: doesn't seem to work -> bug in pyqtgraph? - # tickTextHeight=2, + # tickTextHeight=11, ) - # self.setHeight(35) + self.setHeight(10) def _indexes_to_timestrs( self, @@ -175,7 +175,7 @@ class XAxisLabel(AxisLabel): # TODO: we need to get the parent axe's dimensions transformed # to abs coords to be 100% correct here: # self.parent.boundingRect() - return QtCore.QRectF(0, 0, 100, 31) + return QtCore.QRectF(0, 2, 40, 10) def update_label( self, @@ -206,7 +206,7 @@ class YAxisLabel(AxisLabel): return ('{: ,.%df}' % self.digits).format(tick_pos).replace(',', ' ') def boundingRect(self): # noqa - return QtCore.QRectF(0, 0, 120, 30) + return QtCore.QRectF(0, 0, 50, 11) def update_label( self, diff --git a/piker/ui/_exec.py b/piker/ui/_exec.py index c169640d..c1f247d9 100644 --- a/piker/ui/_exec.py +++ b/piker/ui/_exec.py @@ -8,16 +8,29 @@ from functools import partial import traceback from typing import Tuple, Callable, Dict, Any +# Qt specific import PyQt5 # noqa from pyqtgraph import QtGui from PyQt5 import QtCore -from PyQt5.QtCore import pyqtRemoveInputHook +from PyQt5.QtCore import ( + pyqtRemoveInputHook, Qt, QCoreApplication +) import qdarkstyle + import trio import tractor from outcome import Error +# Proper high DPI scaling is available in Qt >= 5.6.0. This attibute +# must be set before creating the application +if hasattr(Qt, 'AA_EnableHighDpiScaling'): + QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) + +# if hasattr(Qt, 'AA_UseHighDpiPixmaps'): +# QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) + + class MainWindow(QtGui.QMainWindow): size = (800, 500) diff --git a/piker/ui/_graphics.py b/piker/ui/_graphics.py index e0824dee..623c0e14 100644 --- a/piker/ui/_graphics.py +++ b/piker/ui/_graphics.py @@ -9,7 +9,7 @@ import pyqtgraph as pg from PyQt5 import QtCore, QtGui from PyQt5.QtCore import QLineF -from .quantdom.utils import timeit +# from .quantdom.utils import timeit from ._style import _xaxis_at, hcolor from ._axes import YAxisLabel, XAxisLabel @@ -286,7 +286,6 @@ class BarItems(pg.GraphicsObject): ) -> None: super().__init__() self.last = QtGui.QPicture() - # self.buffer = QtGui.QPicture() self.history = QtGui.QPicture() # TODO: implement updateable pixmap solution self._pi = plotitem @@ -307,10 +306,12 @@ class BarItems(pg.GraphicsObject): # @timeit def draw_from_data( self, - data: np.recarray, + data: np.ndarray, start: int = 0, ): - """Draw OHLC datum graphics from a ``np.recarray``. + """Draw OHLC datum graphics from a ``np.ndarray``. + + This routine is usually only called to draw the initial history. """ lines = bars_from_ohlc(data, self.w, start=start) @@ -332,20 +333,16 @@ class BarItems(pg.GraphicsObject): ) -> None: """Draw the current line set using the painter. """ - # start = time.time() - if just_history: - istart = 0 + # draw bars for the "history" picture iend = iend or self.index - 1 pic = self.history else: + # draw the last bar istart = self.index - 1 - iend = self.index + iend = iend or self.index pic = self.last - if iend is not None: - iend = iend - # use 2d array of lines objects, see conlusion on speed: # https://stackoverflow.com/a/60089929 to_draw = np.ravel(self.lines[istart:iend]) @@ -370,9 +367,6 @@ class BarItems(pg.GraphicsObject): # https://doc.qt.io/qt-5/qgraphicsitem.html#update self.update() - # diff = time.time() - start - # print(f'{len(to_draw)} lines update took {diff}') - def update_from_array( self, array: np.ndarray, @@ -407,9 +401,7 @@ class BarItems(pg.GraphicsObject): return # current bar update - i, open, close, = array[-1][['index', 'open', 'close']] - last = close - # i, body, larm, rarm = self.lines[index-1] + i, open, last, = array[-1][['index', 'open', 'close']] body, larm, rarm = self.lines[index-1] # XXX: is there a faster way to modify this? @@ -443,13 +435,18 @@ class BarItems(pg.GraphicsObject): # The only required methods are paint() and boundingRect() # @timeit def paint(self, p, opt, widget): - # start = time.time() # TODO: use to avoid drawing artefacts? # self.prepareGeometryChange() # p.setCompositionMode(0) + # TODO: one thing we could try here is pictures being drawn of + # a fixed count of bars such that based on the viewbox indices we + # only draw the "rounded up" number of "pictures worth" of bars + # as is necesarry for what's in "view". Not sure if this will + # lead to any perf gains other then when zoomed in to less bars + # in view. p.drawPicture(0, 0, self.history) p.drawPicture(0, 0, self.last) @@ -458,9 +455,6 @@ class BarItems(pg.GraphicsObject): # self._pmi.setPixmap(self.picture) # print(self.scene()) - # diff = time.time() - start - # print(f'draw time {diff}') - def boundingRect(self): # TODO: can we do rect caching to make this faster? diff --git a/piker/ui/_style.py b/piker/ui/_style.py index d3fdaad5..8d8f5099 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -10,13 +10,14 @@ from qdarkstyle.palette import DarkPalette _font = QtGui.QFont("Hack", 4) _i3_rgba = QtGui.QColor.fromRgbF(*[0.14]*3 + [1]) - # splitter widget config _xaxis_at = 'bottom' # charting config _min_points_to_show = 3 +CHART_MARGINS = (0, 0, 2, 2) + _tina_mode = False