Просмотр исходного кода

Graph: fix for legend values min & max, avg & current when series only has null values, Closes #923

Torkel Ödegaard 11 лет назад
Родитель
Сommit
c74eda20dc
3 измененных файлов с 15 добавлено и 4 удалено
  1. 3 0
      CHANGELOG.md
  2. 9 4
      src/app/components/timeSeries.js
  3. 3 0
      src/app/directives/grafanaGraph.js

+ 3 - 0
CHANGELOG.md

@@ -6,6 +6,9 @@
 - [Issue #877](https://github.com/grafana/grafana/issues/877). Graph: Smart auto decimal precision when using scaled unit formats
 - [Issue #877](https://github.com/grafana/grafana/issues/877). Graph: Smart auto decimal precision when using scaled unit formats
 - [Issue #850](https://github.com/grafana/grafana/issues/850). Graph: Shared tooltip that shows multiple series & crosshair line, thx @toni-moreno
 - [Issue #850](https://github.com/grafana/grafana/issues/850). Graph: Shared tooltip that shows multiple series & crosshair line, thx @toni-moreno
 
 
+**Fixes**
+- [Issue #925](https://github.com/grafana/grafana/issues/925). Graph: bar width calculation fix for some edge cases (bars would render on top of each other)
+
 =======
 =======
 # 1.8.1 (2014-09-30)
 # 1.8.1 (2014-09-30)
 
 

+ 9 - 4
src/app/components/timeSeries.js

@@ -63,8 +63,10 @@ function (_, kbn) {
     this.yaxis = this.info.yaxis;
     this.yaxis = this.info.yaxis;
 
 
     this.stats.total = 0;
     this.stats.total = 0;
-    this.stats.max = -212312321312;
-    this.stats.min = 212312321312;
+    this.stats.max = Number.MIN_VALUE;
+    this.stats.min = Number.MAX_VALUE;
+    this.stats.avg = null;
+    this.stats.current = null;
 
 
     var ignoreNulls = fillStyle === 'connected';
     var ignoreNulls = fillStyle === 'connected';
     var nullAsZero = fillStyle === 'null as zero';
     var nullAsZero = fillStyle === 'null as zero';
@@ -97,10 +99,13 @@ function (_, kbn) {
       result.push([currentTime * 1000, currentValue]);
       result.push([currentTime * 1000, currentValue]);
     }
     }
 
 
-    if (result.length >= 2) {
-      this.stats.timeStep = result[1][0] - result[0][0];
+    if (this.datapoints.length >= 2) {
+      this.stats.timeStep = (this.datapoints[1][1] - this.datapoints[0][1]) * 1000;
     }
     }
 
 
+    if (this.stats.max === Number.MIN_VALUE) { this.stats.max = null; }
+    if (this.stats.min === Number.MAX_VALUE) { this.stats.min = null; }
+
     if (result.length) {
     if (result.length) {
       this.stats.avg = (this.stats.total / result.length);
       this.stats.avg = (this.stats.total / result.length);
       this.stats.current = result[result.length-1][1];
       this.stats.current = result[result.length-1][1];

+ 3 - 0
src/app/directives/grafanaGraph.js

@@ -185,7 +185,10 @@ function (angular, $, kbn, moment, _, GraphTooltip) {
           }
           }
 
 
           if (data.length && data[0].stats.timeStep) {
           if (data.length && data[0].stats.timeStep) {
+            console.log('timeStep', data[0].stats.timeStep);
+            console.log('timeStep2', data[1].stats.timeStep);
             options.series.bars.barWidth = data[0].stats.timeStep / 1.5;
             options.series.bars.barWidth = data[0].stats.timeStep / 1.5;
+            console.log('barWidth', data[1].stats.timeStep);
           }
           }
 
 
           addTimeAxis(options);
           addTimeAxis(options);