diff --git a/tests/data/layouts/big_logo_False_False_False.png b/tests/data/layouts/big_logo_False_False_False.png index 56d04e7..ba8b181 100644 Binary files a/tests/data/layouts/big_logo_False_False_False.png and b/tests/data/layouts/big_logo_False_False_False.png differ diff --git a/tests/data/layouts/big_logo_False_False_True.png b/tests/data/layouts/big_logo_False_False_True.png index 196b097..26c7745 100644 Binary files a/tests/data/layouts/big_logo_False_False_True.png and b/tests/data/layouts/big_logo_False_False_True.png differ diff --git a/tests/data/layouts/big_logo_False_True_False.png b/tests/data/layouts/big_logo_False_True_False.png index 22aea51..a7184fa 100644 Binary files a/tests/data/layouts/big_logo_False_True_False.png and b/tests/data/layouts/big_logo_False_True_False.png differ diff --git a/tests/data/layouts/big_logo_False_True_True.png b/tests/data/layouts/big_logo_False_True_True.png index 4642164..1e21ee3 100644 Binary files a/tests/data/layouts/big_logo_False_True_True.png and b/tests/data/layouts/big_logo_False_True_True.png differ diff --git a/tests/data/layouts/big_logo_True_False_False.png b/tests/data/layouts/big_logo_True_False_False.png index 1c2c7c1..685cae4 100644 Binary files a/tests/data/layouts/big_logo_True_False_False.png and b/tests/data/layouts/big_logo_True_False_False.png differ diff --git a/tests/data/layouts/big_logo_True_False_True.png b/tests/data/layouts/big_logo_True_False_True.png index ed4fc00..4cab96b 100644 Binary files a/tests/data/layouts/big_logo_True_False_True.png and b/tests/data/layouts/big_logo_True_False_True.png differ diff --git a/tests/data/layouts/big_logo_True_True_False.png b/tests/data/layouts/big_logo_True_True_False.png index 484d5b1..43b194f 100644 Binary files a/tests/data/layouts/big_logo_True_True_False.png and b/tests/data/layouts/big_logo_True_True_False.png differ diff --git a/tests/data/layouts/big_logo_True_True_True.png b/tests/data/layouts/big_logo_True_True_True.png index 5597843..12b7e3b 100644 Binary files a/tests/data/layouts/big_logo_True_True_True.png and b/tests/data/layouts/big_logo_True_True_True.png differ diff --git a/tests/data/layouts/big_price_False_False_False.png b/tests/data/layouts/big_price_False_False_False.png index 3c42be1..b8e9a4f 100644 Binary files a/tests/data/layouts/big_price_False_False_False.png and b/tests/data/layouts/big_price_False_False_False.png differ diff --git a/tests/data/layouts/big_price_False_False_True.png b/tests/data/layouts/big_price_False_False_True.png index b450b56..9c77970 100644 Binary files a/tests/data/layouts/big_price_False_False_True.png and b/tests/data/layouts/big_price_False_False_True.png differ diff --git a/tests/data/layouts/big_price_False_True_False.png b/tests/data/layouts/big_price_False_True_False.png index 3ec00e5..acd82d7 100644 Binary files a/tests/data/layouts/big_price_False_True_False.png and b/tests/data/layouts/big_price_False_True_False.png differ diff --git a/tests/data/layouts/big_price_False_True_True.png b/tests/data/layouts/big_price_False_True_True.png index 662fa55..0d35d95 100644 Binary files a/tests/data/layouts/big_price_False_True_True.png and b/tests/data/layouts/big_price_False_True_True.png differ diff --git a/tests/data/layouts/big_price_True_False_False.png b/tests/data/layouts/big_price_True_False_False.png index 3ffa956..fa7194c 100644 Binary files a/tests/data/layouts/big_price_True_False_False.png and b/tests/data/layouts/big_price_True_False_False.png differ diff --git a/tests/data/layouts/big_price_True_False_True.png b/tests/data/layouts/big_price_True_False_True.png index 4b47ad4..3b74112 100644 Binary files a/tests/data/layouts/big_price_True_False_True.png and b/tests/data/layouts/big_price_True_False_True.png differ diff --git a/tests/data/layouts/big_price_True_True_False.png b/tests/data/layouts/big_price_True_True_False.png index 2e08d9c..d825bf8 100644 Binary files a/tests/data/layouts/big_price_True_True_False.png and b/tests/data/layouts/big_price_True_True_False.png differ diff --git a/tests/data/layouts/big_price_True_True_True.png b/tests/data/layouts/big_price_True_True_True.png index 8f10f0b..4e9d342 100644 Binary files a/tests/data/layouts/big_price_True_True_True.png and b/tests/data/layouts/big_price_True_True_True.png differ diff --git a/tests/data/layouts/default_False_False_False.png b/tests/data/layouts/default_False_False_False.png index 58057cb..fe5daec 100644 Binary files a/tests/data/layouts/default_False_False_False.png and b/tests/data/layouts/default_False_False_False.png differ diff --git a/tests/data/layouts/default_False_False_True.png b/tests/data/layouts/default_False_False_True.png index d20df30..c13073c 100644 Binary files a/tests/data/layouts/default_False_False_True.png and b/tests/data/layouts/default_False_False_True.png differ diff --git a/tests/data/layouts/default_False_True_False.png b/tests/data/layouts/default_False_True_False.png index ef3d99c..a745138 100644 Binary files a/tests/data/layouts/default_False_True_False.png and b/tests/data/layouts/default_False_True_False.png differ diff --git a/tests/data/layouts/default_False_True_True.png b/tests/data/layouts/default_False_True_True.png index 5c01683..5ca40c6 100644 Binary files a/tests/data/layouts/default_False_True_True.png and b/tests/data/layouts/default_False_True_True.png differ diff --git a/tests/data/layouts/default_True_False_False.png b/tests/data/layouts/default_True_False_False.png index 24ab9f2..9fc53c3 100644 Binary files a/tests/data/layouts/default_True_False_False.png and b/tests/data/layouts/default_True_False_False.png differ diff --git a/tests/data/layouts/default_True_False_True.png b/tests/data/layouts/default_True_False_True.png index 5d47f7c..a24e755 100644 Binary files a/tests/data/layouts/default_True_False_True.png and b/tests/data/layouts/default_True_False_True.png differ diff --git a/tests/data/layouts/default_True_True_False.png b/tests/data/layouts/default_True_True_False.png index 4cc3e01..2c0fb16 100644 Binary files a/tests/data/layouts/default_True_True_False.png and b/tests/data/layouts/default_True_True_False.png differ diff --git a/tests/data/layouts/default_True_True_True.png b/tests/data/layouts/default_True_True_True.png index 354f318..0115504 100644 Binary files a/tests/data/layouts/default_True_True_True.png and b/tests/data/layouts/default_True_True_True.png differ diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 7f26329..0d1ad6d 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -5,6 +5,4 @@ from tinyticker import utils # monkey patch the now function so tests are time indenpendent -utils.__dict__["now"] = lambda: pd.Timestamp( - 2021, 7, 22, 18, 00, 00, tzinfo=timezone.utc -) +utils.now = lambda: pd.Timestamp(2021, 7, 22, 18, 00, 00, tzinfo=timezone.utc) diff --git a/tests/unit/layouts/utils.py b/tests/unit/layouts/utils.py index 4407598..352419e 100644 --- a/tests/unit/layouts/utils.py +++ b/tests/unit/layouts/utils.py @@ -27,7 +27,7 @@ def layout_test(layout_func: LayoutFunc, dimensions, resp, data_dir): config.layout.x_gaps = x_gap ticker = TickerStock(config) - out = layout_func(dimensions, ticker, resp) + out = layout_func(dimensions, ticker, resp, 100) filename = f"{layout_func.__name__}_{y_axis}_{x_gap}_{volume}.png" assert out.size == dimensions, f"Wrong dimensions: {filename}" if UPDATE_REF_PLOTS: diff --git a/tinyticker/display.py b/tinyticker/display.py index 0139db4..c89e49f 100644 --- a/tinyticker/display.py +++ b/tinyticker/display.py @@ -13,7 +13,7 @@ from .config import TinytickerConfig from .layouts import LAYOUTS -from .layouts.utils import create_fig_ax, fig_to_image +from .layouts.utils import create_fig_ax, fig_to_image, perc_change from .tickers._base import TickerBase, TickerResponse from .waveshare_lib._base import EPDHighlight from .waveshare_lib.models import MODELS, EPDModel @@ -90,5 +90,5 @@ def show_image(self, image: Image.Image) -> None: def show(self, ticker: TickerBase, resp: TickerResponse) -> None: layout = LAYOUTS.get(ticker.config.layout.name, LAYOUTS["default"]) - image = layout.func(self.epd.size, ticker, resp) + image = layout.func(self.epd.size, ticker, resp, perc_change(ticker, resp)) self.show_image(image) diff --git a/tinyticker/layouts/big_logo.py b/tinyticker/layouts/big_logo.py index d47e302..9124388 100644 --- a/tinyticker/layouts/big_logo.py +++ b/tinyticker/layouts/big_logo.py @@ -10,7 +10,6 @@ fig_to_image, fontsize_for_size, historical_plot, - perc_change, perc_change_abp, resize_aspect, ) @@ -27,7 +26,7 @@ def ttf_font_or_default( @register def big_logo( - size: Tuple[int, int], ticker: TickerBase, resp: TickerResponse + size: Tuple[int, int], ticker: TickerBase, resp: TickerResponse, perc_change: float ) -> Image.Image: # some layout settings padding = min(8, int(0.05 * size[0])) @@ -44,7 +43,7 @@ def big_logo( monospace_font = ttf_font_or_default(monospace_font_file, default_size) regular_font = ttf_font_or_default(regular_font_file, default_size) - range_text = f"{len(resp.historical)}x{ticker.config.interval} {perc_change(ticker, resp):+.2f}%" + range_text = f"{len(resp.historical)}x{ticker.config.interval} {perc_change:+.2f}%" if ticker.config.avg_buy_price: range_text += f" ({perc_change_abp(ticker, resp):+.2f}%)" range_text_bbox = monospace_font.getbbox(range_text) diff --git a/tinyticker/layouts/big_price.py b/tinyticker/layouts/big_price.py index 1422a23..ad6bfeb 100644 --- a/tinyticker/layouts/big_price.py +++ b/tinyticker/layouts/big_price.py @@ -10,7 +10,6 @@ fig_to_image, fontsize_for_size, historical_plot, - perc_change, perc_change_abp, strip_ax, ) @@ -18,7 +17,7 @@ @register def big_price( - size: Tuple[int, int], ticker: TickerBase, resp: TickerResponse + size: Tuple[int, int], ticker: TickerBase, resp: TickerResponse, perc_change: float ) -> Image.Image: """Big price layout.""" show_logo = ticker.config.layout.show_logo and ticker.logo @@ -47,7 +46,7 @@ def big_price( ) ) - sub_string = f"{len(resp.historical)}x{ticker.config.interval} {perc_change(ticker, resp):+.2f}%" + sub_string = f"{len(resp.historical)}x{ticker.config.interval} {perc_change:+.2f}%" if ticker.config.avg_buy_price: sub_string += f" ({perc_change_abp(ticker, resp):+.2f}%)" diff --git a/tinyticker/layouts/default.py b/tinyticker/layouts/default.py index 3aa6c0c..b7fb919 100644 --- a/tinyticker/layouts/default.py +++ b/tinyticker/layouts/default.py @@ -10,7 +10,6 @@ apply_layout_config, fig_to_image, historical_plot, - perc_change, perc_change_abp, strip_ax, ) @@ -18,7 +17,7 @@ @register def default( - size: Tuple[int, int], ticker: TickerBase, resp: TickerResponse + size: Tuple[int, int], ticker: TickerBase, resp: TickerResponse, perc_change: float ) -> Image.Image: """Default layout.""" show_logo = ticker.config.layout.show_logo and ticker.logo @@ -48,7 +47,7 @@ def default( sub_text = ax.text( 0, 1 - (top_text.get_window_extent().height + 1) / (pos.height * size[1]), - f"{len(resp.historical)}x{ticker.config.interval} {perc_change(ticker, resp):+.2f}%", + f"{len(resp.historical)}x{ticker.config.interval} {perc_change:+.2f}%", transform=ax.transAxes, fontsize=8, weight="bold", diff --git a/tinyticker/layouts/register.py b/tinyticker/layouts/register.py index 4d236a7..a0903bc 100644 --- a/tinyticker/layouts/register.py +++ b/tinyticker/layouts/register.py @@ -1,12 +1,12 @@ import dataclasses as dc -from typing import Callable, Optional, Tuple +from typing import Callable, Optional, Tuple, Dict + from PIL import Image from ..tickers._base import TickerBase, TickerResponse -LayoutFunc = Callable[[Tuple[int, int], TickerBase, TickerResponse], Image.Image] -LAYOUTS = {} +LayoutFunc = Callable[[Tuple[int, int], TickerBase, TickerResponse, float], Image.Image] @dc.dataclass @@ -16,6 +16,9 @@ class LayoutData: desc: Optional[str] +LAYOUTS: Dict[str, LayoutData] = {} + + def register(func: LayoutFunc) -> LayoutFunc: """Register a layout function.