mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
- 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
68 lines
1.2 KiB
Go
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
|
|
}
|