Support formatting.

Adding format to schema base panel, in order to use graph unit e.g
bytes, precent, deckbytes etc.

Change-Id: I754596738970177bb70c5425d38e1291c56c84a9
This commit is contained in:
Eldad Marciano 2018-03-06 14:20:40 +02:00
parent ca98fba97f
commit f1c684c1c2
4 changed files with 84 additions and 75 deletions

View File

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +18,21 @@ import voluptuous as v
class Base(object):
formats = v.Any(u'none', u'short', u'percent', u'percentunit',
u'humidity', u'ppm', u'dB', u'currencyUSD',
u'currencyGBP', u'currencyEUR', u'currencyJPY', u'hertz',
u'ns', u'µs', u'ms', u's', u'm', u'h', u'd', u'bits',
u'bytes', u'kbytes', u'mbytes', u'gbytes', u'decbits',
u'decbytes', u'deckbytes', u'decmbytes', u'decgbytes',
u'pps', u'bps', u'Bps', u'Kbits', u'KBs', u'Mbits',
u'MBs', u'GBs', u'Gbits', u'ops', u'rps', u'wps', u'iops',
u'opm', u'rpm', u'wpm', u'lengthmm', u'lengthm',
u'lengthkm', u'lengthmi', u'velocityms', u'velocitykmh',
u'velocitymph', u'velocityknot', u'mlitre', u'litre',
u'm3', u'watt', u'kwatt', u'watth', u'kwatth', u'joule',
u'ev', u'amp', u'volt', u'celsius', u'farenheit',
u'kelvin', u'pressurembar', u'pressurehpa', u'pressurehg',
u'pressurepsi')
def __init__(self):
self.base = {
@ -26,6 +43,7 @@ class Base(object):
v.Required('type'): v.Any(
'dashlist', 'graph', 'singlestat', 'text'),
v.Optional('id'): int,
v.Optional('format'): v.Any(self.formats, v.Length(min=1)),
}
def get_schema(self):

View File

@ -22,83 +22,10 @@ from grafana_dashboards.schema.panel.base import Base
class Graph(Base):
def get_schema(self):
y_format = v.Any(
u'none',
u'short',
u'percent',
u'percentunit',
u'humidity',
u'ppm',
u'dB',
u'currencyUSD',
u'currencyGBP',
u'currencyEUR',
u'currencyJPY',
u'hertz',
u'ns',
u'µs',
u'ms',
u's',
u'm',
u'h',
u'd',
u'bits',
u'bytes',
u'kbytes',
u'mbytes',
u'gbytes',
u'decbits',
u'decbytes',
u'deckbytes',
u'decmbytes',
u'decgbytes',
u'pps',
u'bps',
u'Bps',
u'Kbits',
u'KBs',
u'Mbits',
u'MBs',
u'GBs',
u'Gbits',
u'ops',
u'rps',
u'wps',
u'iops',
u'opm',
u'rpm',
u'wpm',
u'lengthmm',
u'lengthm',
u'lengthkm',
u'lengthmi',
u'velocityms',
u'velocitykmh',
u'velocitymph',
u'velocityknot',
u'mlitre',
u'litre',
u'm3',
u'watt',
u'kwatt',
u'watth',
u'kwatth',
u'joule',
u'ev',
u'amp',
u'volt',
u'celsius',
u'farenheit',
u'kelvin',
u'pressurembar',
u'pressurehpa',
u'pressurehg',
u'pressurepsi',
)
yaxes_format = [
{
v.Optional('decimals'): v.All(int),
v.Optional('format', default='short'): y_format,
v.Optional('format', default='short'): Base.formats,
v.Optional('label', default=''): v.All(str),
v.Optional('logBase', default=1): v.All(int, v.Range(min=1)),
v.Optional('max'): v.All(int),
@ -175,7 +102,8 @@ class Graph(Base):
v.Optional('tooltip'): v.All(tooltip),
v.Required('x-axis', default=True): v.All(bool),
v.Required('y-axis', default=True): v.All(bool),
v.Optional('y_formats'): v.All([y_format], v.Length(min=2, max=2)),
v.Optional('y_formats'): v.All([Base.formats],
v.Length(min=2, max=2)),
v.Optional('yaxes'): v.All(yaxes_format, v.Length(min=2, max=2)),
}
graph.update(self.base)

View File

@ -0,0 +1,49 @@
{
"dashboard": {
"new-dashboard": {
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"bars": false,
"editable": true,
"error": false,
"fill": 1,
"format": "bytes",
"leftYAxisLabel": "left label",
"lines": true,
"linewidth": 2,
"percentage": false,
"pointradius": 5,
"points": false,
"rightYAxisLabel": "right label",
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [],
"title": "no title (click here)",
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"hertz",
"\u00b5s"
]
}
],
"showTitle": false,
"title": "New row"
}
],
"templating": {
"enabled": false,
"list": []
},
"timezone": "utc",
"title": "New dashboard"
}
}
}

View File

@ -0,0 +1,14 @@
dashboard:
title: New dashboard
rows:
- title: New row
height: 250px
panels:
- title: no title (click here)
type: graph
leftYAxisLabel: left label
rightYAxisLabel: right label
y_formats:
- hertz
- µs
format: bytes