Skip to content

Commit c19fafa

Browse files
committed
Improvement to series toggling, CTRL+MouseClick on series name will now hide all others (Closes grafana#350)
1 parent 2b5e974 commit c19fafa

File tree

8 files changed

+97
-17
lines changed

8 files changed

+97
-17
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- Unsaved changes warning feature (Issue #324)
99
- Fixes to filters and "All" option. It now never uses "*" as value, but all options in a {node1, node2, node3} expression (Issue #228, #359)
1010
- Fix for InfluxDB query generation with columns containing dots or dashes (Issue #369, #348) - Thanks to @jbripley
11-
11+
- Improvement to series toggling, CTRL+MouseClick on series name will now hide all others (Issue #350)
1212

1313
# 1.5.3 (2014-04-17)
1414
- Add support for async scripted dashboards (Issue #274)

src/app/directives/grafanaGraph.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ function (angular, $, kbn, moment, _) {
2323
scope.get_data();
2424
});
2525

26-
scope.$on('toggleLegend', function(e, alias) {
27-
if (hiddenData[alias]) {
28-
data.push(hiddenData[alias]);
29-
delete hiddenData[alias];
30-
}
26+
scope.$on('toggleLegend', function(e, series) {
27+
_.each(series, function(serie) {
28+
if (hiddenData[serie.alias]) {
29+
data.push(hiddenData[serie.alias]);
30+
delete hiddenData[serie.alias];
31+
}
32+
});
3133

3234
render_panel();
3335
});

src/app/panels/graphite/legend.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
>
99
</i>
1010
<span class='small histogram-legend-item'>
11-
<a ng-click="toggleSeries(series)" data-unique="1" data-placement="{{series.yaxis === 2 ? 'bottomRight' : 'bottomLeft'}}">
11+
<a ng-click="toggleSeries(series, $event)" data-unique="1" data-placement="{{series.yaxis === 2 ? 'bottomRight' : 'bottomLeft'}}">
1212
{{series.alias}}
1313
</a>
1414
<span ng-if="panel.legend.values">

src/app/panels/graphite/module.js

+43-5
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,53 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
346346
$scope.render();
347347
};
348348

349-
$scope.toggleSeries = function(info) {
350-
if ($scope.hiddenSeries[info.alias]) {
351-
delete $scope.hiddenSeries[info.alias];
349+
$scope.toggleSeries = function(serie, event) {
350+
if ($scope.hiddenSeries[serie.alias]) {
351+
delete $scope.hiddenSeries[serie.alias];
352352
}
353353
else {
354-
$scope.hiddenSeries[info.alias] = true;
354+
$scope.hiddenSeries[serie.alias] = true;
355355
}
356356

357-
$scope.$emit('toggleLegend', info.alias);
357+
if (event.ctrlKey) {
358+
$scope.toggleSeriesExclusiveMode(serie);
359+
}
360+
361+
$scope.$emit('toggleLegend', $scope.legend);
362+
};
363+
364+
$scope.toggleSeriesExclusiveMode = function(serie) {
365+
var hidden = $scope.hiddenSeries;
366+
367+
if (hidden[serie.alias]) {
368+
delete hidden[serie.alias];
369+
}
370+
371+
// check if every other series is hidden
372+
var alreadyExclusive = _.every($scope.legend, function(value) {
373+
if (value.alias === serie.alias) {
374+
return true;
375+
}
376+
377+
return hidden[value.alias];
378+
});
379+
380+
if (alreadyExclusive) {
381+
// remove all hidden series
382+
_.each($scope.legend, function(value) {
383+
delete $scope.hiddenSeries[value.alias];
384+
});
385+
}
386+
else {
387+
// hide all but this serie
388+
_.each($scope.legend, function(value) {
389+
if (value.alias === serie.alias) {
390+
return;
391+
}
392+
393+
$scope.hiddenSeries[value.alias] = true;
394+
});
395+
}
358396
};
359397

360398
$scope.toggleYAxis = function(info) {

src/app/services/dashboard.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
176176

177177
$timeout(function() {
178178
self.original = angular.copy(self.current);
179-
}, 500);
179+
}, 1000);
180180

181181
return true;
182182
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*define([
2+
//'services/all'
3+
], function() {
4+
'use strict';
5+
6+
describe('Graph panel controller', function() {
7+
var _graphPanelCtrl;
8+
9+
beforeEach(module('kibana.panels.graphite'));
10+
beforeEach(module(function($provide){
11+
$provide.value('filterSrv',{});
12+
}));
13+
14+
beforeEach(inject(function($controller, $rootScope) {
15+
_graphPanelCtrl = $controller('graphite', {
16+
$scope: $rootScope.$new()
17+
});
18+
}));
19+
20+
describe('init', function() {
21+
beforeEach(function() {
22+
});
23+
24+
it('asd', function() {
25+
26+
});
27+
});
28+
});
29+
});
30+
*/

src/test/test-main.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ require.config({
1212
'underscore-src': '../vendor/underscore',
1313

1414
moment: '../vendor/moment',
15-
chromath: '../vendor/chromath',
15+
chromath: '../vendor/chromath',
16+
filesaver: '../vendor/filesaver',
1617

1718
angular: '../vendor/angular/angular',
1819
angularMocks: '../vendor/angular/angular-mocks',
@@ -103,18 +104,27 @@ require.config({
103104
require([
104105
'angular',
105106
'angularMocks',
107+
'jquery',
108+
'underscore',
109+
'elasticjs',
110+
'bootstrap',
111+
'angular-sanitize',
112+
'angular-strap',
113+
'angular-dragdrop',
114+
'extend-jquery',
115+
'bindonce'
106116
], function(angular) {
107117
'use strict';
108118

109119
angular.module('kibana', []);
110-
angular.module('kibana.services', []);
120+
angular.module('kibana.services', ['$strap.directives']);
111121

112122
require([
113123
'specs/lexer-specs',
114124
'specs/parser-specs',
115125
'specs/gfunc-specs',
116126
'specs/filterSrv-specs',
117-
'specs/kbn-format-specs',
127+
'specs/kbn-format-specs'
118128
], function () {
119129
window.__karma__.start();
120130
});

tasks/options/karma.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = function(config) {
77
},
88
debug: {
99
configFile: 'src/test/karma.conf.js',
10-
singleRun: true,
10+
singleRun: false,
1111
browsers: ['Chrome']
1212
},
1313
test: {

0 commit comments

Comments
 (0)