forked from grafana/grafonnet-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpie_chart_panel.libsonnet
72 lines (72 loc) · 2.54 KB
/
pie_chart_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
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
{
/**
* Creates a pie chart panel.
* It requires the [pie chart panel plugin in grafana](https://grafana.com/grafana/plugins/grafana-piechart-panel),
* which needs to be explicitly installed.
*
* @name pieChartPanel.new
*
* @param title The title of the pie chart panel.
* @param description (default `''`) Description of the panel
* @param span (optional) Width of the panel
* @param min_span (optional) Min span
* @param datasource (optional) Datasource
* @param aliasColors (optional) Define color mappings
* @param pieType (default `'pie'`) Type of pie chart (one of pie or donut)
* @param showLegend (default `true`) Show legend
* @param showLegendPercentage (default `true`) Show percentage values in the legend
* @param legendType (default `'Right side'`) Type of legend (one of 'Right side', 'Under graph' or 'On graph')
* @param valueName (default `'current') Type of tooltip value
* @param repeat (optional) Variable used to repeat the pie chart
* @param repeatDirection (optional) Which direction to repeat the panel, 'h' for horizontal and 'v' for vertical
* @param maxPerRow (optional) Number of panels to display when repeated. Used in combination with repeat.
* @return A json that represents a pie chart panel
*
* @method addTarget(target) Adds a target object.
*/
new(
title,
description='',
span=null,
min_span=null,
datasource=null,
height=null,
aliasColors={},
pieType='pie',
valueName='current',
showLegend=true,
showLegendPercentage=true,
legendType='Right side',
repeat=null,
repeatDirection=null,
maxPerRow=null,
):: {
type: 'grafana-piechart-panel',
[if description != null then 'description']: description,
pieType: pieType,
title: title,
aliasColors: aliasColors,
[if span != null then 'span']: span,
[if min_span != null then 'minSpan']: min_span,
[if height != null then 'height']: height,
[if repeat != null then 'repeat']: repeat,
[if repeatDirection != null then 'repeatDirection']: repeatDirection,
[if maxPerRow != null then 'maxPerRow']: maxPerRow,
valueName: valueName,
datasource: datasource,
legend: {
show: showLegend,
values: true,
percentage: showLegendPercentage,
},
legendType: legendType,
targets: [
],
_nextTarget:: 0,
addTarget(target):: self {
local nextTarget = super._nextTarget,
_nextTarget: nextTarget + 1,
targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }],
},
},
}