2016-07-28 17:30:00 -04:00
|
|
|
package chart
|
|
|
|
|
2018-04-05 01:06:34 -04:00
|
|
|
import util "github.com/wcharczuk/go-chart/util"
|
2017-05-12 20:12:23 -04:00
|
|
|
|
2016-07-28 17:30:00 -04:00
|
|
|
// 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 {
|
2017-05-12 20:12:23 -04:00
|
|
|
return util.Math.Normalize(vs.Values()...)
|
2016-07-28 17:30:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Normalize returns the values normalized.
|
|
|
|
func (vs Values) Normalize() []Value {
|
2017-01-13 17:07:42 -05:00
|
|
|
var output []Value
|
|
|
|
var total float64
|
|
|
|
|
|
|
|
for _, v := range vs {
|
|
|
|
total += v.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range vs {
|
|
|
|
if v.Value > 0 {
|
|
|
|
output = append(output, Value{
|
|
|
|
Style: v.Style,
|
|
|
|
Label: v.Label,
|
2017-05-12 20:12:23 -04:00
|
|
|
Value: util.Math.RoundDown(v.Value/total, 0.0001),
|
2017-01-13 17:07:42 -05:00
|
|
|
})
|
2016-07-28 17:30:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value2 is a two axis value.
|
|
|
|
type Value2 struct {
|
|
|
|
Style Style
|
|
|
|
Label string
|
|
|
|
XValue, YValue float64
|
|
|
|
}
|