Browse Source

Fixes #189, correction to ms axis formater, now formats days correctly

Torkel Ödegaard 11 years ago
parent
commit
305d5c5aa9
3 changed files with 28 additions and 10 deletions
  1. 4 10
      src/app/components/kbn.js
  2. 23 0
      src/test/specs/kbn-format-specs.js
  3. 1 0
      src/test/test-main.js

+ 4 - 10
src/app/components/kbn.js

@@ -597,18 +597,12 @@ function($, _, moment) {
     else if (size < 86400000) {
       return (size / 3600000).toFixed(decimals) + " hour";
     }
-    // Less than one week, devide in days
-    else if (size < 604800000) {
+    // Less than one year, devide in days
+    else if (size < 31536000000) {
       return (size / 86400000).toFixed(decimals) + " day";
     }
-    // Less than one month, devide in weeks
-    else if (size < 2.62974e9) {
-      return (size / 604800000).toFixed(decimals) + " week";
-    }
-    // Less than one year, devide in weeks
-    else if (size < 3.15569e10) {
-      return (size / 2.62974e9).toFixed(decimals) + " year";
-    }
+
+    return (size / 31536000000).toFixed(decimals) + " year";
   };
 
   kbn.microsFormat = function(size, decimals) {

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

@@ -0,0 +1,23 @@
+define([
+  'kbn'
+], function(kbn) {
+
+  describe('millisecond formating', function() {
+
+    it('should translate 4378634603 as 1.67 years', function() {
+      var str = kbn.msFormat(4378634603, 2);
+      expect(str).to.be('50.68 day');
+    });
+
+    it('should translate 3654454 as 1.02 hour', function() {
+      var str = kbn.msFormat(3654454, 2);
+      expect(str).to.be('1.02 hour');
+    });
+
+    it('should translate 365445 as 6.09 min', function() {
+      var str = kbn.msFormat(365445, 2);
+      expect(str).to.be('6.09 min');
+    });
+
+  });
+});

+ 1 - 0
src/test/test-main.js

@@ -115,6 +115,7 @@ require([
     'specs/parser-specs',
     'specs/gfunc-specs',
     'specs/filterSrv-specs',
+    'specs/kbn-format-specs',
   ], function () {
     window.__karma__.start();
   });