Commit 2ab19148 by Torkel Ödegaard

Graph: toggle legend on/off from panel menu, #941, no keyboard shortcut yet, but could come

parent d12f4a4a
...@@ -97,7 +97,7 @@ function (angular, $, _) { ...@@ -97,7 +97,7 @@ function (angular, $, _) {
$menu = $(menuTemplate); $menu = $(menuTemplate);
$menu.css('left', menuLeftPos); $menu.css('left', menuLeftPos);
$menu.mouseleave(function() { $menu.mouseleave(function() {
//dismiss(1000); dismiss(1000);
}); });
menuScope = $scope.$new(); menuScope = $scope.$new();
...@@ -111,7 +111,7 @@ function (angular, $, _) { ...@@ -111,7 +111,7 @@ function (angular, $, _) {
$(".panel-container").removeClass('panel-highlight'); $(".panel-container").removeClass('panel-highlight');
$panelContainer.toggleClass('panel-highlight'); $panelContainer.toggleClass('panel-highlight');
//dismiss(2500); dismiss(2500);
}; };
if ($scope.panelMeta.titlePos && $scope.panel.title) { if ($scope.panelMeta.titlePos && $scope.panel.title) {
......
...@@ -37,6 +37,8 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) { ...@@ -37,6 +37,8 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
$scope.panelMeta.addEditorTab('Axes & Grid', 'app/panels/graph/axisEditor.html'); $scope.panelMeta.addEditorTab('Axes & Grid', 'app/panels/graph/axisEditor.html');
$scope.panelMeta.addEditorTab('Display Styles', 'app/panels/graph/styleEditor.html'); $scope.panelMeta.addEditorTab('Display Styles', 'app/panels/graph/styleEditor.html');
$scope.panelMeta.addExtendedMenuItem('Toggle legend', '', 'toggleLegend()');
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
// datasource name, null = default datasource // datasource name, null = default datasource
...@@ -143,14 +145,12 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) { ...@@ -143,14 +145,12 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
$scope.panelMeta.loading = false; $scope.panelMeta.loading = false;
$scope.panelMeta.error = err.message || "Timeseries data request error"; $scope.panelMeta.error = err.message || "Timeseries data request error";
$scope.inspector.error = err; $scope.inspector.error = err;
$scope.legend = [];
$scope.render([]); $scope.render([]);
}); });
}; };
$scope.dataHandler = function(results) { $scope.dataHandler = function(results) {
$scope.panelMeta.loading = false; $scope.panelMeta.loading = false;
$scope.legend = [];
// png renderer returns just a url // png renderer returns just a url
if (_.isString(results)) { if (_.isString(results)) {
...@@ -180,16 +180,9 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) { ...@@ -180,16 +180,9 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
var alias = seriesData.target; var alias = seriesData.target;
var color = $scope.panel.aliasColors[alias] || $rootScope.colors[index]; var color = $scope.panel.aliasColors[alias] || $rootScope.colors[index];
var seriesInfo = {
alias: alias,
color: color,
};
$scope.legend.push(seriesInfo);
var series = new TimeSeries({ var series = new TimeSeries({
datapoints: datapoints, datapoints: datapoints,
info: seriesInfo, info: {alias: alias, color: color},
}); });
if (datapoints && datapoints.length > 0) { if (datapoints && datapoints.length > 0) {
...@@ -288,6 +281,12 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) { ...@@ -288,6 +281,12 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
$scope.render(); $scope.render();
}; };
// Called from panel menu
$scope.toggleLegend = function() {
$scope.panel.legend.show = !$scope.panel.legend.show;
$scope.get_data();
};
panelSrv.init($scope); panelSrv.init($scope);
}); });
......
...@@ -51,8 +51,7 @@ function(angular, $) { ...@@ -51,8 +51,7 @@ function(angular, $) {
}, { inputDisabled: true }); }, { inputDisabled: true });
keyboardManager.bind('ctrl+l', function() { keyboardManager.bind('ctrl+l', function() {
scope.dashboard.hideAllLegends = !scope.dashboard.hideAllLegends; scope.$broadcast('toggle-all-legends');
scope.dashboard.emit_refresh('refresh');
}, { inputDisabled: true }); }, { inputDisabled: true });
keyboardManager.bind('ctrl+h', function() { keyboardManager.bind('ctrl+h', function() {
......
...@@ -35,6 +35,7 @@ function (angular, $, kbn, _, moment) { ...@@ -35,6 +35,7 @@ function (angular, $, kbn, _, moment) {
this.annotations = this._ensureListExist(data.annotations); this.annotations = this._ensureListExist(data.annotations);
this.refresh = data.refresh; this.refresh = data.refresh;
this.version = data.version || 0; this.version = data.version || 0;
this.hideAllLegends = data.hideAllLegends || false;
if (this.nav.length === 0) { if (this.nav.length === 0) {
this.nav.push({ type: 'timepicker' }); this.nav.push({ type: 'timepicker' });
......
...@@ -27,11 +27,6 @@ define([ ...@@ -27,11 +27,6 @@ define([
ctx.scope.$digest(); ctx.scope.$digest();
}); });
it('should build legend model', function() {
expect(ctx.scope.legend[0].alias).to.be('test.cpu1');
expect(ctx.scope.legend[1].alias).to.be('test.cpu2');
});
it('should send time series to render', function() { it('should send time series to render', function() {
var data = ctx.scope.render.getCall(0).args[0]; var data = ctx.scope.render.getCall(0).args[0];
expect(data.length).to.be(2); expect(data.length).to.be(2);
...@@ -44,10 +39,6 @@ define([ ...@@ -44,10 +39,6 @@ define([
ctx.scope.$digest(); ctx.scope.$digest();
}); });
it('should clear the legend data', function() {
expect(ctx.scope.legend).to.eql([]);
});
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment