From 5bce176207eb6898e85525005dbcd009a3e97c7e Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 24 Sep 2020 14:22:08 +0200 Subject: [PATCH 1/6] Added new attributs and methods to bar_gauge_panel --- grafonnet/bar_gauge_panel.libsonnet | 94 +++++++++++++++++++---------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index 313e5a03..a116fd01 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -8,40 +8,72 @@ * @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=[], - ):: { - type: 'bargauge', - title: title, - [if description != null then 'description']: description, - datasource: datasource, - targets: [ - ], - fieldConfig: { - defaults: { - unit: unit, - thresholds: { - mode: 'absolute', - steps: thresholds, + new( + title, + description=null, + datasource=null, + unit=null, + 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, + options: { + "fieldOptions": { + "calcs": [ + reductionFunc + ], + "defaults": { + "mappings": [], + "thresholds": [], + [if options_min != null then 'min']: options_min, + [if options_max != null then 'max']: options_max, + } + }, + orientation: options_orientation, + displayMode: options_displayMode, + }, + [if pluginVersion != null then 'pluginVersion']: pluginVersion, + + _nextTarget:: 0, + addTarget(target):: self { + 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 }] } } }, }, - }, - }, - _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), - }, -} +} \ No newline at end of file From 1048272e8b2428163df9b2529efeb37fae2713c4 Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 24 Sep 2020 14:26:30 +0200 Subject: [PATCH 2/6] Added new attributs and methods to bar_gauge_panel --- grafonnet/bar_gauge_panel.libsonnet | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index a116fd01..bf064b0c 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -48,8 +48,9 @@ [if options_max != null then 'max']: options_max, } }, - orientation: options_orientation, - displayMode: options_displayMode, + [if options_orientation != null then 'orientation']: options_orientation, + [if options_displayMode != null then 'displayMode']: options_displayMode, + showUnfilled: true, }, [if pluginVersion != null then 'pluginVersion']: pluginVersion, From f3a1ec65141d4cf9a5dafe1a6700c937c23f9bd1 Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 24 Sep 2020 14:27:46 +0200 Subject: [PATCH 3/6] add empty line at the end --- grafonnet/bar_gauge_panel.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index bf064b0c..a45298b2 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -77,4 +77,4 @@ options+: {fieldOptions+: { defaults+: { thresholds+: [threshold { id: nextThreshold }] } } }, }, }, -} \ No newline at end of file +} From be0e4ab92a45d55453906dfdc80cf3c10178950a Mon Sep 17 00:00:00 2001 From: Bastien Date: Fri, 25 Sep 2020 09:57:41 +0200 Subject: [PATCH 4/6] Indent file properly --- grafonnet/bar_gauge_panel.libsonnet | 104 ++++++++++++++-------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index a45298b2..a27fcb94 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -20,61 +20,61 @@ * @method addMapping(mapping) Adds a mapping object. * @method addThreshold(threshold) Adds a threshold object. */ - new( - title, - description=null, - datasource=null, - unit=null, - 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, - 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, + new( + title, + description=null, + datasource=null, + unit=null, + 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, + 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 { - local nextTarget = super._nextTarget, - _nextTarget: nextTarget + 1, - targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], - }, + _nextTarget:: 0, + addTarget(target):: self { + 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), + 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 }] } } }, - }, + _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 }] } } }, - }, + _nextThreshold:: 0, + addThreshold(threshold):: self { + local nextThreshold = super._nextThreshold, + _nextThreshold: nextThreshold + 1, + options+: {fieldOptions+: { defaults+: { thresholds+: [threshold { id: nextThreshold }] } } }, }, + }, } From 1b3d7c3ff6ce2a633d3274341cfc1aba6b100d9a Mon Sep 17 00:00:00 2001 From: Bastien Date: Sat, 26 Sep 2020 14:55:41 +0200 Subject: [PATCH 5/6] Pass unit testing --- grafonnet/bar_gauge_panel.libsonnet | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index a27fcb94..e407d905 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -37,16 +37,16 @@ [if description != null then 'description']: description, datasource: datasource, options: { - "fieldOptions": { - "calcs": [ - reductionFunc + fieldOptions: { + calcs: [ + reductionFunc, ], - "defaults": { - "mappings": [], - "thresholds": [], + 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, @@ -67,14 +67,14 @@ addMapping(mapping):: self { local nextMapping = super._nextMapping, _nextMapping: nextMapping + 1, - options+: {fieldOptions+: { defaults+: { mappings+: [mapping { id: nextMapping }] } } }, + 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 }] } } }, + options+: { fieldOptions+: { defaults+: { thresholds+: [threshold { id: nextThreshold }] } } }, }, }, -} +} \ No newline at end of file From 33e845919454879aa7ecf3461db3c9ea83273fca Mon Sep 17 00:00:00 2001 From: Bastien Date: Tue, 29 Sep 2020 14:56:24 +0200 Subject: [PATCH 6/6] Reformat file --- grafonnet/bar_gauge_panel.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index e407d905..01488d15 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -77,4 +77,4 @@ options+: { fieldOptions+: { defaults+: { thresholds+: [threshold { id: nextThreshold }] } } }, }, }, -} \ No newline at end of file +}