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

View File

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

View File

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