Bladeren bron

Graph: Fix for y axis and scaled units (GiB etc) caused rounding, for example 400 GiB instead of 378 GiB, Fixes #1251

Torkel Ödegaard 11 jaren geleden
bovenliggende
commit
fed06ef97d
3 gewijzigde bestanden met toevoegingen van 9 en 1 verwijderingen
  1. 1 0
      CHANGELOG.md
  2. 1 1
      src/app/components/kbn.js
  3. 7 0
      src/test/specs/kbn-format-specs.js

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@
 - [Issue #1126](https://github.com/grafana/grafana/issues/1126). InfluxDB: Support more than 10 series name segments when using alias ``$number`` patterns
 
 **Fixes**
+- [Issue #1251](https://github.com/grafana/grafana/issues/1251). Graph: Fix for y axis and scaled units (GiB etc) caused rounding, for example 400 GiB instead of 378 GiB
 - [Issue #1199](https://github.com/grafana/grafana/issues/1199). Graph: fix for series tooltip when one series is hidden/disabled
 - [Issue #1207](https://github.com/grafana/grafana/issues/1207). Graphite: movingAverage / movingMedian parameter type impovement, now handles int and interval parameter
 

+ 1 - 1
src/app/components/kbn.js

@@ -339,7 +339,7 @@ function($, _, moment) {
       return "";
     }
 
-    var factor = decimals ? Math.pow(10, decimals) : 1;
+    var factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
     var formatted = String(Math.round(value * factor) / factor);
 
     // if exponent return directly

+ 7 - 0
src/test/specs/kbn-format-specs.js

@@ -29,6 +29,13 @@ define([
   describeValueFormat('ns', 25, 1, 0, '25 ns');
   describeValueFormat('ns', 2558, 50, 0, '2.56 µs');
 
+  describe('kbn.toFixed and negative decimals', function() {
+    it('should treat as zero decimals', function() {
+      var str = kbn.toFixed(186.123, -2);
+      expect(str).to.be('186');
+    });
+  });
+
   describe('calculateInterval', function() {
     it('1h 100 resultion', function() {
       var range = { from: kbn.parseDate('now-1h'), to: kbn.parseDate('now') };