-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
override.go
93 lines (83 loc) · 2.41 KB
/
override.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fields
import (
"github.com/K-Phoen/grabana/timeseries/axis"
"github.com/K-Phoen/sdk"
)
// StackMode configures mode of series stacking.
// FIXME: copied here to avoid circular imports with parent package
type StackMode string
const (
// Unstacked will not stack series
Unstacked StackMode = "none"
// NormalStack will stack series as absolute numbers
NormalStack StackMode = "normal"
// PercentStack will stack series as percents
PercentStack StackMode = "percent"
)
type OverrideOption func(field *sdk.FieldConfigOverride)
// Unit overrides the unit.
func Unit(unit string) OverrideOption {
return func(field *sdk.FieldConfigOverride) {
field.Properties = append(field.Properties,
sdk.FieldConfigOverrideProperty{
ID: "unit",
Value: unit,
})
}
}
// FillOpacity overrides the opacity.
func FillOpacity(opacity int) OverrideOption {
return func(field *sdk.FieldConfigOverride) {
field.Properties = append(field.Properties,
sdk.FieldConfigOverrideProperty{
ID: "custom.fillOpacity",
Value: opacity,
})
}
}
// FixedColorScheme forces the use of a fixed color scheme.
func FixedColorScheme(color string) OverrideOption {
return func(field *sdk.FieldConfigOverride) {
field.Properties = append(field.Properties,
sdk.FieldConfigOverrideProperty{
ID: "color",
Value: map[string]string{
"mode": "fixed",
"fixedColor": color,
},
})
}
}
// NegativeY flips the results to negative values on the Y axis.
func NegativeY() OverrideOption {
return func(field *sdk.FieldConfigOverride) {
field.Properties = append(field.Properties,
sdk.FieldConfigOverrideProperty{
ID: "custom.transform",
Value: "negative-Y",
})
}
}
// AxisPlacement overrides how the axis should be placed in the panel.
func AxisPlacement(placement axis.PlacementMode) OverrideOption {
return func(field *sdk.FieldConfigOverride) {
field.Properties = append(field.Properties,
sdk.FieldConfigOverrideProperty{
ID: "custom.axisPlacement",
Value: string(placement),
})
}
}
// Stack overrides if the series should be stacked and using which mode (default not stacked).
func Stack(mode StackMode) OverrideOption {
return func(field *sdk.FieldConfigOverride) {
field.Properties = append(field.Properties,
sdk.FieldConfigOverrideProperty{
ID: "custom.stacking",
Value: map[string]interface{}{
"group": false,
"mode": string(mode),
},
})
}
}