From 96cf8f97d4be15f035cc856d204516c00564b8a8 Mon Sep 17 00:00:00 2001 From: akrzos Date: Tue, 2 Jan 2018 16:07:52 -0500 Subject: [PATCH] Add legend for graphs Simple support for a legend on graphs. Change-Id: I3dc96a1463a8e765b9c97fa2fd1550872d7a285f --- grafana_dashboards/schema/panel/graph.py | 13 +++++ tests/schema/fixtures/dashboard-0023.json | 68 +++++++++++++++++++++++ tests/schema/fixtures/dashboard-0023.yaml | 27 +++++++++ 3 files changed, 108 insertions(+) create mode 100644 tests/schema/fixtures/dashboard-0023.json create mode 100644 tests/schema/fixtures/dashboard-0023.yaml diff --git a/grafana_dashboards/schema/panel/graph.py b/grafana_dashboards/schema/panel/graph.py index ada6f78..8c4a788 100644 --- a/grafana_dashboards/schema/panel/graph.py +++ b/grafana_dashboards/schema/panel/graph.py @@ -84,6 +84,18 @@ class Graph(Base): y_formats = [y_format] + legend = { + v.Optional('alignAsTable', default=False): v.All(bool), + v.Optional('avg', default=False): v.All(bool), + v.Optional('current', default=False): v.All(bool), + v.Optional('max', default=False): v.All(bool), + v.Optional('min', default=False): v.All(bool), + v.Optional('rightSide', default=False): v.All(bool), + v.Optional('show', default=False): v.All(bool), + v.Optional('total', default=False): v.All(bool), + v.Optional('values', default=False): v.All(bool), + } + null_point_modes = v.Any('connected', 'null', 'null as zero') value_types = v.Any('individual', 'cumulative') @@ -119,6 +131,7 @@ class Graph(Base): v.Required('fill', default=1): v.All(int), v.Optional('hideTimeOverride'): v.All(bool), v.Optional('leftYAxisLabel'): v.All(str, v.Length(min=1)), + v.Optional('legend'): v.All(legend), v.Required('lines', default=True): v.All(bool), v.Required('linewidth', default=2): v.All(int), v.Optional('nullPointMode'): v.All(null_point_modes), diff --git a/tests/schema/fixtures/dashboard-0023.json b/tests/schema/fixtures/dashboard-0023.json new file mode 100644 index 0000000..61bbaa8 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0023.json @@ -0,0 +1,68 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "bars": false, + "datasource": "graphite", + "editable": true, + "error": false, + "fill": 1, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "percentage": false, + "pointradius": 5, + "points": false, + "span": 12, + "stack": false, + "steppedLine": false, + "targets": [ + { + "target": "$hostname.Cpu.cpu_prct_used" + } + ], + "title": "no title (click here)", + "type": "graph", + "x-axis": true, + "y-axis": true + } + ], + "showTitle": false, + "title": "New row" + } + ], + "templating": { + "enabled": true, + "list": [ + { + "datasource": "graphite", + "includeAll": false, + "multi": false, + "name": "hostname", + "query": "node*", + "refresh": true, + "type": "query" + } + ] + }, + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0023.yaml b/tests/schema/fixtures/dashboard-0023.yaml new file mode 100644 index 0000000..89f3f36 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0023.yaml @@ -0,0 +1,27 @@ +dashboard: + templating: + - name: hostname + type: query + datasource: graphite + query: node* + refresh: true + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: graph + datasource: graphite + targets: + - target: $hostname.Cpu.cpu_prct_used + legend: + alignAsTable: true + avg: true + current: true + max: true + min: true + rightSide: true + show: true + total: false + values: true