From 948c117f5b067e33e15a42a9d6791e98443665e3 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Wed, 1 May 2024 22:28:59 +0100 Subject: [PATCH] Retain stocks order by default --- docs/configuration.md | 4 ++++ internal/widget/stocks.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 3b0ebf9..77da5b5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -831,6 +831,7 @@ Preview: | Name | Type | Required | | ---- | ---- | -------- | | stocks | array | yes | +| sort | string | no | ##### `stocks` An array of stocks for which to display information about. @@ -849,6 +850,9 @@ The symbol, as seen in Yahoo Finance. The name that will be displayed under the symbol. +##### `sort-by` +By default the stocks are displayed in the order they were defined. You can customize their ordering by setting the `sort-by` property to `absolute-change` for descending order based on the stock's absolute price change. + ### Twitch Channels Display a list of channels from Twitch. diff --git a/internal/widget/stocks.go b/internal/widget/stocks.go index afba0e4..1863875 100644 --- a/internal/widget/stocks.go +++ b/internal/widget/stocks.go @@ -12,6 +12,7 @@ import ( type Stocks struct { widgetBase `yaml:",inline"` Stocks feed.Stocks `yaml:"-"` + Sort string `yaml:"sort-by"` Tickers []feed.StockRequest `yaml:"stocks"` } @@ -28,7 +29,10 @@ func (widget *Stocks) Update(ctx context.Context) { return } - stocks.SortByAbsChange() + if widget.Sort == "absolute-change" { + stocks.SortByAbsChange() + } + widget.Stocks = stocks }