Debian Codegraph @

value.go

raw symbols SCIP
1 package chart
2
3 // Value is a chart value.
4 type Value struct {
5 Style Style
6 Label string
7 Value float64
8 }
9
10 // Values is an array of Value.
11 type Values []Value
12
13 // Values returns the values.
14 func (vs Values) Values() []float64 {
15 values := make([]float64, len(vs))
16 for index, v := range vs {
17 values[index] = v.Value
18 }
19 return values
20 }
21
22 // ValuesNormalized returns normalized values.
23 func (vs Values) ValuesNormalized() []float64 {
24 return Normalize(vs.Values()...)
25 }
26
27 // Normalize returns the values normalized.
28 func (vs Values) Normalize() []Value {
29 var output []Value
30 var total float64
31
32 for _, v := range vs {
33 total += v.Value
34 }
35
36 for _, v := range vs {
37 if v.Value > 0 {
38 output = append(output, Value{
39 Style: v.Style,
40 Label: v.Label,
41 Value: RoundDown(v.Value/total, 0.0001),
42 })
43 }
44 }
45 return output
46 }
47
48 // Value2 is a two axis value.
49 type Value2 struct {
50 Style Style
51 Label string
52 XValue, YValue float64
53 }