[Mod] improve chart drawing performance

This commit is contained in:
vn.py 2019-07-19 00:26:58 +08:00
parent 66b46704e6
commit af37ba8beb
3 changed files with 12 additions and 2 deletions

View File

@ -32,6 +32,8 @@ class ChartItem(pg.GraphicsObject):
)
self._down_brush: QtGui.QBrush = pg.mkBrush(color=DOWN_COLOR)
self._rect_area: Tuple[float, float] = None
@abstractmethod
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
"""
@ -109,7 +111,11 @@ class ChartItem(pg.GraphicsObject):
min_ix = int(rect.left())
max_ix = int(rect.right())
max_ix = min(max_ix, len(self._bar_picutures))
self._draw_item_picture(min_ix, max_ix)
rect_area = (rect.left(), rect.right())
if rect_area != self._rect_area or not self._item_picuture:
self._rect_area = rect_area
self._draw_item_picture(min_ix, max_ix)
self._item_picuture.play(painter)

View File

@ -118,6 +118,7 @@ class BarManager:
max_price = max(max_price, bar.high_price)
min_price = min(min_price, bar.low_price)
self._price_ranges[(min_ix, max_ix)] = (min_price, max_price)
return min_price, max_price
def get_volume_range(self, min_ix: float = None, max_ix: float = None) -> Tuple[float, float]:
@ -148,6 +149,7 @@ class BarManager:
for bar in bar_list[1:]:
max_volume = max(max_volume, bar.volume)
self._volume_ranges[(min_ix, max_ix)] = (min_volume, max_volume)
return min_volume, max_volume
def _clear_cache(self) -> None:

View File

@ -399,7 +399,8 @@ class ChartCursor(QtCore.QObject):
"""
self._proxy = pg.SignalProxy(
self._widget.scene().sigMouseMoved,
rateLimit=360,
delay=0.1,
rateLimit=60,
slot=self._mouse_moved
)
@ -412,6 +413,7 @@ class ChartCursor(QtCore.QObject):
# First get current mouse point
pos = evt[0]
for plot_name, view in self._views.items():
rect = view.sceneBoundingRect()