diff --git a/vnpy/chart/item.py b/vnpy/chart/item.py index e04c7643..c63adee3 100644 --- a/vnpy/chart/item.py +++ b/vnpy/chart/item.py @@ -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) diff --git a/vnpy/chart/manager.py b/vnpy/chart/manager.py index a786eed6..d4beda07 100644 --- a/vnpy/chart/manager.py +++ b/vnpy/chart/manager.py @@ -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: diff --git a/vnpy/chart/widget.py b/vnpy/chart/widget.py index e00aab1b..caf4c8a9 100644 --- a/vnpy/chart/widget.py +++ b/vnpy/chart/widget.py @@ -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()