From 8a43b76c96b46214d825fc798dcca99d5839c154 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 19 Jul 2019 17:34:08 +0800 Subject: [PATCH] [Fix] potential bug of KeyError when item_info_text is empty --- vnpy/chart/item.py | 2 +- vnpy/chart/widget.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/vnpy/chart/item.py b/vnpy/chart/item.py index 467b9c3e..979686df 100644 --- a/vnpy/chart/item.py +++ b/vnpy/chart/item.py @@ -115,7 +115,7 @@ class ChartItem(pg.GraphicsObject): max_ix = int(rect.right()) max_ix = min(max_ix, len(self._bar_picutures)) - rect_area = (rect.left(), rect.right()) + rect_area = (min_ix, max_ix) if rect_area != self._rect_area or not self._item_picuture: self._rect_area = rect_area self._draw_item_picture(min_ix, max_ix) diff --git a/vnpy/chart/widget.py b/vnpy/chart/widget.py index 53b5da1a..45c0b26c 100644 --- a/vnpy/chart/widget.py +++ b/vnpy/chart/widget.py @@ -470,10 +470,11 @@ class ChartCursor(QtCore.QObject): for item, plot in self._item_plot_map.items(): item_info_text = item.get_info_text(self._x) - if item_info_text: - if plot not in buf: - buf[plot] = item_info_text - else: + + if plot not in buf: + buf[plot] = item_info_text + else: + if item_info_text: buf[plot] += ("\n\n" + item_info_text) for plot_name, plot in self._plots.items():