From cf1f9c347dc0a9ab93b6f957ef3cecf3871bc237 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kalitowski Date: Thu, 24 Sep 2020 11:14:40 +0200 Subject: [PATCH 1/5] allow to set up orientation and displayMode of barguage --- grafonnet/bar_gauge_panel.libsonnet | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index 313e5a03..58584fd8 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -19,6 +19,8 @@ datasource=null, unit=null, thresholds=[], + orientation=null, + displayMode=null, ):: { type: 'bargauge', title: title, @@ -43,5 +45,17 @@ targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], }, addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + "options": { + "reduceOptions": { + "values": false, + "calcs": [ + "mean" + ], + "fields": "" + }, + "orientation": orientation, + "displayMode": displayMode, + "showUnfilled": true + }, }, } From 24512e625afccf0ee7b8b6c1af7593608450b70c Mon Sep 17 00:00:00 2001 From: Przemyslaw Kalitowski Date: Thu, 24 Sep 2020 11:17:58 +0200 Subject: [PATCH 2/5] add comment about new variables --- grafonnet/bar_gauge_panel.libsonnet | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index 58584fd8..82181c6a 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -9,6 +9,8 @@ * @param datasource (optional) Panel datasource. * @param unit (optional) The unit of the data. * @param thresholds (optional) An array of threashold values. + * @param orientation (optional) string (horizontal or vertical) + * @param displayMode (optional) string (eg. lcd) * * @method addTarget(target) Adds a target object. * @method addTargets(targets) Adds an array of targets. From 59188343f3cc904a85ce26e27fc69ca4c4ced5bf Mon Sep 17 00:00:00 2001 From: Przemyslaw Kalitowski Date: Thu, 24 Sep 2020 11:50:36 +0200 Subject: [PATCH 3/5] add check if orienation and displayMode is configured --- grafonnet/bar_gauge_panel.libsonnet | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index 82181c6a..7bd42506 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -55,8 +55,8 @@ ], "fields": "" }, - "orientation": orientation, - "displayMode": displayMode, + [if orientation !=null then 'orientation']: orientation, + [if displayMode !=null then 'displayMode']: displayMode, "showUnfilled": true }, }, From ff0ee8db20efd6bf601168d79c1bae2540d02573 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kalitowski Date: Thu, 24 Sep 2020 13:42:10 +0200 Subject: [PATCH 4/5] after test-update --- grafonnet/bar_gauge_panel.libsonnet | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index 7bd42506..e08df7b1 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -47,17 +47,17 @@ targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], }, addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), - "options": { - "reduceOptions": { - "values": false, - "calcs": [ - "mean" - ], - "fields": "" + options: { + reduceOptions: { + values: false, + calcs: [ + 'mean', + ], + fields: '', + }, + [if orientation != null then 'orientation']: orientation, + [if displayMode != null then 'displayMode']: displayMode, + showUnfilled: true, }, - [if orientation !=null then 'orientation']: orientation, - [if displayMode !=null then 'displayMode']: displayMode, - "showUnfilled": true - }, }, } From 2d5be87b0dfcd2f11d37a40263bfedbb942c928a Mon Sep 17 00:00:00 2001 From: Przemyslaw Kalitowski Date: Fri, 25 Sep 2020 11:29:09 +0200 Subject: [PATCH 5/5] add params to let configure other values --- grafonnet/bar_gauge_panel.libsonnet | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/grafonnet/bar_gauge_panel.libsonnet b/grafonnet/bar_gauge_panel.libsonnet index e08df7b1..5b49e752 100644 --- a/grafonnet/bar_gauge_panel.libsonnet +++ b/grafonnet/bar_gauge_panel.libsonnet @@ -9,8 +9,12 @@ * @param datasource (optional) Panel datasource. * @param unit (optional) The unit of the data. * @param thresholds (optional) An array of threashold values. + * @param values (optional) Bool if show values + * @param calcs (optional) An array of type of calculation + * @param fields (optional) string - fields that should be included in the panel * @param orientation (optional) string (horizontal or vertical) * @param displayMode (optional) string (eg. lcd) + * @param showUnfilled (optional) bool if showUnfilled * * @method addTarget(target) Adds a target object. * @method addTargets(targets) Adds an array of targets. @@ -21,8 +25,12 @@ datasource=null, unit=null, thresholds=[], - orientation=null, - displayMode=null, + values=false, + calcs=['mean'], + fields='', + orientation='auto', + displayMode='gradient', + showUnfilled=true, ):: { type: 'bargauge', title: title, @@ -49,15 +57,13 @@ addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), options: { reduceOptions: { - values: false, - calcs: [ - 'mean', - ], - fields: '', + values: values, + calcs: calcs, + fields: fields, }, - [if orientation != null then 'orientation']: orientation, - [if displayMode != null then 'displayMode']: displayMode, - showUnfilled: true, + orientation: orientation, + displayMode: displayMode, + showUnfilled: showUnfilled, }, }, }