From e926b01185f63c5934b72b1e605e0b3659323150 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 20 Sep 2016 12:23:31 +0300 Subject: [PATCH] Bug fixes for flexible Y-Min and Y-Max settings (#6066) * fix(flexible_y-min/max): fixed negative values support and added tests for this. * fix(flexible_y-min/max): fixed issue with Y-Min and Y-Max values stored as numbers. Issue: panels with configured Y-Min and Y-Max don't display anything after upgrade. --- public/app/plugins/panel/graph/graph.js | 3 +- .../plugins/panel/graph/specs/graph_specs.ts | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index 69154ffed65..2e7353b6048 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -354,7 +354,8 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholdManExports) { function parseThresholdExpr(expr) { var match, operator, value, precision; - match = expr.match(/\s*([<=>~]*)\W*(\d+(\.\d+)?)/); + expr = String(expr); + match = expr.match(/\s*([<=>~]*)\s*(\-?\d+(\.\d+)?)/); if (match) { operator = match[1]; value = parseFloat(match[2]); diff --git a/public/app/plugins/panel/graph/specs/graph_specs.ts b/public/app/plugins/panel/graph/specs/graph_specs.ts index 10c81b7212d..2065bffb130 100644 --- a/public/app/plugins/panel/graph/specs/graph_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_specs.ts @@ -312,5 +312,52 @@ describe('grafanaGraph', function() { expect(ctx.plotOptions.yaxes[0].max).to.be(0); }); }); + describe('and negative values used', function() { + ctx.setup(function(ctrl, data) { + ctrl.panel.yaxes[0].min = '-10'; + ctrl.panel.yaxes[0].max = '-13.14'; + data[0] = new TimeSeries({ + datapoints: [[120,10],[160,20]], + alias: 'series1', + }); + }); + + it('should set min and max to negative', function() { + expect(ctx.plotOptions.yaxes[0].min).to.be(-10); + expect(ctx.plotOptions.yaxes[0].max).to.be(-13.14); + }); + }); + }); + graphScenario('when using Y-Min and Y-Max settings stored as number', function(ctx) { + describe('and Y-Min is 0 and Y-Max is 100', function() { + ctx.setup(function(ctrl, data) { + ctrl.panel.yaxes[0].min = 0; + ctrl.panel.yaxes[0].max = 100; + data[0] = new TimeSeries({ + datapoints: [[120,10],[160,20]], + alias: 'series1', + }); + }); + + it('should set min to 0 and max to 100', function() { + expect(ctx.plotOptions.yaxes[0].min).to.be(0); + expect(ctx.plotOptions.yaxes[0].max).to.be(100); + }); + }); + describe('and Y-Min is -100 and Y-Max is -10.5', function() { + ctx.setup(function(ctrl, data) { + ctrl.panel.yaxes[0].min = -100; + ctrl.panel.yaxes[0].max = -10.5; + data[0] = new TimeSeries({ + datapoints: [[120,10],[160,20]], + alias: 'series1', + }); + }); + + it('should set min to -100 and max to -10.5', function() { + expect(ctx.plotOptions.yaxes[0].min).to.be(-100); + expect(ctx.plotOptions.yaxes[0].max).to.be(-10.5); + }); + }); }); });