Files
gico/graph/common/common.go
Tai Groot 8f8735d5a8 chore: modernize Go 1.26, update deps, fix lint issues
- Update Go version from 1.19 to 1.26
- Update all dependencies to latest versions
- Fix staticcheck warnings (unused vars, types, functions)
- Remove unused svgToPng function
- Add GitHub Actions CI workflow
2026-02-23 17:27:51 +00:00

68 lines
1.2 KiB
Go

package common
import (
"bytes"
"image/color"
sc "github.com/taigrr/simplecolorpalettes/simplecolor"
)
var (
colorScheme []sc.SimpleColor
)
func CreateGraph() bytes.Buffer {
var x bytes.Buffer
return x
}
func init() {
colors := []string{"#0e4429", "#006d32", "#26a641", "#39d353"}
for _, c := range colors {
color := sc.FromHexString(c)
colorScheme = append(colorScheme, color)
}
}
func SetColorScheme(c []color.Color) {
for _, c := range c {
colorScheme = append(colorScheme, sc.FromRGBA(c.RGBA()))
}
}
func ColorForFrequency(freq, min, max int) sc.SimpleColor {
if freq == 0 {
return sc.SimpleColor(0)
}
spread := max - min
if spread < len(colorScheme)-1 {
return colorScheme[freq-min+1]
}
interval := float64(spread) / float64(len(colorScheme))
colorIndex := 0
for i := float64(min); i < float64(freq); i += float64(interval) {
colorIndex++
}
if colorIndex > len(colorScheme)-1 {
colorIndex = len(colorScheme) - 1
}
return colorScheme[colorIndex]
}
func MinMax(f []int) (int, int) {
max := 0
for _, x := range f {
if x > max {
max = x
}
}
min := max
for _, x := range f {
if x < min && x != 0 {
min = x
}
}
return min, max
}