From ee2fa0d24a65f036939671ccd5d71b1bc1b7e38c Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 5 Feb 2023 10:50:18 -0800 Subject: [PATCH] fix minmax func --- graph/common/common.go | 23 ++++++++++------------- graph/svg/svg.go | 1 + 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/graph/common/common.go b/graph/common/common.go index 4ff4292..0129126 100644 --- a/graph/common/common.go +++ b/graph/common/common.go @@ -2,8 +2,8 @@ package common import ( "bytes" + "fmt" "image/color" - "math" "sync" sc "github.com/taigrr/simplecolorpalettes/simplecolor" @@ -35,6 +35,7 @@ func SetColorScheme(c []color.Color) { } func ColorForFrequency(freq, min, max int) sc.SimpleColor { + fmt.Printf("f: %d, min: %d, max: %d\n", freq, min, max) if freq == 0 { return sc.SimpleColor(0) } @@ -54,22 +55,18 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor { } func MinMax(f []int) (int, int) { - min, max := math.MaxInt, math.MinInt + max := 0 for _, x := range f { - if x == 0 { - continue - } - if x < min { - min = x - } else if x > max { + if x > max { max = x } } - if min == math.MaxInt { - min = 0 - } - if max == math.MinInt { - max = 0 + min := max + for _, x := range f { + if x < min && x != 0 { + min = x + } } + return min, max } diff --git a/graph/svg/svg.go b/graph/svg/svg.go index 76a1815..8eb575b 100644 --- a/graph/svg/svg.go +++ b/graph/svg/svg.go @@ -26,6 +26,7 @@ var ( func GetWeekSVG(frequencies []int, shouldHighlight bool) bytes.Buffer { squareColors := []sc.SimpleColor{} min, max := common.MinMax(frequencies) + fmt.Println(frequencies) for _, f := range frequencies { squareColors = append(squareColors, common.ColorForFrequency(f, min, max)) }