Use pixel buffers on axis labels

chart_trader
Tyler Goodlet 2020-12-29 14:34:25 -05:00
parent 1e09b0f08f
commit f3a0b1e91e
3 changed files with 16 additions and 7 deletions

View File

@ -22,7 +22,7 @@ from typing import List, Tuple, Optional
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, QtWidgets
from PyQt5.QtCore import QPointF from PyQt5.QtCore import QPointF
from ._style import DpiAwareFont, hcolor, _font from ._style import DpiAwareFont, hcolor, _font
@ -44,6 +44,10 @@ class Axis(pg.AxisItem):
) -> None: ) -> None:
super().__init__(**kwargs) super().__init__(**kwargs)
# XXX: pretty sure this makes things slower
# self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)
self.linked_charts = linked_charts self.linked_charts = linked_charts
self._min_tick = min_tick self._min_tick = min_tick
@ -158,9 +162,12 @@ class AxisLabel(pg.GraphicsObject):
fg_color: str = 'black', fg_color: str = 'black',
opacity: int = 0, opacity: int = 0,
font_size_inches: Optional[float] = None, font_size_inches: Optional[float] = None,
): ) -> None:
super().__init__(parent) super().__init__(parent)
self.setFlag(self.ItemIgnoresTransformations) self.setFlag(self.ItemIgnoresTransformations)
# XXX: pretty sure this is faster
self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)
self.parent = parent self.parent = parent
self.opacity = opacity self.opacity = opacity
@ -177,7 +184,12 @@ class AxisLabel(pg.GraphicsObject):
self.rect = None self.rect = None
def paint(self, p, option, widget): def paint(
self,
p: QtGui.QPainter,
opt: QtWidgets.QStyleOptionGraphicsItem,
w: QtWidgets.QWidget
) -> None:
# p.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver) # p.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)
if self.label_str: if self.label_str:

View File

@ -218,7 +218,6 @@ class CrossHair(pg.GraphicsObject):
self.active_plot = None self.active_plot = None
self.digits = digits self.digits = digits
self._lastx = None self._lastx = None
# self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)
def add_plot( def add_plot(
self, self,
@ -240,7 +239,6 @@ class CrossHair(pg.GraphicsObject):
opacity=_ch_label_opac, opacity=_ch_label_opac,
bg_color='default', bg_color='default',
) )
yl.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)
yl.hide() # on startup if mouse is off screen yl.hide() # on startup if mouse is off screen
# TODO: checkout what ``.sigDelayed`` can be used for # TODO: checkout what ``.sigDelayed`` can be used for
@ -283,8 +281,6 @@ class CrossHair(pg.GraphicsObject):
) )
# place label off-screen during startup # place label off-screen during startup
self.xaxis_label.setPos(self.plots[0].mapFromView(QPointF(0, 0))) self.xaxis_label.setPos(self.plots[0].mapFromView(QPointF(0, 0)))
self.xaxis_label.setCacheMode(
QtGui.QGraphicsItem.DeviceCoordinateCache)
def add_curve_cursor( def add_curve_cursor(
self, self,

View File

@ -25,6 +25,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from ..._profile import pg_profile_enabled from ..._profile import pg_profile_enabled
# TODO: got a feeling that dropping this inheritance gets us even more speedups
class FastAppendCurve(pg.PlotCurveItem): class FastAppendCurve(pg.PlotCurveItem):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):