mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Merge pull request #231 from ehaughee/markets-sort-by-change
Add Markets sort-by: change to sort by percent change
This commit is contained in:
commit
c41cfadb19
@ -1539,7 +1539,7 @@ Preview:
|
|||||||
An array of markets for which to display information about.
|
An array of markets for which to display information about.
|
||||||
|
|
||||||
##### `sort-by`
|
##### `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
|
###### Properties for each stock
|
||||||
| Name | Type | Required |
|
| Name | Type | Required |
|
||||||
|
@ -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{
|
var weatherCodeTable = map[int]string{
|
||||||
0: "Clear Sky",
|
0: "Clear Sky",
|
||||||
1: "Mainly Clear",
|
1: "Mainly Clear",
|
||||||
|
@ -38,6 +38,10 @@ func (widget *Markets) Update(ctx context.Context) {
|
|||||||
markets.SortByAbsChange()
|
markets.SortByAbsChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if widget.Sort == "change" {
|
||||||
|
markets.SortByChange()
|
||||||
|
}
|
||||||
|
|
||||||
widget.Markets = markets
|
widget.Markets = markets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user