# panel_bargauge.py
# V0.5.0 LDO 19/10/2022: initial version
# V0.5.1 LDO 12/11/2022: refactor modules
# V0.6.1 LDO 17/12/2022: release candidate 1
'''
grafanacode:
class for generating bargauge panels
'''
#******************************************************************************
# EXTERNAL MODULE REFERENCES
#******************************************************************************
from attrs import define, field, Factory
from attr.validators import in_, instance_of, optional, deep_iterable
from grafanacode import funcs
from grafanacode.plugins import panel_base
#******************************************************************************
# Panel Property classes: store panel property configuration parts
#******************************************************************************
#******************************************************************************
# Panel Class
#******************************************************************************
[docs]@define(slots=False)
class PanelBarGauge(panel_base.PanelBaseExtOpt1):
'''
Dataclass encapsulating a bargauge panel
'''
# logging level of this item
loglevel : int = 15
# attributes
displaymode = field( default='lcd',
validator=in_(['basic', 'lcd', 'gradient']))
showunfilled = field( default=True,
validator=instance_of(bool))
minvizwidth = field( default=0,
validator=instance_of(int))
minvizheight = field( default=10,
validator=instance_of(int))
# message
def __attrs_post_init__(self):
'''
Attrs post init, just print a message.
'''
print (f' > Init Panel: {self.title} - type: PanelBarGauge ')
[docs] def getJson(self, customjson={}, dashboard=None, panel=None):
'''
Create the json to pack this panel.
Parameters:
customjson (dict): custom or child class json code to add
Returns:
dict: panel json code
'''
# pylint: disable=unused-argument
hjson = super().getJson(
{
'options': {
'displayMode' : self.displaymode,
'showUnfilled' : self.showunfilled,
'minVizWidth' : self.minvizwidth,
'minVizHeight' : self.minvizheight,
},
'type' : 'bargauge',
}
)
# merge child class JSON
funcs.deepMerge(hjson, customjson)
return hjson
#******************************************************************************
# EXTRACT FUNCTIONS : EXTRACT A CREATION SCRIPT FROM A JSON
#******************************************************************************
# pylint: disable=invalid-name