From 187caf92d71ae9313ab46033d010aa3de4f089e1 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 8 Jan 2016 14:34:28 -0800 Subject: [PATCH] Add support for seriesOverrides Reference: https://github.com/grafana/grafana/blob/master/public/app/plugins/panels/graph/seriesOverridesCtrl.js#L94 Change-Id: I22743f566b32aaa5527237dd023551a8f3a3dbc4 --- grafana_dashboards/schema/panel/graph.py | 22 ++++++++ tests/schema/fixtures/dashboard-0013.json | 62 +++++++++++++++++++++++ tests/schema/fixtures/dashboard-0013.yaml | 27 ++++++++++ 3 files changed, 111 insertions(+) create mode 100644 tests/schema/fixtures/dashboard-0013.json create mode 100644 tests/schema/fixtures/dashboard-0013.yaml diff --git a/grafana_dashboards/schema/panel/graph.py b/grafana_dashboards/schema/panel/graph.py index 1e0b30e..361b7f2 100644 --- a/grafana_dashboards/schema/panel/graph.py +++ b/grafana_dashboards/schema/panel/graph.py @@ -93,6 +93,26 @@ class Graph(Base): v.Required('value_type', default='cumulative'): v.All(value_types), } + series_override = { + v.Required('alias'): v.All(str, v.Length(min=1)), + v.Optional('bars'): v.All(bool), + v.Optional('lines'): v.All(bool), + v.Optional('fill'): v.All(int, v.Range(min=1, max=10)), + v.Optional('width'): v.All(int, v.Range(min=1, max=10)), + v.Optional('nullPointMode'): v.All(null_point_modes), + v.Optional('fillBelowTo'): v.All(str), + v.Optional('steppedLine'): v.All(bool), + v.Optional('points'): v.All(bool), + v.Optional('pointsradius'): v.All(int, v.Range(min=1, max=5)), + v.Optional('stack'): v.All(v.Any(bool, 'A', 'B', 'C', 'D')), + v.Optional('color'): v.All(str), + v.Optional('yaxis'): v.All(int, v.Range(min=1, max=2)), + v.Optional('zindex'): v.All(int, v.Range(min=-3, max=3)), + v.Optional('transform'): v.All(v.Any('negative-Y')), + v.Optional('legend'): v.All(bool), + } + series_overrides = [series_override] + graph = { v.Required('bars', default=False): v.All(bool), v.Required('fill', default=1): v.All(int), @@ -104,6 +124,8 @@ class Graph(Base): 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.Optional('seriesOverrides'): v.All(series_overrides, + 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), diff --git a/tests/schema/fixtures/dashboard-0013.json b/tests/schema/fixtures/dashboard-0013.json new file mode 100644 index 0000000..8c95a81 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0013.json @@ -0,0 +1,62 @@ +{ + "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, + "seriesOverrides": [ + { + "alias": "foo", + "bars": true, + "color": "#ff00ff", + "fill": 5, + "fillBelowTo": "something", + "legend": true, + "lines": true, + "nullPointMode": "null as zero", + "points": true, + "pointsradius": 3, + "stack": true, + "steppedLine": true, + "transform": "negative-Y", + "width": 5, + "yaxis": 2, + "zindex": 1 + }, + { + "alias": "bar", + "stack": "A" + } + ], + "span": 12, + "stack": false, + "steppedLine": false, + "targets": [], + "title": "no title (click here)", + "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-0013.yaml b/tests/schema/fixtures/dashboard-0013.yaml new file mode 100644 index 0000000..29a335e --- /dev/null +++ b/tests/schema/fixtures/dashboard-0013.yaml @@ -0,0 +1,27 @@ +dashboard: + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - title: no title (click here) + type: graph + seriesOverrides: + - alias: foo + bars: True + lines: True + fill: 5 + width: 5 + nullPointMode: null as zero + fillBelowTo: something + steppedLine: True + points: True + pointsradius: 3 + stack: True + color: '#ff00ff' + yaxis: 2 + zindex: 1 + transform: negative-Y + legend: True + - alias: bar + stack: A