Fix label snap on line highlight bug

basic_orders
Tyler Goodlet 2021-03-14 12:28:11 -04:00
parent cf2f001bcc
commit 61198818dc
2 changed files with 23 additions and 11 deletions

View File

@ -377,15 +377,16 @@ class Cursor(pg.GraphicsObject):
# px perfect... # px perfect...
line_offset = self._lw / 2 line_offset = self._lw / 2
if iy != last_iy and self._y_label_update: if iy != last_iy:
# update y-range items # update y-range items
self.graphics[plot]['hl'].setY(iy + line_offset) self.graphics[plot]['hl'].setY(iy + line_offset)
self.graphics[self.active_plot]['yl'].update_label( if self._y_label_update:
abs_pos=plot.mapFromView(QPointF(ix, iy + line_offset)), self.graphics[self.active_plot]['yl'].update_label(
value=iy abs_pos=plot.mapFromView(QPointF(ix, iy + line_offset)),
) value=iy
)
# update all trackers # update all trackers
for item in self._trackers: for item in self._trackers:
@ -425,15 +426,22 @@ class Cursor(pg.GraphicsObject):
except AttributeError: except AttributeError:
return self.plots[0].boundingRect() return self.plots[0].boundingRect()
def show_xhair(self) -> None: def show_xhair(
self,
y_label_level: float = None,
) -> None:
g = self.graphics[self.active_plot] g = self.graphics[self.active_plot]
# show horiz line and y-label # show horiz line and y-label
g['hl'].show() g['hl'].show()
g['vl'].show() g['vl'].show()
self._y_label_update = True
yl = g['yl'] yl = g['yl']
# yl.fg_color = pg.mkColor(hcolor('black')) # yl.fg_color = pg.mkColor(hcolor('black'))
# yl.bg_color = pg.mkColor(hcolor(self.label_color)) # yl.bg_color = pg.mkColor(hcolor(self.label_color))
if y_label_level:
yl.update_from_data(0, y_label_level, _save_last=False)
yl.show() yl.show()
def hide_xhair( def hide_xhair(
@ -447,12 +455,15 @@ class Cursor(pg.GraphicsObject):
g['hl'].hide() g['hl'].hide()
g['vl'].hide() g['vl'].hide()
# only disable cursor y-label updates
# if we're highlighting a line
yl = g['yl'] yl = g['yl']
if hide_label: if hide_label:
yl.hide() yl.hide()
elif y_label_level: elif y_label_level:
yl.update_from_data(0, y_label_level) yl.update_from_data(0, y_label_level, _save_last=False)
if fg_color is not None: if fg_color is not None:
yl.fg_color = pg.mkColor(hcolor(fg_color)) yl.fg_color = pg.mkColor(hcolor(fg_color))

View File

@ -320,9 +320,10 @@ class LevelLine(pg.InfiniteLine):
self.currentPen = self.hoverPen self.currentPen = self.hoverPen
# only disable cursor y-label updates if self not in cur._trackers:
# if we're highlighting a line # only disable cursor y-label updates
cur._y_label_update = False # if we're highlighting a line
cur._y_label_update = False
# add us to cursor state # add us to cursor state
cur.add_hovered(self) cur.add_hovered(self)
@ -348,7 +349,7 @@ class LevelLine(pg.InfiniteLine):
cur._hovered.remove(self) cur._hovered.remove(self)
if self not in cur._trackers: if self not in cur._trackers:
cur.show_xhair() cur.show_xhair(y_label_level=self.value())
if not self._always_show_labels: if not self._always_show_labels:
for at, label in self._labels: for at, label in self._labels: