go-chart/util.go
Will Charczuk cbc4672f1e updates.
2016-07-07 14:44:03 -07:00

57 lines
1001 B
Go

package chart
import (
"fmt"
"image/color"
"time"
)
// ColorIsZero returns if a color.RGBA is unset or not.
func ColorIsZero(c color.RGBA) bool {
return c.R == 0 && c.G == 0 && c.B == 0 && c.A == 0
}
// ColorAsString returns if a color.RGBA is unset or not.
func ColorAsString(c color.RGBA) string {
return fmt.Sprintf("RGBA(%v,%v,%v,%v)", c.R, c.G, c.G, c.A)
}
// MinAndMax returns both the min and max in one pass.
func MinAndMax(values ...float64) (min float64, max float64) {
if len(values) == 0 {
return
}
min = values[0]
max = values[0]
for _, v := range values {
if max < v {
max = v
}
if min > v {
min = v
}
}
return
}
// MinAndMaxOfTime returns the min and max of a given set of times
// in one pass.
func MinAndMaxOfTime(values ...time.Time) (min time.Time, max time.Time) {
if len(values) == 0 {
return
}
min = values[0]
max = values[0]
for _, v := range values {
if max.Before(v) {
max = v
}
if min.After(v) {
min = v
}
}
return
}