Skip to content

Commit 0015f81

Browse files
committed
Implementation of legend values (min, max, current, total, avg), Closes grafana#60, Fixes grafana#14
1 parent ed76335 commit 0015f81

File tree

5 files changed

+71
-12
lines changed

5 files changed

+71
-12
lines changed

src/app/directives/grafanaGraph.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ function (angular, $, kbn, moment, _) {
260260
return "%Y-%m";
261261
}
262262
if(_int >= 10000) {
263-
return "%Y-%m-%d";
263+
return "%m/%d";
264264
}
265265
if(_int >= 3600) {
266-
return "%m/%d %H:%M" //"%H:%M<br>%m-%d";
266+
return "%m/%d %H:%M";
267267
}
268268
if(_int >= 700) {
269-
return "%a %H:%M" //"%H:%M<br>%m-%d";
269+
return "%a %H:%M";
270270
}
271271

272272
return "%H:%M";

src/app/panels/graphite/axisEditor.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,35 @@ <h5>Grid</h5>
4848
<div class="section">
4949
<h5>Legend</h5>
5050
<div class="editor-option">
51-
<label class="small">Legend</label><input type="checkbox" ng-model="panel.legend" ng-checked="panel.legend" ng-change="render();">
51+
<label class="small">Show Legend</label><input type="checkbox" ng-model="panel.legend.show" ng-checked="panel.legend.show" ng-change="render();">
5252
</div>
53+
<div class="editor-option">
54+
<label class="small">Include Values</label><input type="checkbox" ng-model="panel.legend.values" ng-checked="panel.legend.values" ng-change="render();">
55+
</div>
56+
</div>
57+
58+
<div class="section" ng-if="panel.legend.values">
59+
<h5>Legend values</h5>
60+
<div class="editor-option">
61+
<label class="small">Min</label><input type="checkbox" ng-model="panel.legend.min" ng-checked="panel.legend.min" ng-change="render();">
62+
</div>
63+
64+
<div class="editor-option">
65+
<label class="small">Max</label><input type="checkbox" ng-model="panel.legend.max" ng-checked="panel.legend.max" ng-change="render();">
66+
</div>
67+
68+
<div class="editor-option">
69+
<label class="small">Current</label><input type="checkbox" ng-model="panel.legend.current" ng-checked="panel.legend.current" ng-change="render();">
70+
</div>
71+
72+
<div class="editor-option">
73+
<label class="small">Total</label><input type="checkbox" ng-model="panel.legend.total" ng-checked="panel.legend.total" ng-change="render();">
74+
</div>
75+
76+
<div class="editor-option">
77+
<label class="small">Avg</label><input type="checkbox" ng-model="panel.legend.avg" ng-checked="panel.legend.avg" ng-change="render();">
78+
</div>
79+
5380
</div>
5481

5582
</div>

src/app/panels/graphite/legend.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<span ng-show="panel.legend"
1+
<span ng-show="panel.legend.show"
22
ng-class="{'pull-right': series.yaxis === 2, 'hidden-series': hiddenSeries[series.alias]}"
33
ng-repeat='series in legend'
44
class="histogram-legend">
@@ -9,8 +9,25 @@
99
</i>
1010
<span class='small histogram-legend-item'>
1111
<a ng-click="toggleSeries(series)" data-unique="1" data-placement="{{series.yaxis === 2 ? 'bottomRight' : 'bottomLeft'}}">
12-
{{series.alias}} [max: {{series.max}}, min: {{series.min}}, total: {{series.total}}, avg: {{series.avg}}, current: {{series.current}}]
12+
{{series.alias}}
1313
</a>
14+
<span ng-if="panel.legend.values">
15+
<span ng-show="panel.legend.current">
16+
&nbsp;&nbsp;Current: {{series.current}}&nbsp;
17+
</span>
18+
<span ng-show="panel.legend.min">
19+
&nbsp;&nbsp;Min: {{series.min}}&nbsp;
20+
</span>
21+
<span ng-show="panel.legend.max">
22+
&nbsp;&nbsp;Max: {{series.max}}&nbsp;
23+
</span>
24+
<span ng-show="panel.legend.total">
25+
&nbsp;&nbsp;Total: {{series.total}}&nbsp;
26+
</span>
27+
<span ng-show="panel.legend.avg">
28+
&nbsp;&nbsp;Avg: {{series.avg}}&nbsp;
29+
</span>
30+
</span>
1431
</span>
1532
</span>
1633

src/app/panels/graphite/module.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,15 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
153153
/** @scratch /panels/histogram/3
154154
* legend:: Display the legond
155155
*/
156-
legend : true,
156+
legend: {
157+
show: true, // disable/enable legend
158+
values: false, // disable/enable legend values
159+
min: false,
160+
max: false,
161+
current: false,
162+
total: false,
163+
avg: false
164+
},
157165
/** @scratch /panels/histogram/3
158166
* ==== Transformations
159167
/** @scratch /panels/histogram/3
@@ -182,11 +190,16 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
182190
};
183191

184192
_.defaults($scope.panel,_d);
185-
_.defaults($scope.panel.tooltip,_d.tooltip);
186-
_.defaults($scope.panel.annotate,_d.annotate);
187-
_.defaults($scope.panel.grid,_d.grid);
193+
_.defaults($scope.panel.tooltip, _d.tooltip);
194+
_.defaults($scope.panel.annotate, _d.annotate);
195+
_.defaults($scope.panel.grid, _d.grid);
188196

189197
// backward compatible stuff
198+
if (_.isBoolean($scope.panel.legend)) {
199+
$scope.panel.legend = { show: $scope.panel.legend };
200+
_.defaults($scope.panel.legend, _d.legend);
201+
}
202+
190203
if ($scope.panel.y_format) {
191204
$scope.panel.y_formats[0] = $scope.panel.y_format;
192205
delete $scope.panel.y_format;

src/app/panels/graphite/timeSeries.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ function (_) {
4848
result.push([currentTime * 1000, currentValue]);
4949
}, this);
5050

51-
this.info.avg = this.info.total / result.length;
52-
this.info.current = result[result.length-1][1];
51+
if (result.length) {
52+
this.info.avg = (this.info.total / result.length).toFixed(2);
53+
this.info.current = result[result.length-1][1];
54+
}
5355

5456
return result;
5557
};

0 commit comments

Comments
 (0)