Skip to content

Commit

Permalink
Neutral option for GaugePanel (#649)
Browse files Browse the repository at this point in the history
* Some targets (Influx for example) use alias insted of legendFormat (which is Prometheus 'alias'). This commit setup both of them by legendFormat.

* Added `neutral` option for `GaugePanel` (supported by Grafana 9.3.0 - grafana/grafana#38273)

---------

Co-authored-by: JamesGibo <[email protected]>
  • Loading branch information
JaSei and JamesGibo authored Jul 16, 2024
1 parent 16e2bcf commit dc2df71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog
x.x.x ?
=======

* Added `neutral` option for `GaugePanel` (supported by Grafana 9.3.0 - https://github.com/grafana/grafana/discussions/38273)
* Added support `alias` via the `legendFormat` option for `Target`
* **Breaking change:** Fixed spelling errors for temperature units, corrected 'CELSUIS' to 'CELSIUS' and 'FARENHEIT' to 'FAHRENHEIT'.
* Added ``tooltipSort`` parameter to PieChartv2 panel
* Fix mappings for Table
Expand Down
7 changes: 7 additions & 0 deletions grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ class Target(object):
Metric to show.
:param target: Graphite way to select data
:param legendFormat: Target alias. Prometheus use legendFormat, other like Influx use alias. This set legendFormat as well as alias.
"""

expr = attr.ib(default="")
Expand All @@ -598,6 +599,7 @@ def to_json_data(self):
'interval': self.interval,
'intervalFactor': self.intervalFactor,
'legendFormat': self.legendFormat,
'alias': self.legendFormat,
'metric': self.metric,
'refId': self.refId,
'step': self.step,
Expand Down Expand Up @@ -3463,6 +3465,7 @@ class GaugePanel(Panel):
:param thresholdMarkers: option to show marker of level on gauge
:param thresholds: single stat thresholds
:param valueMaps: the list of value to text mappings
:param neutral: neutral point of gauge, leave empty to use Min as neutral point
"""

allValues = attr.ib(default=False, validator=instance_of(bool))
Expand All @@ -3487,6 +3490,7 @@ class GaugePanel(Panel):
validator=instance_of(list),
)
valueMaps = attr.ib(default=attr.Factory(list))
neutral = attr.ib(default=None)

def to_json_data(self):
return self.panel_json(
Expand All @@ -3504,6 +3508,9 @@ def to_json_data(self):
'mappings': self.valueMaps,
'override': {},
'values': self.allValues,
'custom': {
'neutral': self.neutral,
},
},
'showThresholdLabels': self.thresholdLabels,
'showThresholdMarkers': self.thresholdMarkers,
Expand Down

0 comments on commit dc2df71

Please sign in to comment.