go-chart/value.go

47 lines
916 B
Go
Raw Permalink Normal View History

2016-07-28 23:30:00 +02:00
package chart
// Value is a chart value.
type Value struct {
Style Style
Label string
Value float64
}
// Values is an array of Value.
type Values []Value
// Values returns the values.
func (vs Values) Values() []float64 {
values := make([]float64, len(vs))
for index, v := range vs {
values[index] = v.Value
}
return values
}
// ValuesNormalized returns normalized values.
func (vs Values) ValuesNormalized() []float64 {
2016-07-30 03:24:25 +02:00
return Math.Normalize(vs.Values()...)
2016-07-28 23:30:00 +02:00
}
// Normalize returns the values normalized.
func (vs Values) Normalize() []Value {
output := make([]Value, len(vs))
2016-07-30 03:24:25 +02:00
total := Math.Sum(vs.Values()...)
2016-07-28 23:30:00 +02:00
for index, v := range vs {
output[index] = Value{
Style: v.Style,
Label: v.Label,
2016-07-30 03:24:25 +02:00
Value: Math.RoundDown(v.Value/total, 0.0001),
2016-07-28 23:30:00 +02:00
}
}
return output
}
// Value2 is a two axis value.
type Value2 struct {
Style Style
Label string
XValue, YValue float64
}