8000 Add Markets sort-by: change to sort by percent change by ehaughee · Pull Request #231 · glanceapp/glance · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Markets sort-by: change to sort by percent change #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ Preview:
An array of markets for which to display information about.

##### `sort-by`
By default the markets 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.
By default the markets are displayed in the order they were defined. You can customize their ordering by setting the `sort-by` property to `change` for descending order based on the stock's percentage change (e.g. 1% would be sorted higher than -1%) or `absolute-change` for descending order based on the stock's absolute price change (e.g. -1% would be sorted higher than +0.5%).

###### Properties for each stock
| Name | Type | Required |
Expand Down
6 changes: 6 additions & 0 deletions internal/feed/primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func (t Markets) SortByAbsChange() {
})
}

func (t Markets) SortByChange() {
sort.Slice(t, func(i, j int) bool {
return t[i].PercentChange > t[j].PercentChange
})
}

var weatherCodeTable = map[int]string{
0: "Clear Sky",
1: "Mainly Clear",
Expand Down
4 changes: 4 additions & 0 deletions internal/widget/markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (widget *Markets) Update(ctx context.Context) {
markets.SortByAbsChange()
}

if widget.Sort == "change" {
markets.SortByChange()
}

widget.Markets = markets
}

Expand Down
0