Always just look up the current plot on mouse handling

its_happening
Tyler Goodlet 2020-07-17 10:32:13 -04:00
parent b97286d7f5
commit a59497c949
1 changed files with 11 additions and 20 deletions

View File

@ -11,8 +11,6 @@ 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 .quantdom.base import Quotes
from ._style import _xaxis_at # , _tina_mode from ._style import _xaxis_at # , _tina_mode
from ._axes import YAxisLabel, XAxisLabel from ._axes import YAxisLabel, XAxisLabel
@ -27,8 +25,7 @@ class CrossHair(pg.GraphicsObject):
def __init__(self, parent, digits: int = 0): def __init__(self, parent, digits: int = 0):
super().__init__() super().__init__()
# self.pen = pg.mkPen('#000000') self.pen = pg.mkPen('#a9a9a9') # gray?
self.pen = pg.mkPen('#a9a9a9')
self.parent = parent self.parent = parent
self.graphics = {} self.graphics = {}
self.plots = [] self.plots = []
@ -89,8 +86,6 @@ class CrossHair(pg.GraphicsObject):
self.xaxis_label = XAxisLabel(parent=xaxis, opacity=1) self.xaxis_label = XAxisLabel(parent=xaxis, opacity=1)
def mouseAction(self, action, plot): # noqa def mouseAction(self, action, plot): # noqa
# TODO: why do we no handle all plots the same?
# -> main plot has special path? would simplify code.
if action == 'Enter': if action == 'Enter':
# show horiz line and y-label # show horiz line and y-label
self.graphics[plot]['hl'].show() self.graphics[plot]['hl'].show()
@ -108,9 +103,15 @@ class CrossHair(pg.GraphicsObject):
""" """
pos = evt[0] pos = evt[0]
# find position in main chart # find position inside active plot
mouse_point = self.plots[0].mapToView(pos) mouse_point = self.active_plot.mapToView(pos)
self.graphics[self.active_plot]['hl'].setY(
mouse_point.y()
)
self.graphics[self.active_plot]['yl'].update_label(
evt_post=pos, point_view=mouse_point
)
# move the vertical line to the current x coordinate in all charts # move the vertical line to the current x coordinate in all charts
for opts in self.graphics.values(): for opts in self.graphics.values():
opts['vl'].setX(mouse_point.x()) opts['vl'].setX(mouse_point.x())
@ -118,22 +119,12 @@ class CrossHair(pg.GraphicsObject):
# update the label on the bottom of the crosshair # update the label on the bottom of the crosshair
self.xaxis_label.update_label(evt_post=pos, point_view=mouse_point) self.xaxis_label.update_label(evt_post=pos, point_view=mouse_point)
# vertical position of the mouse is inside an indicator def boundingRect(self):
mouse_point_ind = self.active_plot.mapToView(pos) return self.active_plot.boundingRect()
self.graphics[self.active_plot]['hl'].setY(
mouse_point_ind.y()
)
self.graphics[self.active_plot]['yl'].update_label(
evt_post=pos, point_view=mouse_point_ind
)
# def paint(self, p, *args): # def paint(self, p, *args):
# pass # pass
def boundingRect(self):
return self.plots[0].boundingRect()
def _mk_lines_array(data: List, size: int) -> np.ndarray: def _mk_lines_array(data: List, size: int) -> np.ndarray:
"""Create an ndarray to hold lines graphics objects. """Create an ndarray to hold lines graphics objects.