summaryrefslogtreecommitdiffstats
path: root/monitoring/ceph-mixin/dashboards/piechart_panel.libsonnet
blob: 68ff71954a9c2528f025399b8b125ea6f7c08cd5 (plain)
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
{
  /**
   * Creates a pie chart panel.
   *
   * @name pieChartPanel.new
   *
   * @param title The title of the pie chart panel.
   * @param description (default `''`) Description of the panel
   * @param datasource (optional) Datasource
   * @param pieType (default `'pie'`) Type of pie chart (one of pie or donut)
   *
   * @method addTarget(target) Adds a target object.
   */
  new(
    title,
    description='',
    datasource=null,
    gridPos={},
    displayMode='table',
    placement='bottom',
    showLegend=true,
    displayLabels=[],
    tooltip={},
    pieType='pie',
    values=[],
    colorMode='auto',
    overrides=[],
    reduceOptions={},
  ):: {
    type: 'piechart',
    [if description != null then 'description']: description,
    title: title,
    gridPos: gridPos,
    datasource: datasource,
    options: {
      legend: {
        calcs: [],
        values: values,
        displayMode: displayMode,
        placement: placement,
        showLegend: showLegend,
      },
      pieType: pieType,
      tooltip: tooltip,
      displayLabels: displayLabels,
      reduceOptions: reduceOptions,
    },
    fieldConfig: {
      defaults: {
        color: { mode: colorMode },
        mappings: [],
        custom: {
          hideFrom: {
            legend: false,
            tooltip: false,
            viz: false,
          },
        },
      },
      overrides: overrides,
    },
    targets: [
    ],
    _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),
  },
}