From 09fccdf8e5c5abaf51e96c3d010a8b47c028e2c3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 29 Aug 2021 13:06:47 -0400 Subject: [PATCH] Add fiat size to each order line label --- piker/ui/_lines.py | 14 +++++++++++++- piker/ui/_position.py | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/piker/ui/_lines.py b/piker/ui/_lines.py index d290b364..688abf10 100644 --- a/piker/ui/_lines.py +++ b/piker/ui/_lines.py @@ -33,6 +33,7 @@ from ._anchors import ( right_axis, # gpath_pin, ) +from ..calc import humanize from ._label import Label from ._style import hcolor, _font @@ -669,7 +670,9 @@ def order_line( view=line.getViewBox(), # display the order pos size, which is some multiple # of the user defined base unit size - fmt_str=('units: {size:.{size_digits}f}'), # old + fmt_str=( + '{size:.{size_digits}f}u{fiat_text}' + ), color=line.color, ) @@ -677,9 +680,18 @@ def order_line( line._labels.append(label) + def maybe_show_fiat_text(fields: dict) -> str: + fiat_size = fields.get('fiat_size') + if not fiat_size: + return '' + + return f' -> ${humanize(fiat_size)}' + label.fields = { 'size': size, 'size_digits': 0, + 'fiat_size': None, + 'fiat_text': maybe_show_fiat_text, } label.orient_v = orient_v diff --git a/piker/ui/_position.py b/piker/ui/_position.py index edbe4cc5..0099cbd7 100644 --- a/piker/ui/_position.py +++ b/piker/ui/_position.py @@ -212,7 +212,8 @@ class Allocator(BaseModel): return { 'size': abs(round(order_size, ndigits=ld)), - 'size_digits': ld + 'size_digits': ld, + 'fiat_size': round(order_size * price, ndigits=2), } def slots_used(