From cdcbb872d58fba33d5ccad07c9867c3898e841b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 19 Aug 2014 16:57:33 +0200 Subject: [PATCH] options per series is starting to work nicely --- src/app/directives/grafanaGraph.js | 20 +++++++++++------ src/app/panels/graph/module.js | 1 + src/app/panels/graph/seriesOverridesCtrl.js | 4 +++- src/app/panels/graph/styleEditor.html | 5 ++++- src/test/specs/grafanaGraph-specs.js | 24 ++++++++++++++++++--- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 21d47bcdf63..e4f527bb2f3 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -184,18 +184,26 @@ function (angular, $, kbn, moment, _) { } function applySeriesOverrideOptions(series) { + series.lines = {}; + series.points = {}; + series.bars = {}; + for (var i = 0; i < scope.panel.seriesOverrides.length; i++) { var override = scope.panel.seriesOverrides[i]; - if (override.alias === series.info.alias) { - if (!_.isUndefined(override.fill)) { - series.lines = { - fill: override.fill === 0 ? 0.001 : override.fill/10 - }; - } + if (override.alias !== series.info.alias) { + continue; } + if (override.lines !== void 0) { series.lines.show = override.lines; } + if (override.points !== void 0) { series.points.show = override.points; } + if (override.bars !== void 0) { series.bars.show = override.bars; } + if (override.fill !== void 0) { series.lines.fill = translateFillOption(override.fill); } } } + function translateFillOption(fill) { + return fill === 0 ? 0.001 : fill/10; + } + function shouldDelayDraw(panel) { if (panel.legend.rightSide) { return true; diff --git a/src/app/panels/graph/module.js b/src/app/panels/graph/module.js index 9d2253b0147..b0de8f190c7 100644 --- a/src/app/panels/graph/module.js +++ b/src/app/panels/graph/module.js @@ -352,6 +352,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries) { $scope.removeSeriesOverride = function(override) { $scope.panel.seriesOverrides = _.without($scope.panel.seriesOverrides, override); + $scope.render(); }; panelSrv.init($scope); diff --git a/src/app/panels/graph/seriesOverridesCtrl.js b/src/app/panels/graph/seriesOverridesCtrl.js index ed2e27fdf7c..9f42f3ef75d 100644 --- a/src/app/panels/graph/seriesOverridesCtrl.js +++ b/src/app/panels/graph/seriesOverridesCtrl.js @@ -41,6 +41,7 @@ define([ $scope.removeOverride = function(option) { delete $scope.override[option.propertyName]; $scope.updateCurrentOverrides(); + $scope.render(); }; $scope.updateCurrentOverrides = function() { @@ -59,7 +60,8 @@ define([ $scope.addOverrideOption('Bars', 'bars', [true, false]); $scope.addOverrideOption('Lines', 'lines', [true, false]); $scope.addOverrideOption('Points', 'points', [true, false]); - $scope.addOverrideOption('Line fill', 'fill', [1,2,3,4,5,6,7,8]); + $scope.addOverrideOption('Line fill', 'fill', [0,1,2,3,4,5,6,7,8,9,10]); + $scope.addOverrideOption('Line width', 'linewidth', [0,1,2,3,4,5,6,7,8,9,10]); $scope.updateCurrentOverrides(); }); diff --git a/src/app/panels/graph/styleEditor.html b/src/app/panels/graph/styleEditor.html index 9b0d2b4fbba..ca7ec99180d 100644 --- a/src/app/panels/graph/styleEditor.html +++ b/src/app/panels/graph/styleEditor.html @@ -84,7 +84,10 @@ alias or regex
  • - +
  • diff --git a/src/test/specs/grafanaGraph-specs.js b/src/test/specs/grafanaGraph-specs.js index 63f5055f238..b070c03ec44 100644 --- a/src/test/specs/grafanaGraph-specs.js +++ b/src/test/specs/grafanaGraph-specs.js @@ -74,23 +74,41 @@ define([ }); - graphScenario('series option fill override', function(ctx) { + graphScenario('series option overrides, fill & points', function(ctx) { ctx.setup(function(scope, data) { scope.panel.lines = true; scope.panel.fill = 5; scope.panel.seriesOverrides = [ - { alias: 'test', fill: 0 } + { alias: 'test', fill: 0, points: true } ]; data[1].info.alias = 'test'; }); - it('should match second series and set line fill', function() { + it('should match second series and fill zero, and enable points', function() { expect(ctx.plotOptions.series.lines.fill).to.be(0.5); expect(ctx.plotData[1].lines.fill).to.be(0.001); + expect(ctx.plotData[1].points.show).to.be(true); + }); + }); + + graphScenario('series option overrides, bars, true & lines false', function(ctx) { + ctx.setup(function(scope, data) { + scope.panel.lines = true; + scope.panel.seriesOverrides = [ + { alias: 'test', bars: true, lines: false } + ]; + + data[1].info.alias = 'test'; }); + it('should match second series and disable lines, and enable bars', function() { + expect(ctx.plotOptions.series.lines.show).to.be(true); + expect(ctx.plotData[1].lines.show).to.be(false); + expect(ctx.plotData[1].bars.show).to.be(true); + }); }); + }); });