From 29b9d17faa05bf804eb9667810a29ab94d089885 Mon Sep 17 00:00:00 2001 From: bigbenhur Date: Fri, 3 Jun 2016 22:30:38 +0200 Subject: [PATCH] fix crash due to zero or negative data values in graph with log scale --- public/app/core/time_series2.ts | 6 ++++++ public/app/plugins/panel/graph/graph.js | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/public/app/core/time_series2.ts b/public/app/core/time_series2.ts index dfae26fb48b..d01fe1156b3 100644 --- a/public/app/core/time_series2.ts +++ b/public/app/core/time_series2.ts @@ -97,6 +97,7 @@ export default class TimeSeries { this.stats.total = 0; this.stats.max = -Number.MAX_VALUE; this.stats.min = Number.MAX_VALUE; + this.stats.logmin = Number.MAX_VALUE; this.stats.avg = null; this.stats.current = null; this.allIsNull = true; @@ -133,6 +134,11 @@ export default class TimeSeries { if (currentValue < this.stats.min) { this.stats.min = currentValue; } + + if (currentValue < this.stats.logmin && currentValue > 0) { + this.stats.logmin = currentValue; + } + } if (currentValue !== 0) { diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index 8019a51354b..00fec42cd6f 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -386,11 +386,12 @@ function (angular, $, moment, _, kbn, GraphTooltip) { if (max === null || max < series.stats.max) { max = series.stats.max; } - if (min === null || min > series.stats.min) { - min = series.stats.min; + if (min === null || min > series.stats.logmin) { + min = series.stats.logmin; } } } + if (max === null && min === null) { max = Math.pow(axis.logBase,+2); min = Math.pow(axis.logBase,-2); @@ -400,7 +401,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) { min = max*Math.pow(axis.logBase,-4); } - axis.transform = function(v) { return Math.log(v) / Math.log(axis.logBase); }; + axis.transform = function(v) { return (v < Number.MIN_VALUE) ? null : Math.log(v) / Math.log(axis.logBase); }; axis.inverseTransform = function (v) { return Math.pow(axis.logBase,v); }; min = axis.inverseTransform(Math.floor(axis.transform(min)));