Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added StatSpecialValuesMapping #675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build/
dist/
.uptodate
/.env
.venv
test-results/junit-*.xml
/.cache
.ensure-*
Expand Down
36 changes: 36 additions & 0 deletions grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,42 @@ def to_json_data(self):
}
)

@attr.s
class StatSpecialMapping(object):
"""
Generates json structure for special value mapping item for the StatPanel:

:param text: String that will replace input value
:param match: Special value to look for
Possible values: null, nan, null+nan, true, false, empty
:param color: How to color the text if mapping occurs
:param index: index
"""

text = attr.ib()
match = attr.ib(default='', validator=in_([
'null',
'nan',
'null+nan',
'true',
'false',
'empty'
]))
color = attr.ib(default='', validator=instance_of(str))
index = attr.ib(default=None)

def to_json_data(self):
return {
'options': {
'match': self.match,
'result': {
'color': self.color,
'index': self.index,
'text': self.text
}
},
'type': 'special'
}

@attr.s
class StatValueMappingItem(object):
Expand Down