fix minmax func

This commit is contained in:
2023-02-05 10:50:18 -08:00
parent 88a63e6705
commit ee2fa0d24a
2 changed files with 11 additions and 13 deletions

View File

@@ -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
}

View File

@@ -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))
}