From da1279aa5b0d0bea8761762da9ef2065bb009710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 20 Aug 2014 10:50:26 +0200 Subject: [PATCH] Added zindex per series override option, #425 --- src/app/components/timeSeries.js | 2 ++ src/app/directives/grafanaGraph.js | 2 ++ src/app/panels/graph/seriesOverridesCtrl.js | 1 + src/test/specs/grafanaGraph-specs.js | 12 +++++++++++- src/test/specs/timeSeries-specs.js | 8 ++++++-- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/components/timeSeries.js b/src/app/components/timeSeries.js index e49b45e17e4..95a4d3ded34 100644 --- a/src/app/components/timeSeries.js +++ b/src/app/components/timeSeries.js @@ -9,6 +9,7 @@ function (_, kbn) { this.datapoints = opts.datapoints; this.info = opts.info; this.label = opts.info.alias; + this.zindex = 0; } function matchSeriesOverride(aliasOrRegex, seriesAlias) { @@ -45,6 +46,7 @@ function (_, kbn) { if (override.linewidth !== void 0) { this.lines.lineWidth = override.linewidth; } if (override.pointradius !== void 0) { this.points.radius = override.pointradius; } if (override.steppedLine !== void 0) { this.lines.steps = override.steppedLine; } + if (override.zindex !== void 0) { this.zindex = override.zindex; } if (override.yaxis !== void 0) { this.info.yaxis = override.yaxis; } diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 3525e3a98f4..6148c6d2bc4 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -168,6 +168,8 @@ function (angular, $, kbn, moment, _) { addAnnotations(options); configureAxisOptions(data, options); + data = _.sortBy(data, function(series) { return series.zindex; }); + // if legend is to the right delay plot draw a few milliseconds // so the legend width calculation can be done if (shouldDelayDraw(panel)) { diff --git a/src/app/panels/graph/seriesOverridesCtrl.js b/src/app/panels/graph/seriesOverridesCtrl.js index 4616e6ac1f8..cc6b240d474 100644 --- a/src/app/panels/graph/seriesOverridesCtrl.js +++ b/src/app/panels/graph/seriesOverridesCtrl.js @@ -66,6 +66,7 @@ define([ $scope.addOverrideOption('Points Radius', 'pointradius', [1,2,3,4,5]); $scope.addOverrideOption('Stack', 'stack', [true, false]); $scope.addOverrideOption('Y-axis', 'yaxis', [1, 2]); + $scope.addOverrideOption('Z-index', 'zindex', [-1,-2,-3,0,1,2,3]); $scope.updateCurrentOverrides(); }); diff --git a/src/test/specs/grafanaGraph-specs.js b/src/test/specs/grafanaGraph-specs.js index 903bdcc36d1..449d8db4c39 100644 --- a/src/test/specs/grafanaGraph-specs.js +++ b/src/test/specs/grafanaGraph-specs.js @@ -71,7 +71,6 @@ define([ expect(ctx.plotOptions.series.lines.lineWidth).to.be(3); expect(ctx.plotOptions.series.lines.steps).to.be(true); }); - }); graphScenario('series option overrides, fill & points', function(ctx) { @@ -92,6 +91,17 @@ define([ }); }); + graphScenario('should order series order according to zindex', function(ctx) { + ctx.setup(function(scope, data) { + data[0].zindex = 2; + }); + + it('should move zindex 2 last', function() { + expect(ctx.plotData[0].info.alias).to.be('series2'); + expect(ctx.plotData[1].info.alias).to.be('series1'); + }); + }); + }); }); diff --git a/src/test/specs/timeSeries-specs.js b/src/test/specs/timeSeries-specs.js index 6f5fa2a4698..f5fa980c491 100644 --- a/src/test/specs/timeSeries-specs.js +++ b/src/test/specs/timeSeries-specs.js @@ -93,14 +93,18 @@ define([ }); }); - describe('override series y-axis', function() { + describe('override series y-axis, and z-index', function() { beforeEach(function() { series.info.alias = 'test'; - series.applySeriesOverrides([{ alias: 'test', yaxis: 2 }]); + series.applySeriesOverrides([{ alias: 'test', yaxis: 2, zindex: 2 }]); }); it('should set yaxis', function() { expect(series.info.yaxis).to.be(2); + + }); + it('should set zindex', function() { + expect(series.zindex).to.be(2); }); });