From ccaedfae3fe82a101642defeb873fa49a44b35f0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 3 Jul 2020 18:08:03 -0400 Subject: [PATCH] Handle high = low bars For whatever reason if the `QLineF` high/low values are the same a weird little rectangle is drawn (my guess is a `float` precision error of some sort). Instead, if they're the same just use one of the values. Also, store local vars to avoid so many lookups. --- piker/ui/_graphics.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/piker/ui/_graphics.py b/piker/ui/_graphics.py index 31c71139..d179cc22 100644 --- a/piker/ui/_graphics.py +++ b/piker/ui/_graphics.py @@ -18,7 +18,7 @@ from ._axes import YAxisLabel, XAxisLabel # TODO: checkout pyqtgraph.PlotCurveItem.setCompositionMode -_mouse_rate_limit = 50 +_mouse_rate_limit = 40 class CrossHairItem(pg.GraphicsObject): @@ -175,8 +175,7 @@ class BarItems(pg.GraphicsObject): sigPlotChanged = QtCore.Signal(object) w: float = 0.5 - - bull_brush = bear_brush = pg.mkPen('#808080') + bull_pen = pg.mkPen('#808080') # XXX: tina mode, see below # bull_brush = pg.mkPen('#00cc00') @@ -211,19 +210,26 @@ class BarItems(pg.GraphicsObject): with self.painter() as p: for i, q in enumerate(data): + low = q['low'] + high = q['high'] + index = q['index'] + + # high - low line + if low != high: + hl = QLineF(index, low, index, high) + else: + # if we don't do it renders a weird rectangle? + hl = QLineF(low, low, low, low) + # open line + o = QLineF(index - self.w, q['open'], index, q['open']) + # close line + c = QLineF(index + self.w, q['close'], index, q['close']) + # indexing here is as per the below comments - lines[3*i:3*i+3] = ( - # high_to_low - QLineF(q['index'], q['low'], q['index'], q['high']), - # open_sticks - QLineF(q['index'] - self.w, q['open'], q['index'], q['open']), - # close_sticks - QtCore.QLineF( - q['index'] + self.w, q['close'], q['index'], q['close']) - ) - # if not _tina_mode: # piker mode - p.setPen(self.bull_brush) + lines[3*i:3*i+3] = (hl, o, c) + p.setPen(self.bull_pen) p.drawLines(*lines) + # if not _tina_mode: # piker mode # else _tina_mode: # self.lines = lines = np.concatenate( # [high_to_low, open_sticks, close_sticks])