Drop YSticky for level lines stuff

basic_orders
Tyler Goodlet 2021-02-08 07:04:08 -05:00
parent 1ef2d18a41
commit 0449734c53
1 changed files with 27 additions and 14 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
@ -30,11 +30,14 @@ from .._style import (
# _font, # _font,
# DpiAwareFont # DpiAwareFont
) )
from .._axes import YSticky from .._axes import YAxisLabel
class LevelLabel(YSticky): class LevelLabel(YAxisLabel):
"""Y-axis oriented label that sticks to where it's placed despite
chart resizing and supports displaying multiple fields.
"""
_w_margin = 4 _w_margin = 4
_h_margin = 3 _h_margin = 3
@ -42,11 +45,12 @@ class LevelLabel(YSticky):
_x_offset = 0 _x_offset = 0
# fields to be displayed # fields to be displayed
# class fields:
level: float = 0.0 level: float = 0.0
digits: int = 2
size: float = 2.0 size: float = 2.0
size_digits: int = int(2.0) size_digits: int = int(2.0)
def __init__( def __init__(
self, self,
chart, chart,
@ -56,7 +60,12 @@ class LevelLabel(YSticky):
orient_h: str = 'left', orient_h: str = 'left',
**kwargs **kwargs
) -> None: ) -> None:
super().__init__(chart, *args, **kwargs) super().__init__(
chart,
*args,
use_arrow=False,
**kwargs
)
# TODO: this is kinda cludgy # TODO: this is kinda cludgy
self._hcolor = None self._hcolor = None
@ -128,7 +137,6 @@ class LevelLabel(YSticky):
h, w = br.height(), br.width() h, w = br.height(), br.width()
return h, w return h, w
def size_hint(self) -> Tuple[None, None]: def size_hint(self) -> Tuple[None, None]:
return None, None return None, None
@ -156,6 +164,13 @@ class LevelLabel(YSticky):
self._pen = self.pen self._pen = self.pen
self.update() self.update()
# def view_size(self):
# """Widgth and height of this label in view box coordinates.
# """
# return self.height()
# self._chart.mapFromView(QPointF(index, value)),
# global for now but probably should be # global for now but probably should be
# attached to chart instance? # attached to chart instance?
@ -206,8 +221,6 @@ class L1Labels:
self.bid_label = L1Label( self.bid_label = L1Label(
chart=chart, chart=chart,
parent=chart.getAxis('right'), parent=chart.getAxis('right'),
# TODO: pass this from symbol data
digits=digits,
opacity=1, opacity=1,
font_size_inches=font_size_inches, font_size_inches=font_size_inches,
bg_color='papas_special', bg_color='papas_special',
@ -215,13 +228,12 @@ class L1Labels:
orient_v='bottom', orient_v='bottom',
) )
self.bid_label.size_digits = size_digits self.bid_label.size_digits = size_digits
self.bid_label._size_br_from_str(self.max_value) self.bid_label.digits = digits
# self.bid_label._size_br_from_str(self.max_value)
self.ask_label = L1Label( self.ask_label = L1Label(
chart=chart, chart=chart,
parent=chart.getAxis('right'), parent=chart.getAxis('right'),
# TODO: pass this from symbol data
digits=digits,
opacity=1, opacity=1,
font_size_inches=font_size_inches, font_size_inches=font_size_inches,
bg_color='papas_special', bg_color='papas_special',
@ -229,7 +241,8 @@ class L1Labels:
orient_v='top', orient_v='top',
) )
self.ask_label.size_digits = size_digits self.ask_label.size_digits = size_digits
self.ask_label._size_br_from_str(self.max_value) self.ask_label.digits = digits
# self.ask_label._size_br_from_str(self.max_value)
self.bid_label._use_extra_fields = True self.bid_label._use_extra_fields = True
self.ask_label._use_extra_fields = True self.ask_label._use_extra_fields = True
@ -452,7 +465,7 @@ def level_line(
parent=chart.getAxis('right'), parent=chart.getAxis('right'),
# TODO: pass this from symbol data # TODO: pass this from symbol data
digits=digits, digits=digits,
opacity=0.666, opacity=0.616,
font_size_inches=font_size_inches, font_size_inches=font_size_inches,
color=color, color=color,