From cdc1df0e276b3ce690352e00b689c205f29bba2b Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 7 Jan 2016 14:14:28 -0800 Subject: [PATCH] Add tooltip customization support This is important for stacked graphs so that the tooltip can show individual, rather than cumulative values (which makes the most sense for our node graphs). Also, sort the elements in the schema. I think keeping them all in order makes more sense than required/optional sections. Change-Id: Ie542dc4d0e151a00e84cc970c2cfa8c02377d7bf --- grafana_dashboards/schema/panel/graph.py | 14 ++++++-- tests/schema/fixtures/dashboard-0012.json | 43 +++++++++++++++++++++++ tests/schema/fixtures/dashboard-0012.yaml | 12 +++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/schema/fixtures/dashboard-0012.json create mode 100644 tests/schema/fixtures/dashboard-0012.yaml diff --git a/grafana_dashboards/schema/panel/graph.py b/grafana_dashboards/schema/panel/graph.py index f102476..1e0b30e 100644 --- a/grafana_dashboards/schema/panel/graph.py +++ b/grafana_dashboards/schema/panel/graph.py @@ -85,23 +85,31 @@ class Graph(Base): y_formats = [y_format] null_point_modes = v.Any('connected', 'null', 'null as zero') + value_types = v.Any('individual', 'cumulative') + + tooltip = { + v.Required('query_as_alias', default=True): v.All(bool), + v.Required('shared', default=True): v.All(bool), + v.Required('value_type', default='cumulative'): v.All(value_types), + } graph = { v.Required('bars', default=False): v.All(bool), v.Required('fill', default=1): v.All(int), + v.Optional('leftYAxisLabel'): v.All(str, v.Length(min=1)), v.Required('lines', default=True): v.All(bool), v.Required('linewidth', default=2): v.All(int), + v.Optional('nullPointMode'): v.All(null_point_modes), v.Required('percentage', default=False): v.All(bool), v.Required('pointradius', default=5): v.All(int), v.Required('points', default=False): v.All(bool), + v.Optional('rightYAxisLabel'): v.All(str, v.Length(min=1)), v.Required('stack', default=False): v.All(bool), v.Required('steppedLine', default=False): v.All(bool), v.Required('targets', default=[]): v.All(list), + 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('nullPointMode'): v.All(null_point_modes), - 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) diff --git a/tests/schema/fixtures/dashboard-0012.json b/tests/schema/fixtures/dashboard-0012.json new file mode 100644 index 0000000..cde1484 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0012.json @@ -0,0 +1,43 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "bars": false, + "editable": true, + "error": false, + "fill": 1, + "lines": true, + "linewidth": 2, + "percentage": false, + "pointradius": 5, + "points": false, + "span": 12, + "stack": false, + "steppedLine": false, + "targets": [], + "title": "no title (click here)", + "tooltip": { + "query_as_alias": true, + "shared": true, + "value_type": "individual" + }, + "type": "graph", + "x-axis": true, + "y-axis": true + } + ], + "showTitle": false, + "title": "New row" + } + ], + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0012.yaml b/tests/schema/fixtures/dashboard-0012.yaml new file mode 100644 index 0000000..9b3c88a --- /dev/null +++ b/tests/schema/fixtures/dashboard-0012.yaml @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + +dashboard: + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: graph + tooltip: + value_type: individual