mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
fix minmax func
This commit is contained in:
@@ -2,8 +2,8 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
sc "github.com/taigrr/simplecolorpalettes/simplecolor"
|
sc "github.com/taigrr/simplecolorpalettes/simplecolor"
|
||||||
@@ -35,6 +35,7 @@ func SetColorScheme(c []color.Color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ColorForFrequency(freq, min, max int) sc.SimpleColor {
|
func ColorForFrequency(freq, min, max int) sc.SimpleColor {
|
||||||
|
fmt.Printf("f: %d, min: %d, max: %d\n", freq, min, max)
|
||||||
if freq == 0 {
|
if freq == 0 {
|
||||||
return sc.SimpleColor(0)
|
return sc.SimpleColor(0)
|
||||||
}
|
}
|
||||||
@@ -54,22 +55,18 @@ func ColorForFrequency(freq, min, max int) sc.SimpleColor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MinMax(f []int) (int, int) {
|
func MinMax(f []int) (int, int) {
|
||||||
min, max := math.MaxInt, math.MinInt
|
max := 0
|
||||||
for _, x := range f {
|
for _, x := range f {
|
||||||
if x == 0 {
|
if x > max {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if x < min {
|
|
||||||
min = x
|
|
||||||
} else if x > max {
|
|
||||||
max = x
|
max = x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if min == math.MaxInt {
|
min := max
|
||||||
min = 0
|
for _, x := range f {
|
||||||
|
if x < min && x != 0 {
|
||||||
|
min = x
|
||||||
}
|
}
|
||||||
if max == math.MinInt {
|
|
||||||
max = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return min, max
|
return min, max
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ var (
|
|||||||
func GetWeekSVG(frequencies []int, shouldHighlight bool) bytes.Buffer {
|
func GetWeekSVG(frequencies []int, shouldHighlight bool) bytes.Buffer {
|
||||||
squareColors := []sc.SimpleColor{}
|
squareColors := []sc.SimpleColor{}
|
||||||
min, max := common.MinMax(frequencies)
|
min, max := common.MinMax(frequencies)
|
||||||
|
fmt.Println(frequencies)
|
||||||
for _, f := range frequencies {
|
for _, f := range frequencies {
|
||||||
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user