Add support for dotted style level lines

basic_orders
Tyler Goodlet 2021-01-22 22:57:42 -05:00
parent 92efb8fd8e
commit 50d2d8517b
1 changed files with 31 additions and 6 deletions

View File

@ -216,6 +216,7 @@ class LevelLine(pg.InfiniteLine):
color: str = 'default', color: str = 'default',
highlight_color: str = 'default_light', highlight_color: str = 'default_light',
hl_on_hover: bool = True, hl_on_hover: bool = True,
dotted: bool = False,
**kwargs, **kwargs,
) -> None: ) -> None:
@ -223,28 +224,48 @@ class LevelLine(pg.InfiniteLine):
self.label = label self.label = label
self.sigPositionChanged.connect(self.set_level) self.sigPositionChanged.connect(self.set_level)
self._chart = chart self._chart = chart
self._hoh = hl_on_hover self._hoh = hl_on_hover
self._dotted = dotted
self._hcolor = None self._hcolor = None
self.color = color self.color = color
# TODO: for when we want to move groups of lines?
self._track_cursor: bool = False self._track_cursor: bool = False
# testing markers
# self.addMarker('<|', 0.1, 3)
# self.addMarker('<|>', 0.2, 3)
# self.addMarker('>|', 0.3, 3)
# self.addMarker('>|<', 0.4, 3)
# self.addMarker('>|<', 0.5, 3)
# self.addMarker('^', 0.6, 3)
# self.addMarker('v', 0.7, 3)
# self.addMarker('o', 0.8, 3)
@property @property
def color(self): def color(self):
return self._hcolor return self._hcolor
@color.setter @color.setter
def color(self, color: str) -> None: def color(self, color: str) -> None:
# set pens to new color
self._hcolor = color self._hcolor = color
self.setPen(pg.mkPen(hcolor(color))) pen = pg.mkPen(hcolor(color))
hoverpen = pg.mkPen(hcolor(color + '_light'))
# set hover pen to new color if self._dotted:
pen = pg.mkPen(hcolor(color + '_light')) pen.setStyle(QtCore.Qt.DashLine)
# use slightly thicker highlight hoverpen.setStyle(QtCore.Qt.DashLine)
pen.setWidth(2)
self.setHoverPen(pen) # set regular pen
self.setPen(pen)
# use slightly thicker highlight for hover pen
hoverpen.setWidth(2)
self.hoverPen = hoverpen
def set_level(self, value: float) -> None: def set_level(self, value: float) -> None:
self.label.update_from_data(0, self.value()) self.label.update_from_data(0, self.value())
@ -352,6 +373,9 @@ def level_line(
# when moused over (aka "hovered") # when moused over (aka "hovered")
hl_on_hover: bool = True, hl_on_hover: bool = True,
# line style
dotted: bool = False,
**linelabelkwargs **linelabelkwargs
) -> LevelLine: ) -> LevelLine:
"""Convenience routine to add a styled horizontal line to a plot. """Convenience routine to add a styled horizontal line to a plot.
@ -385,6 +409,7 @@ def level_line(
movable=True, movable=True,
angle=0, angle=0,
hl_on_hover=hl_on_hover, hl_on_hover=hl_on_hover,
dotted=dotted,
) )
line.setValue(level) line.setValue(level)