Browse Source

fix crash due to zero or negative data values in graph with log scale

bigbenhur 9 years ago
parent
commit
29b9d17faa
2 changed files with 10 additions and 3 deletions
  1. 6 0
      public/app/core/time_series2.ts
  2. 4 3
      public/app/plugins/panel/graph/graph.js

+ 6 - 0
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) {

+ 4 - 3
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)));