Center bars around index, adjust curves back to match...

bar_select
Tyler Goodlet 2020-10-21 11:19:41 -04:00
parent cd828db9e9
commit f2c4a46c94
2 changed files with 14 additions and 16 deletions

View File

@ -120,7 +120,7 @@ async def cascade(
# TODO: talk to ``pyqtgraph`` core about proper way to solve this: # TODO: talk to ``pyqtgraph`` core about proper way to solve this:
# XXX: hack to get curves aligned with bars graphics: prepend # XXX: hack to get curves aligned with bars graphics: prepend
# a copy of the first datum.. # a copy of the first datum..
dst.push(history[:1]) # dst.push(history[:1])
# check for data length mis-allignment and fill missing values # check for data length mis-allignment and fill missing values
diff = len(src.array) - len(history) diff = len(src.array) - len(history)

View File

@ -10,7 +10,7 @@ from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import QLineF from PyQt5.QtCore import QLineF
# from .quantdom.utils import timeit # from .quantdom.utils import timeit
from ._style import _xaxis_at, hcolor from ._style import _xaxis_at, hcolor, _font
from ._axes import YAxisLabel, XAxisLabel from ._axes import YAxisLabel, XAxisLabel
# TODO: # TODO:
@ -197,15 +197,15 @@ class CrossHair(pg.GraphicsObject):
# Update x if cursor changed after discretization calc # Update x if cursor changed after discretization calc
# (this saves draw cycles on small mouse moves) # (this saves draw cycles on small mouse moves)
lastx = self._lastx lastx = self._lastx
newx = int(x) ix = round(x) # since bars are centered around index
if newx != lastx: if ix != lastx:
for plot, opts in self.graphics.items(): for plot, opts in self.graphics.items():
# move the vertical line to the current "center of bar" # move the vertical line to the current "center of bar"
opts['vl'].setX(newx + BarItems.w) opts['vl'].setX(ix)
# update the chart's "contents" label # update the chart's "contents" label
plot._update_contents_label(newx + 1) plot._update_contents_label(ix)
# update the label on the bottom of the crosshair # update the label on the bottom of the crosshair
self.xaxis_label.update_label( self.xaxis_label.update_label(
@ -215,7 +215,7 @@ class CrossHair(pg.GraphicsObject):
# update all subscribed curve dots # update all subscribed curve dots
for cursor in opts.get('cursors', ()): for cursor in opts.get('cursors', ()):
cursor.setIndex(newx + 1) cursor.setIndex(ix)
def boundingRect(self): def boundingRect(self):
try: try:
@ -250,7 +250,7 @@ def bars_from_ohlc(
# place the x-coord start as "middle" of the drawing range such # place the x-coord start as "middle" of the drawing range such
# that the open arm line-graphic is at the left-most-side of # that the open arm line-graphic is at the left-most-side of
# the indexe's range according to the view mapping. # the indexe's range according to the view mapping.
index_start = index + w index_start = index
# high - low line # high - low line
if low != high: if low != high:
@ -265,7 +265,7 @@ def bars_from_ohlc(
# open line # open line
o = QLineF(index_start - w, open, index_start, open) o = QLineF(index_start - w, open, index_start, open)
# close line # close line
c = QLineF(index_start + w, close, index_start, close) c = QLineF(index_start, close, index_start + w, close)
# indexing here is as per the below comments # indexing here is as per the below comments
lines[i] = (hl, o, c) lines[i] = (hl, o, c)
@ -439,7 +439,7 @@ class BarItems(pg.GraphicsObject):
body, larm, rarm = self.lines[index-1] body, larm, rarm = self.lines[index-1]
# XXX: is there a faster way to modify this? # XXX: is there a faster way to modify this?
# update right arm # update close line / right arm
rarm.setLine(rarm.x1(), last, rarm.x2(), last) rarm.setLine(rarm.x1(), last, rarm.x2(), last)
# update body # update body
@ -455,16 +455,13 @@ class BarItems(pg.GraphicsObject):
# if the bar was flat it likely does not have # if the bar was flat it likely does not have
# the index set correctly due to a rendering bug # the index set correctly due to a rendering bug
# see above # see above
body.setLine(i + self.w, low, i + self.w, high) body.setLine(i, low, i, high)
body._flat = False body._flat = False
else: else:
body.setLine(body.x1(), low, body.x2(), high) body.setLine(body.x1(), low, body.x2(), high)
self.draw_lines(just_history=False) self.draw_lines(just_history=False)
# be compat with ``pg.PlotCurveItem``
setData = update_from_array
# XXX: From the customGraphicsItem.py example: # XXX: From the customGraphicsItem.py example:
# The only required methods are paint() and boundingRect() # The only required methods are paint() and boundingRect()
# @timeit # @timeit
@ -566,6 +563,7 @@ def h_line(level: float) -> pg.InfiniteLine:
default_pen = pg.mkPen(hcolor('default')) default_pen = pg.mkPen(hcolor('default'))
line.setPen(default_pen) line.setPen(default_pen)
# os_line.label.setColor(hcolor('default_light')) if getattr(line, 'label', None):
# os_line.label.setFont(_font) line.label.setFont(_font)
return line return line