Skip to content

Commit

Permalink
Merge pull request #122 from jakubplichta/improvements
Browse files Browse the repository at this point in the history
Add sane defaults to graph axes
  • Loading branch information
jakubplichta authored Apr 15, 2018
2 parents 46f90b3 + 1590ff5 commit d23081b
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3"
services:
grafana-graphite:
image: "kamon/grafana_graphite"
ports:
- "2003:2003"
- "8380:80"
- "8381:81"
5 changes: 5 additions & 0 deletions grafana_dashboards/components/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Yaxes(JsonListGenerator):
def __init__(self, data, registry):
super(Yaxes, self).__init__(data, registry, YaxesItemBase)

def gen_json_from_data(self, data, context):
if len(data) == 1:
data.append(data[0])
return super(Yaxes, self).gen_json_from_data(data, context)

def gen_item_json(self, items, result_list):
if isinstance(items, dict) and len(items) > 1:
result_list.append(items)
Expand Down
3 changes: 2 additions & 1 deletion grafana_dashboards/components/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PanelsItemBase(JsonGenerator):
class Graph(PanelsItemBase):

_copy_fields = {'stack', 'fill', 'aliasColors', 'leftYAxisLabel', 'bars', 'lines', 'linewidth', 'y_formats',
'x-axis', 'y-axis', 'xaxis', 'points', 'pointradius', 'percentage', 'steppedLine', 'repeat',
'x-axis', 'y-axis', 'points', 'pointradius', 'percentage', 'steppedLine', 'repeat',
'minSpan'}

def gen_json_from_data(self, data, context):
Expand Down Expand Up @@ -89,6 +89,7 @@ def gen_json_from_data(self, data, context):
or 'grid' in self.data and ('leftMin' in grid_data or 'leftMax' in grid_data))
and ('y_formats' not in self.data)):
panel_json['y_formats'] = ['short', 'short']
panel_json['xaxis'] = self.data.get('xaxis', {'show': True, 'format': 'time'})
self._create_component(panel_json, Yaxes)
return panel_json

Expand Down
7 changes: 7 additions & 0 deletions samples/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
rightMax: 10
leftMin: 0
rightMin: -10
yaxes:
- my-yaxes

- name: memory
panels:
Expand Down Expand Up @@ -208,3 +210,8 @@
title: '{title}'
dashboard: '{dashboard}'
params: '{params}'

- name: my-yaxes
yaxes:
- yaxis:
format: bytes
6 changes: 5 additions & 1 deletion tests/grafana_dashboards/components/graph/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"targets": [],
"title": null,
"type": "graph",
"nullPointMode": "null"
"nullPointMode": "null",
"xaxis": {
"format": "time",
"show": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
"y_formats": [
"short",
"short"
]
],
"xaxis": {
"format": "time",
"show": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
"y_formats": [
"short",
"short"
]
],
"xaxis": {
"format": "time",
"show": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
"y_formats": [
"short",
"short"
]
],
"xaxis": {
"format": "time",
"show": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
"threshold2": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"xaxis": {
"format": "time",
"show": true
}
}
6 changes: 6 additions & 0 deletions tests/grafana_dashboards/components/yaxes/compat.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
"format": "ms",
"logBase": 2,
"min": 1,
"show": true
},
{
"format": "ms",
"logBase": 2,
Expand Down
4 changes: 4 additions & 0 deletions tests/grafana_dashboards/components/yaxes/single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"mocked",
"mocked"
]
2 changes: 2 additions & 0 deletions tests/grafana_dashboards/components/yaxes/single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yaxes:
- yaxis:

0 comments on commit d23081b

Please sign in to comment.