Commit 517721ea by Torkel Ödegaard

Merge pull request #4108 from benrubson/issue3982-3

Make auto interval calculation more accurate
parents b56a2c14 2034d4b9
...@@ -12,39 +12,66 @@ function($, _) { ...@@ -12,39 +12,66 @@ function($, _) {
kbn.round_interval = function(interval) { kbn.round_interval = function(interval) {
switch (true) { switch (true) {
// 0.5s // 0.3s
case (interval <= 500): case (interval <= 300):
return 100; // 0.1s return 100; // 0.1s
// 5s // 0.75s
case (interval <= 5000): case (interval <= 750):
return 500; // 0.5s
// 1.5s
case (interval <= 1500):
return 1000; // 1s return 1000; // 1s
// 3.5s
case (interval <= 3500):
return 2000; // 2s
// 7.5s // 7.5s
case (interval <= 7500): case (interval <= 7500):
return 5000; // 5s return 5000; // 5s
// 15s // 12.5s
case (interval <= 15000): case (interval <= 12500):
return 10000; // 10s return 10000; // 10s
// 17.5s
case (interval <= 17500):
return 15000; // 15s
// 25s
case (interval <= 25000):
return 20000; // 20s
// 45s // 45s
case (interval <= 45000): case (interval <= 45000):
return 30000; // 30s return 30000; // 30s
// 3m // 1.5m
case (interval <= 180000): case (interval <= 90000):
return 60000; // 1m return 60000; // 1m
// 9m // 3.5m
case (interval <= 210000):
return 120000; // 2m
// 7.5m
case (interval <= 450000): case (interval <= 450000):
return 300000; // 5m return 300000; // 5m
// 20m // 12.5m
case (interval <= 1200000): case (interval <= 750000):
return 600000; // 10m return 600000; // 10m
// 12.5m
case (interval <= 1050000):
return 900000; // 15m
// 25m
case (interval <= 1500000):
return 1200000; // 20m
// 45m // 45m
case (interval <= 2700000): case (interval <= 2700000):
return 1800000; // 30m return 1800000; // 30m
// 2h // 1.5h
case (interval <= 7200000): case (interval <= 5400000):
return 3600000; // 1h return 3600000; // 1h
// 6h // 2.5h
case (interval <= 21600000): case (interval <= 9000000):
return 7200000; // 2h
// 4.5h
case (interval <= 16200000):
return 10800000; // 3h return 10800000; // 3h
// 9h
case (interval <= 32400000):
return 21600000; // 6h
// 24h // 24h
case (interval <= 86400000): case (interval <= 86400000):
return 43200000; // 12h return 43200000; // 12h
......
...@@ -127,7 +127,7 @@ define([ ...@@ -127,7 +127,7 @@ define([
it('10m 1600 resolution', function() { it('10m 1600 resolution', function() {
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
var str = kbn.calculateInterval(range, 1600, null); var str = kbn.calculateInterval(range, 1600, null);
expect(str).to.be('100ms'); expect(str).to.be('500ms');
}); });
it('fixed user interval', function() { it('fixed user interval', function() {
...@@ -145,7 +145,7 @@ define([ ...@@ -145,7 +145,7 @@ define([
it('large time range and user low limit', function() { it('large time range and user low limit', function() {
var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') }; var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') };
var str = kbn.calculateInterval(range, 1000, '>10s'); var str = kbn.calculateInterval(range, 1000, '>10s');
expect(str).to.be('30m'); expect(str).to.be('20m');
}); });
}); });
}); });
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