From 0fd7eb7d98aaec99c66631b74beb725f2458fc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draic=20Calpin?= Date: Thu, 28 Sep 2023 15:08:26 +0100 Subject: [PATCH 1/2] Add the Unit field to Graph Panels --- grafanalib/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/grafanalib/core.py b/grafanalib/core.py index 037ef7c1..b9f5e06e 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -2059,7 +2059,7 @@ class Graph(Panel): :param stack: Each series is stacked on top of another :param percentage: Available when Stack is selected. Each series is drawn as a percentage of the total of all series :param thresholds: List of GraphThresholds - Only valid when alert not defined - + :param unit: Set Y Axis Unit """ alert = attr.ib(default=None) @@ -2093,6 +2093,7 @@ class Graph(Panel): validator=instance_of(Tooltip), ) thresholds = attr.ib(default=attr.Factory(list)) + unit = attr.ib(default='', validator=instance_of(str)) xAxis = attr.ib(default=attr.Factory(XAxis), validator=instance_of(XAxis)) try: yAxes = attr.ib( @@ -2112,6 +2113,11 @@ def to_json_data(self): 'aliasColors': self.aliasColors, 'bars': self.bars, 'error': self.error, + 'fieldConfig': { + 'defaults': { + 'unit': self.unit + }, + }, 'fill': self.fill, 'grid': self.grid, 'isNew': self.isNew, From 4b59302b11e5218e81d5b1d2ff51b10fb1f85cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draic=20Calpin?= Date: Thu, 28 Sep 2023 15:09:40 +0100 Subject: [PATCH 2/2] Update changelog for Graph Panel --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index af9c2c7d..c521a4e9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,7 @@ Changelog ================== * Added ... +* Add Unit option for Graph panel * Added Minimum option for Timeseries * Added Maximum option for Timeseries * Added Number of decimals displays option for Timeseries