Use label anchor
parent
791fd23524
commit
3aab6d67e9
|
@ -225,6 +225,8 @@ class Label:
|
||||||
self.vb.scene().removeItem(self.txt)
|
self.vb.scene().removeItem(self.txt)
|
||||||
|
|
||||||
|
|
||||||
|
# anchoring helper funcs
|
||||||
|
|
||||||
def vbr_left(label) -> Callable[..., float]:
|
def vbr_left(label) -> Callable[..., float]:
|
||||||
"""Return a closure which gives the scene x-coordinate for the
|
"""Return a closure which gives the scene x-coordinate for the
|
||||||
leftmost point of the containing view box.
|
leftmost point of the containing view box.
|
||||||
|
|
|
@ -360,6 +360,8 @@ class LevelLine(pg.InfiniteLine):
|
||||||
self._marker.setPos(
|
self._marker.setPos(
|
||||||
QPointF(marker_right, self.scene_y())
|
QPointF(marker_right, self.scene_y())
|
||||||
)
|
)
|
||||||
|
# TODO: make this label update part of a scene-aware-marker
|
||||||
|
# composed annotation
|
||||||
self._marker.label.update()
|
self._marker.label.update()
|
||||||
|
|
||||||
elif not self.use_marker_margin:
|
elif not self.use_marker_margin:
|
||||||
|
@ -763,9 +765,7 @@ def position_line(
|
||||||
|
|
||||||
# monkey-cache height for sizing on pp nav-hub
|
# monkey-cache height for sizing on pp nav-hub
|
||||||
arrow_path._height = path_br.height()
|
arrow_path._height = path_br.height()
|
||||||
|
|
||||||
arrow_path._width = path_br.width()
|
arrow_path._width = path_br.width()
|
||||||
# wp = QPointF(w, w)
|
|
||||||
|
|
||||||
marker_label = Label(
|
marker_label = Label(
|
||||||
view=vb,
|
view=vb,
|
||||||
|
@ -775,17 +775,18 @@ def position_line(
|
||||||
)
|
)
|
||||||
arrow_path.label = marker_label
|
arrow_path.label = marker_label
|
||||||
|
|
||||||
# def arrow_br():
|
def arrow_tr():
|
||||||
# # get actual arrow graphics path
|
# get actual arrow graphics path
|
||||||
# path_br = arrow_path.mapToScene(
|
path_br = arrow_path.mapToScene(
|
||||||
# arrow_path.path()
|
arrow_path.path()
|
||||||
# ).boundingRect()
|
).boundingRect()
|
||||||
|
|
||||||
# # vb.locate(arrow_path) #, children=True)
|
# vb.locate(arrow_path) #, children=True)
|
||||||
|
|
||||||
# return path_br.bottomRight() - QPointF(0, marker_label.h / 2)
|
return path_br.topRight() - QPointF(0, marker_label.h / 3)
|
||||||
|
|
||||||
# marker_label.scene_anchor = arrow_br
|
|
||||||
|
marker_label.scene_anchor = arrow_tr
|
||||||
|
|
||||||
line._labels.append(marker_label)
|
line._labels.append(marker_label)
|
||||||
|
|
||||||
|
@ -807,13 +808,9 @@ def position_line(
|
||||||
ymn, ymx = vr[1]
|
ymn, ymx = vr[1]
|
||||||
level = line.value()
|
level = line.value()
|
||||||
|
|
||||||
path = line._marker
|
marker = line._marker
|
||||||
label = path.label
|
label = marker.label
|
||||||
|
|
||||||
# get actual arrow-marker graphics path
|
|
||||||
path_br = path.mapToScene(
|
|
||||||
path.path()
|
|
||||||
).boundingRect()
|
|
||||||
|
|
||||||
# provide "nav hub" like indicator for where
|
# provide "nav hub" like indicator for where
|
||||||
# the position is on the y-dimension
|
# the position is on the y-dimension
|
||||||
|
@ -821,33 +818,28 @@ def position_line(
|
||||||
_, marker_right, _ = line.marker_right_points()
|
_, marker_right, _ = line.marker_right_points()
|
||||||
|
|
||||||
if level > ymx: # pin to top of view
|
if level > ymx: # pin to top of view
|
||||||
path.setPos(
|
marker.setPos(
|
||||||
QPointF(
|
QPointF(
|
||||||
marker_right,
|
marker_right,
|
||||||
path._height/3,
|
marker._height/3,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
elif level < ymn: # pin to bottom of view
|
elif level < ymn: # pin to bottom of view
|
||||||
|
|
||||||
path.setPos(
|
marker.setPos(
|
||||||
QPointF(
|
QPointF(
|
||||||
marker_right,
|
marker_right,
|
||||||
vb.height() - 4/3*path._height,
|
vb.height() - 4/3*marker._height,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# adjust marker labels to be above bottom of view
|
|
||||||
label.txt.setPos(path_br.topRight() - QPointF(0, label.h / 2))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# pp line is viewable so show marker normally
|
# pp line is viewable so show marker normally
|
||||||
line._marker.show()
|
marker.update()
|
||||||
|
|
||||||
# place label at bottom right of pp marker
|
# re-anchor label (i.e. trigger call of ``arrow_tr()`` from above
|
||||||
label.txt.setPos(path_br.bottomRight() - QPointF(0, label.h / 2))
|
label.update()
|
||||||
|
|
||||||
line.show_labels()
|
|
||||||
|
|
||||||
vb.sigRangeChanged.connect(update_pp_nav)
|
vb.sigRangeChanged.connect(update_pp_nav)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue