Add sticky "orientation", allow overriding label draw instructions.
parent
e65f511648
commit
a5d5208cfa
|
@ -150,12 +150,20 @@ class AxisLabel(pg.GraphicsObject):
|
||||||
p.setOpacity(self.opacity)
|
p.setOpacity(self.opacity)
|
||||||
p.fillRect(self.rect, self.bg_color)
|
p.fillRect(self.rect, self.bg_color)
|
||||||
|
|
||||||
|
# can be overrided in subtype
|
||||||
|
self.draw(p, self.rect)
|
||||||
|
|
||||||
|
p.drawText(self.rect, self.text_flags, self.label_str)
|
||||||
|
|
||||||
|
def draw(
|
||||||
|
self,
|
||||||
|
p: QtGui.QPainter,
|
||||||
|
rect: QtCore.QRectF
|
||||||
|
) -> None:
|
||||||
# this adds a nice black outline around the label for some odd
|
# this adds a nice black outline around the label for some odd
|
||||||
# reason; ok by us
|
# reason; ok by us
|
||||||
p.drawRect(self.rect)
|
p.drawRect(self.rect)
|
||||||
|
|
||||||
p.drawText(self.rect, self.text_flags, self.label_str)
|
|
||||||
|
|
||||||
def boundingRect(self): # noqa
|
def boundingRect(self): # noqa
|
||||||
# if self.label_str:
|
# if self.label_str:
|
||||||
# self._size_br_from_str(self.label_str)
|
# self._size_br_from_str(self.label_str)
|
||||||
|
@ -263,14 +271,21 @@ class YSticky(YAxisLabel):
|
||||||
self,
|
self,
|
||||||
chart,
|
chart,
|
||||||
*args,
|
*args,
|
||||||
|
orient_v: str = 'bottom',
|
||||||
|
orient_h: str = 'left',
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self._orient_v = orient_v
|
||||||
|
self._orient_h = orient_h
|
||||||
|
|
||||||
self._chart = chart
|
self._chart = chart
|
||||||
chart.sigRangeChanged.connect(self.update_on_resize)
|
chart.sigRangeChanged.connect(self.update_on_resize)
|
||||||
self._last_datum = (None, None)
|
self._last_datum = (None, None)
|
||||||
|
self._v_shift = {'top': 1., 'bottom': 0, 'middle': 1/2.}[orient_v]
|
||||||
|
self._h_shift = {'left': -1., 'right': 0}[orient_h]
|
||||||
|
|
||||||
def update_on_resize(self, vr, r):
|
def update_on_resize(self, vr, r):
|
||||||
# TODO: add an `.index` to the array data-buffer layer
|
# TODO: add an `.index` to the array data-buffer layer
|
||||||
|
|
Loading…
Reference in New Issue