forked from grafana/grafonnet-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar_gauge_panel.libsonnet
47 lines (47 loc) · 1.28 KB
/
bar_gauge_panel.libsonnet
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
{
/**
* Create a [bar gauge panel](https://grafana.com/docs/grafana/latest/panels/visualizations/bar-gauge-panel/),
*
* @name barGaugePanel.new
*
* @param title Panel title.
* @param description (optional) Panel description.
* @param datasource (optional) Panel datasource.
* @param unit (optional) The unit of the data.
* @param thresholds (optional) An array of threashold values.
*
* @method addTarget(target) Adds a target object.
* @method addTargets(targets) Adds an array of targets.
*/
new(
title,
description=null,
datasource=null,
unit=null,
thresholds=[],
):: {
type: 'bargauge',
title: title,
[if description != null then 'description']: description,
datasource: datasource,
targets: [
],
fieldConfig: {
defaults: {
unit: unit,
thresholds: {
mode: 'absolute',
steps: thresholds,
},
},
},
_nextTarget:: 0,
addTarget(target):: self {
// automatically ref id in added targets.
local nextTarget = super._nextTarget,
_nextTarget: nextTarget + 1,
targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }],
},
addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self),
},
}