Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Add new attributs and methods for bar_gauge_panel #275

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions grafonnet/bar_gauge_panel.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,73 @@
* @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.
* @param reductionFunc (default: null) Reduction method to display data.
* @param options_orientation (default: 'auto') Set display orientation of the graph.
* @param options_displayMode (default: 'lcd') Set display orientation of the graph.
* @param options_min (default: null) Set minimum field value of the graph.
* @param options_max (default: null) Set maximum field value of the graph.
* @param pluginVersion (default: null) Set the version of grafana to match with the graph plugin.
*
* @method addTarget(target) Adds a target object.
* @method addTargets(targets) Adds an array of targets.
* @method addMapping(mapping) Adds a mapping object.
* @method addThreshold(threshold) Adds a threshold object.
*/
new(
title,
description=null,
datasource=null,
unit=null,
thresholds=[],
reductionFunc='mean',
options_orientation='auto',
options_displayMode='lcd',
options_min=1,
options_max=100,
pluginVersion=null,
):: {
type: 'bargauge',
title: title,
[if description != null then 'description']: description,
datasource: datasource,
targets: [
],
fieldConfig: {
defaults: {
unit: unit,
thresholds: {
mode: 'absolute',
steps: thresholds,
options: {
fieldOptions: {
calcs: [
reductionFunc,
],
defaults: {
mappings: [],
thresholds: [],
[if options_min != null then 'min']: options_min,
[if options_max != null then 'max']: options_max,
},
},
[if options_orientation != null then 'orientation']: options_orientation,
[if options_displayMode != null then 'displayMode']: options_displayMode,
showUnfilled: true,
},
[if pluginVersion != null then 'pluginVersion']: pluginVersion,

_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),

_nextMapping:: 0,
addMapping(mapping):: self {
local nextMapping = super._nextMapping,
_nextMapping: nextMapping + 1,
options+: { fieldOptions+: { defaults+: { mappings+: [mapping { id: nextMapping }] } } },
},

_nextThreshold:: 0,
addThreshold(threshold):: self {
local nextThreshold = super._nextThreshold,
_nextThreshold: nextThreshold + 1,
options+: { fieldOptions+: { defaults+: { thresholds+: [threshold { id: nextThreshold }] } } },
},
},
}