From 1b278fff12f96e3c0bb47f8c28bbba6bb416e36c Mon Sep 17 00:00:00 2001 From: rkfg Date: Sat, 29 Jan 2022 16:00:32 +0300 Subject: [PATCH] Make gauge sort more stable --- ui/models/sort.go | 7 +++++++ ui/views/channels.go | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ui/models/sort.go b/ui/models/sort.go index 03a5998..a989ada 100644 --- a/ui/models/sort.go +++ b/ui/models/sort.go @@ -33,6 +33,13 @@ func Int64Sort(a, b int64, o Order) bool { return a > b } +func Float64Sort(a, b float64, o Order) bool { + if o == Asc { + return a < b + } + return a > b +} + func UInt64Sort(a, b uint64, o Order) bool { if o == Asc { return a < b diff --git a/ui/views/channels.go b/ui/views/channels.go index 93dc7bf..7c36903 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -330,9 +330,9 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels { name: fmt.Sprintf("%-21s", columns[i]), sort: func(order models.Order) models.ChannelsSort { return func(c1, c2 *netmodels.Channel) bool { - return models.Int64Sort( - c1.LocalBalance*100/c1.Capacity, - c2.LocalBalance*100/c2.Capacity, + return models.Float64Sort( + float64(c1.LocalBalance)*100/float64(c1.Capacity), + float64(c2.LocalBalance)*100/float64(c2.Capacity), order) } },