From f4b52386cc9ab575cf5c52c7167d88cf39f8ee71 Mon Sep 17 00:00:00 2001 From: akrzos Date: Wed, 7 Feb 2018 13:25:26 -0500 Subject: [PATCH] Add yaxes format for newer versions of Grafana y_formats has moved to yaxes, but still support y_formats Change-Id: Iabd1302352c77dc82c543412596e21550e4c0579 --- grafana_dashboards/schema/panel/graph.py | 16 +++++-- tests/schema/fixtures/dashboard-0025.json | 58 +++++++++++++++++++++++ tests/schema/fixtures/dashboard-0025.yaml | 13 +++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 tests/schema/fixtures/dashboard-0025.json create mode 100644 tests/schema/fixtures/dashboard-0025.yaml diff --git a/grafana_dashboards/schema/panel/graph.py b/grafana_dashboards/schema/panel/graph.py index 8c4a788..f33a10e 100644 --- a/grafana_dashboards/schema/panel/graph.py +++ b/grafana_dashboards/schema/panel/graph.py @@ -81,8 +81,17 @@ class Graph(Base): u'pressurehg', u'pressurepsi', ) - - y_formats = [y_format] + yaxes_format = [ + { + v.Optional('decimals'): int, + v.Optional('format', default='short'): y_format, + 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, v.Range(min=1)), + v.Optional('min'): v.All(int, v.Range(min=1)), + v.Optional('show', default=True): v.All(bool), + } + ] legend = { v.Optional('alignAsTable', default=False): v.All(bool), @@ -149,7 +158,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_formats, v.Length(min=2, max=2)), + v.Optional('y_formats'): v.All([y_format], v.Length(min=2, max=2)), + v.Optional('yaxes'): v.All(yaxes_format, v.Length(min=2, max=2)), } graph.update(self.base) return v.Schema(graph) diff --git a/tests/schema/fixtures/dashboard-0025.json b/tests/schema/fixtures/dashboard-0025.json new file mode 100644 index 0000000..7e9675c --- /dev/null +++ b/tests/schema/fixtures/dashboard-0025.json @@ -0,0 +1,58 @@ +{ + "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, + "yaxes": [ + { + "format": "hertz", + "label": "", + "logBase": 1, + "show": true + }, + { + "format": "\u00b5s", + "label": "", + "logBase": 1, + "show": true + } + ] + } + ], + "showTitle": false, + "title": "New row" + } + ], + "templating": { + "enabled": false, + "list": [] + }, + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0025.yaml b/tests/schema/fixtures/dashboard-0025.yaml new file mode 100644 index 0000000..bb15d5f --- /dev/null +++ b/tests/schema/fixtures/dashboard-0025.yaml @@ -0,0 +1,13 @@ +dashboard: + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: graph + leftYAxisLabel: left label + rightYAxisLabel: right label + yaxes: + - format: hertz + - format: µs