-
Notifications
You must be signed in to change notification settings - Fork 1
/
panel.go
177 lines (154 loc) · 3.93 KB
/
panel.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package grafana
type GraphPanel struct {
AliasColors interface{} `json:"aliasColors,omitempty"`
Bars bool `json:"bars"`
Datasource string `json:"datasource,omitempty"`
Editable bool `json:"editable"`
Error bool `json:"error"`
Fill int64 `json:"fill"`
Grid interface{} `json:"grid,omitempty"`
Id int64 `json:"id"`
LeftYAxisLabel string `json:"leftYAxisLabel"`
Legend Legend `json:"legend,omitempty"`
Lines bool `json:"lines"`
Linewidth int64 `json:"linewidth"`
Links []interface{} `json:"links,omitempty"`
MinSpan interface{} `json:"minSpan,omitempty"`
NullPointMode string `json:"nullPointMode"`
Percentage bool `json:"percentage"`
Pointradius int64 `json:"pointradius"`
Points bool `json:"points"`
Renderer string `json:"renderer"`
RightYAxisLabel string `json:"rightYAxisLabel"`
SeriesOverrides []interface{} `json:"seriesOverrides,omitempty"`
Span interface{} `json:"span,omitempty"`
Stack bool `json:"stack"`
SteppedLine bool `json:"steppedLine"`
Targets []Target `json:"targets"`
TimeFrom interface{} `json:"timeFrom,omitempty"`
TimeShift interface{} `json:"timeShift,omitempty"`
Title string `json:"title"`
Tooltip struct {
Shared bool `json:"shared"`
ValueType string `json:"value_type"`
} `json:"tooltip"`
Transparent bool `json:"transparent"`
Type string `json:"type"`
XAxis bool `json:"x-axis"`
YAxis bool `json:"y-axis"`
YFormats []string `json:"y_formats"`
}
type Legend struct {
Avg bool `json:"avg"`
Current bool `json:"current"`
Max bool `json:"max"`
Min bool `json:"min"`
Show bool `json:"show"`
Total bool `json:"total"`
Values bool `json:"values"`
}
func (l *Legend) EnableAvg() *Legend {
l.Show = true
l.Values = true
l.Avg = true
return l
}
func (l *Legend) DisableAvg() *Legend {
l.Avg = false
return l
}
func (l *Legend) EnableCurrent() *Legend {
l.Show = true
l.Values = true
l.Current = true
return l
}
func (l *Legend) DisableCurrent() *Legend {
l.Avg = false
return l
}
func (l *Legend) EnableMax() *Legend {
l.Show = true
l.Values = true
l.Max = true
return l
}
func (l *Legend) DisableMax() *Legend {
l.Max = false
return l
}
func (l *Legend) EnableMin() *Legend {
l.Show = true
l.Values = true
l.Min = true
return l
}
func (l *Legend) DisableMin() *Legend {
l.Min = false
return l
}
func (l *Legend) EnableTotal() *Legend {
l.Show = true
l.Values = true
l.Total = true
return l
}
func (l *Legend) DisableTotal() *Legend {
l.Total = false
return l
}
func (l *Legend) EnableLegend() *Legend {
l.Show = true
l.Values = true
return l
}
func (l *Legend) DisableLegend() *Legend {
l.Show = false
l.Values = true
return l
}
func NewGraphPanel(title string) GraphPanel {
var p GraphPanel
p.Type = "graph"
p.XAxis = true
p.YAxis = true
p.Lines = true
p.Fill = 1
p.Linewidth = 2
p.Renderer = "flot"
p.NullPointMode = "connected"
p.YFormats = []string{
"short",
"short",
}
p.Title = title
p.Legend.EnableLegend()
return p
}
func (p *GraphPanel) SetDatasource(ds string) *GraphPanel {
p.Datasource = ds
return p
}
func (p *GraphPanel) SetStack(check bool) *GraphPanel {
p.Stack = check
return p
}
func (p *GraphPanel) AddTarget(target Target) *GraphPanel {
p.Targets = append(p.Targets, target)
return p
}
func (p *GraphPanel) SetSpanWidth(width int) *GraphPanel {
if width > 12 || width < 0 {
width = 4
}
p.Span = width
return p
}
func (p *GraphPanel) SetLeftYFormat(format string) *GraphPanel {
p.YFormats[0] = format
return p
}
func (p *GraphPanel) SetRightYFormat(format string) *GraphPanel {
p.YFormats[1] = format
return p
}