Update max l1 label size on chart

basic_orders
Tyler Goodlet 2021-03-11 21:42:38 -05:00
parent a51d5c536e
commit 4a1df686a5
3 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,5 @@
# piker: trading gear for hackers # piker: trading gear for hackers
# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0) # Copyright (C) Tyler Goodlet (in stewardship for piker0)
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -16,6 +16,7 @@
""" """
Fast, smooth, sexy curves. Fast, smooth, sexy curves.
""" """
from typing import Tuple from typing import Tuple

View File

@ -121,7 +121,7 @@ class SelectRect(QtGui.QGraphicsRectItem):
p1: QtCore.QPointF, p1: QtCore.QPointF,
p2: QtCore.QPointF p2: QtCore.QPointF
) -> None: ) -> None:
"""Set position of selection rectagle and accompanying label, move """Set position of selection rect and accompanying label, move
label to match. label to match.
""" """

View File

@ -152,7 +152,7 @@ class LevelLabel(YAxisLabel):
h, w = self.set_label_str(fields) h, w = self.set_label_str(fields)
if self._adjust_to_l1: if self._adjust_to_l1:
self._x_offset = _max_l1_line_len self._x_offset = self._chart._max_l1_line_len
self.setPos(QPointF( self.setPos(QPointF(
self._h_shift * (w + self._x_offset), self._h_shift * (w + self._x_offset),
@ -211,11 +211,6 @@ class LevelLabel(YAxisLabel):
self.update() self.update()
# global for now but probably should be
# attached to chart instance?
_max_l1_line_len: float = 0
class L1Label(LevelLabel): class L1Label(LevelLabel):
text_flags = ( text_flags = (
@ -232,10 +227,14 @@ class L1Label(LevelLabel):
""" """
h, w = super().set_label_str(fields) h, w = super().set_label_str(fields)
# Set a global "max L1 label length" so we can look it up # Set a global "max L1 label length" so we can
# on order lines and adjust their labels not to overlap with it. # look it up on order lines and adjust their
global _max_l1_line_len # labels not to overlap with it.
_max_l1_line_len = max(_max_l1_line_len, w) chart = self._chart
chart._max_l1_line_len: float = max(
chart._max_l1_line_len,
w
)
return h, w return h, w