diff --git a/grafana_dashboards/schema/panel/graph.py b/grafana_dashboards/schema/panel/graph.py index 4d18bb4..c24f235 100644 --- a/grafana_dashboards/schema/panel/graph.py +++ b/grafana_dashboards/schema/panel/graph.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + # Copyright 2015 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +22,68 @@ 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'pps', + u'bps', + u'Bps', + u'ops', + u'rps', + u'wps', + u'iops', + 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', + ) + + y_formats = [y_format] + graph = { v.Required('bars', default=False): v.All(bool), v.Required('fill', default=1): v.All(int), @@ -35,6 +99,7 @@ class Graph(Base): v.Required('y-axis', default=True): v.All(bool), v.Optional('leftYAxisLabel'): v.All(str, v.Length(min=1)), v.Optional('rightYAxisLabel'): v.All(str, v.Length(min=1)), + v.Optional('y_formats'): v.All(y_formats, v.Length(min=2, max=2)), } graph.update(self.base) return v.Schema(graph) diff --git a/tests/schema/fixtures/dashboard-0010.json b/tests/schema/fixtures/dashboard-0010.json new file mode 100644 index 0000000..8944003 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0010.json @@ -0,0 +1,44 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "bars": false, + "editable": true, + "error": false, + "fill": 1, + "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" + } + ], + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0010.yaml b/tests/schema/fixtures/dashboard-0010.yaml new file mode 100644 index 0000000..4f767d7 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0010.yaml @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +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