Commit cf87e8ec by hc4 Committed by Torkel Ödegaard

Fix parsing of intervals. defined in ms (#5151)

* Fix parsing of intervals. defined in ms

Fix parsing of intervals. defined in ms.
Increase accuracy for sub-second inrevals.
Closes #5008

* Tests for sub-ms intervals

Unit test for https://github.com/grafana/grafana/commit/2034d4b9710b0cb9fd0cdf14aa9981cd0417eda4
parent a6afd855
......@@ -12,9 +12,21 @@ function($, _) {
kbn.round_interval = function(interval) {
switch (true) {
// 0.3s
case (interval <= 300):
return 100; // 0.1s
// 0.015s
case (interval <= 15):
return 10; // 0.01s
// 0.035s
case (interval <= 35):
return 20; // 0.02s
// 0.075s
case (interval <= 75):
return 50; // 0.05s
// 0.15s
case (interval <= 150):
return 100; // 0.1s
// 0.35s
case (interval <= 350):
return 200; // 0.2s
// 0.75s
case (interval <= 750):
return 500; // 0.5s
......@@ -133,7 +145,7 @@ function($, _) {
return str;
};
kbn.interval_regex = /(\d+(?:\.\d+)?)([Mwdhmsy])/;
kbn.interval_regex = /(\d+(?:\.\d+)?)(ms|[Mwdhmsy])/;
// histogram & trends
kbn.intervals_in_seconds = {
......@@ -143,7 +155,8 @@ function($, _) {
d: 86400,
h: 3600,
m: 60,
s: 1
s: 1,
ms: 0.001
};
kbn.calculateInterval = function(range, resolution, userInterval) {
......
......@@ -147,5 +147,11 @@ define([
var str = kbn.calculateInterval(range, 1000, '>10s');
expect(str).to.be('20m');
});
it('10s 900 resolution and user low limit in ms', function() {
var range = { from: dateMath.parse('now-10s'), to: dateMath.parse('now') };
var str = kbn.calculateInterval(range, 900, '>15ms');
expect(str).to.be('15ms');
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment