diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index d6b05b578fa..c1236cf50b4 100644 --- a/src/app/components/kbn.js +++ b/src/app/components/kbn.js @@ -574,6 +574,10 @@ function($, _, moment) { return function(val) { return kbn.microsFormat(val, decimals); }; + case 'ns': + return function(val) { + return kbn.nanosFormat(val, decimals); + }; default: return function(val) { return val % 1 === 0 ? val : val.toFixed(decimals); @@ -617,5 +621,23 @@ function($, _, moment) { } }; + kbn.nanosFormat = function(size, decimals) { + if (size < 1000) { + return size.toFixed(0) + " ns"; + } + else if (size < 1000000) { + return (size / 1000).toFixed(decimals) + " µs"; + } + else if (size < 1000000000) { + return (size / 1000000).toFixed(decimals) + " ms"; + } + else if (size < 60000000000){ + return (size / 1000000000).toFixed(decimals) + " s"; + } + else { + return (size / 60000000000).toFixed(decimals) + " m"; + } + }; + return kbn; }); diff --git a/src/app/panels/graphite/axisEditor.html b/src/app/panels/graphite/axisEditor.html index 1a91fe6bcb2..fa17c76b7a9 100644 --- a/src/app/panels/graphite/axisEditor.html +++ b/src/app/panels/graphite/axisEditor.html @@ -10,11 +10,11 @@
- +
- +
diff --git a/src/test/specs/kbn-format-specs.js b/src/test/specs/kbn-format-specs.js index cd1a68ad602..0fcc0180f49 100644 --- a/src/test/specs/kbn-format-specs.js +++ b/src/test/specs/kbn-format-specs.js @@ -21,4 +21,33 @@ define([ }); }); + + describe('nanosecond formatting', function () { + + it('should translate 25 to 25 ns', function () { + var str = kbn.nanosFormat(25, 2); + expect(str).to.be("25 ns"); + }); + + it('should translate 2558 to 2.56 µs', function () { + var str = kbn.nanosFormat(2558, 2); + expect(str).to.be("2.56 µs"); + }); + + it('should translate 2558000 to 2.56 ms', function () { + var str = kbn.nanosFormat(2558000, 2); + expect(str).to.be("2.56 ms"); + }); + + it('should translate 2019962000 to 2.02 s', function () { + var str = kbn.nanosFormat(2049962000, 2); + expect(str).to.be("2.05 s"); + }); + + it('should translate 95199620000 to 1.59 m', function () { + var str = kbn.nanosFormat(95199620000, 2); + expect(str).to.be("1.59 m"); + }); + + }); });