From c5b39a5100fda8efb2671236493d64158163ad1f Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Thu, 12 Nov 2015 09:56:46 -0800 Subject: [PATCH 1/7] Added currency units --- public/app/core/utils/kbn.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/app/core/utils/kbn.js b/public/app/core/utils/kbn.js index 1d60ba48fd6..a9e8d219ce6 100644 --- a/public/app/core/utils/kbn.js +++ b/public/app/core/utils/kbn.js @@ -341,6 +341,8 @@ function($, _) { // Currencies kbn.valueFormats.currencyUSD = kbn.formatBuilders.currency('$'); kbn.valueFormats.currencyGBP = kbn.formatBuilders.currency('£'); + kbn.valueFormats.currencyEUR = kbn.formatBuilders.currency('€'); + kbn.valueFormats.currencyJPY = kbn.formatBuilders.currency('¥'); // Data kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b'); @@ -508,6 +510,8 @@ function($, _) { submenu: [ {text: 'Dollars ($)', value: 'currencyUSD'}, {text: 'Pounds (£)', value: 'currencyGBP'}, + {text: 'Euro (€)', value: 'currencyEUR'}, + {text: 'Yen (¥)', value: 'currencyJPY'}, ] }, { From 3c54d14460f7356188718714a872337773f212ba Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Thu, 12 Nov 2015 20:26:59 -0800 Subject: [PATCH 2/7] Added UI for time units, minute scalability --- public/app/core/utils/kbn.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/public/app/core/utils/kbn.js b/public/app/core/utils/kbn.js index a9e8d219ce6..70487fe46e4 100644 --- a/public/app/core/utils/kbn.js +++ b/public/app/core/utils/kbn.js @@ -489,6 +489,26 @@ function($, _) { } }; + kbn.valueFormats.m = function(size, decimals, scaledDecimals) { + if (size === null) { return ""; } + + if (Math.abs(size) < 60) { + return kbn.toFixed(size, decimals) + " min"; + } + else if (Math.abs(size) < 1440) { + return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 2, " hour"); + } + else if (Math.abs(size) < 10080) { + return kbn.toFixedScaled(size / 1440, decimals, scaledDecimals, 3, " day"); + } + else if (Math.abs(size) < 604800) { + return kbn.toFixedScaled(size / 86400, decimals, scaledDecimals, 4, " week"); + } + else { + return kbn.toFixedScaled(size / 5.25948e5, decimals, scaledDecimals, 5, " year"); + } + }; + ///// FORMAT MENU ///// kbn.getUnitFormats = function() { @@ -522,6 +542,9 @@ function($, _) { {text: 'microseconds (µs)', value: 'µs' }, {text: 'milliseconds (ms)', value: 'ms' }, {text: 'seconds (s)', value: 's' }, + {text: 'minutes (m)', value: 'm' }, + {text: 'hours (h)', value: 'h' }, + {text: 'days (d)', value: 'd' }, ] }, { From 7f9c8a19357017c427fae258642108c746ed01f6 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Thu, 12 Nov 2015 23:56:24 -0800 Subject: [PATCH 3/7] Added hours, days units and tests for all --- public/app/core/utils/kbn.js | 35 +++++++++++++++++++++++++++-- public/test/core/utils/kbn_specs.js | 21 +++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/public/app/core/utils/kbn.js b/public/app/core/utils/kbn.js index 70487fe46e4..123e8e16be1 100644 --- a/public/app/core/utils/kbn.js +++ b/public/app/core/utils/kbn.js @@ -432,7 +432,7 @@ function($, _) { kbn.valueFormats.s = function(size, decimals, scaledDecimals) { if (size === null) { return ""; } - if (Math.abs(size) < 600) { + if (Math.abs(size) < 60) { return kbn.toFixed(size, decimals) + " s"; } // Less than 1 hour, devide in minutes @@ -502,13 +502,44 @@ function($, _) { return kbn.toFixedScaled(size / 1440, decimals, scaledDecimals, 3, " day"); } else if (Math.abs(size) < 604800) { - return kbn.toFixedScaled(size / 86400, decimals, scaledDecimals, 4, " week"); + return kbn.toFixedScaled(size / 10080, decimals, scaledDecimals, 4, " week"); } else { return kbn.toFixedScaled(size / 5.25948e5, decimals, scaledDecimals, 5, " year"); } }; + kbn.valueFormats.h = function(size, decimals, scaledDecimals) { + if (size === null) { return ""; } + + if (Math.abs(size) < 24) { + return kbn.toFixed(size, decimals) + " hour"; + } + else if (Math.abs(size) < 168) { + return kbn.toFixedScaled(size / 24, decimals, scaledDecimals, 2, " day"); + } + else if (Math.abs(size) < 8760) { + return kbn.toFixedScaled(size / 168, decimals, scaledDecimals, 3, " week"); + } + else { + return kbn.toFixedScaled(size / 8760, decimals, scaledDecimals, 4, " year"); + } + }; + + kbn.valueFormats.d = function(size, decimals, scaledDecimals) { + if (size === null) { return ""; } + + if (Math.abs(size) < 7) { + return kbn.toFixed(size, decimals) + " day"; + } + else if (Math.abs(size) < 365) { + return kbn.toFixedScaled(size / 7, decimals, scaledDecimals, 2, " week"); + } + else { + return kbn.toFixedScaled(size / 365, decimals, scaledDecimals, 3, " year"); + } + }; + ///// FORMAT MENU ///// kbn.getUnitFormats = function() { diff --git a/public/test/core/utils/kbn_specs.js b/public/test/core/utils/kbn_specs.js index 2253f4d8ecd..23c752fe471 100644 --- a/public/test/core/utils/kbn_specs.js +++ b/public/test/core/utils/kbn_specs.js @@ -68,6 +68,27 @@ define([ describeValueFormat('wps', 789000000, 1000000, -1, '789M wps'); describeValueFormat('iops', 11000000000, 1000000000, -1, '11B iops'); + describeValueFormat('s', 24, 1, 0, '24 s'); + describeValueFormat('s', 246, 1, 0, '4.1 min'); + describeValueFormat('s', 24567, 100, 0, '6.82 hour'); + describeValueFormat('s', 24567890, 10000, 0, '40.62 week'); + describeValueFormat('s', 24567890000, 1000000, 0, '778.53 year'); + + describeValueFormat('m', 24, 1, 0, '24 min'); + describeValueFormat('m', 246, 10, 0, '4.1 hour'); + describeValueFormat('m', 6545, 10, 0, '4.55 day'); + describeValueFormat('m', 24567, 100, 0, '2.44 week'); + describeValueFormat('m', 24567892, 10000, 0, '46.7 year'); + + describeValueFormat('h', 21, 1, 0, '21 hour'); + describeValueFormat('h', 145, 1, 0, '6.04 day'); + describeValueFormat('h', 1234, 100, 0, '7.3 week'); + describeValueFormat('h', 9458, 1000, 0, '1.08 year'); + + describeValueFormat('d', 3, 1, 0, '3 day'); + describeValueFormat('d', 245, 100, 0, '35 week'); + describeValueFormat('d', 2456, 10, 0, '6.73 year'); + describe('kbn.toFixed and negative decimals', function() { it('should treat as zero decimals', function() { var str = kbn.toFixed(186.123, -2); From 0ff5ff5dbe8ebc492385f6b49ce355d29daa29f1 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 25 Nov 2015 04:05:40 -0800 Subject: [PATCH 4/7] Enabled refresh interval for absolute time range --- public/app/features/dashboard/timeSrv.js | 7 +------ public/test/specs/time_srv_specs.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/public/app/features/dashboard/timeSrv.js b/public/app/features/dashboard/timeSrv.js index e0e0ed47dab..1aff02bea90 100644 --- a/public/app/features/dashboard/timeSrv.js +++ b/public/app/features/dashboard/timeSrv.js @@ -93,12 +93,7 @@ define([ this.setTime = function(time) { _.extend(this.time, time); - // disable refresh if we have an absolute time - if (moment.isMoment(time.to)) { - this.old_refresh = this.dashboard.refresh || this.old_refresh; - this.setAutoRefresh(false); - } - else if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { + if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { this.setAutoRefresh(this.old_refresh); this.old_refresh = null; } diff --git a/public/test/specs/time_srv_specs.js b/public/test/specs/time_srv_specs.js index 4f065af6cf8..8c110483b47 100644 --- a/public/test/specs/time_srv_specs.js +++ b/public/test/specs/time_srv_specs.js @@ -78,17 +78,24 @@ define([ }); describe('setTime', function() { - it('should return disable refresh for absolute times', function() { + it('should return disable refresh if refresh is disabled for any range', function() { _dashboard.refresh = false; ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); expect(_dashboard.refresh).to.be(false); }); + it('should restore refresh for absolute time range', function() { + _dashboard.refresh = '30s'; + + ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); + expect(_dashboard.refresh).to.be('30s'); + }); + it('should restore refresh after relative time range is set', function() { _dashboard.refresh = '10s'; ctx.service.setTime({from: moment([2011,1,1]), to: moment([2015,1,1])}); - expect(_dashboard.refresh).to.be(false); + expect(_dashboard.refresh).to.be('10s'); ctx.service.setTime({from: '2011-01-01', to: 'now' }); expect(_dashboard.refresh).to.be('10s'); }); From 712a420217f48d13908ed2b571b419031be7c3f1 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 29 Nov 2015 03:12:48 -0800 Subject: [PATCH 5/7] Fixed refresh setting for absolute time --- public/app/features/dashboard/timeSrv.js | 9 +++++++-- public/app/features/dashboard/timepicker/timepicker.ts | 2 +- public/test/specs/time_srv_specs.js | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/timeSrv.js b/public/app/features/dashboard/timeSrv.js index 1aff02bea90..691bfd07904 100644 --- a/public/app/features/dashboard/timeSrv.js +++ b/public/app/features/dashboard/timeSrv.js @@ -90,10 +90,15 @@ define([ timer.cancel(this.refresh_timer); }; - this.setTime = function(time) { + this.setTime = function(time, enableRefresh) { _.extend(this.time, time); - if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { + // disable refresh if zoom in or zoom out + if (!enableRefresh && moment.isMoment(time.to)) { + this.old_refresh = this.dashboard.refresh || this.old_refresh; + this.setAutoRefresh(false); + } + else if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { this.setAutoRefresh(this.old_refresh); this.old_refresh = null; } diff --git a/public/app/features/dashboard/timepicker/timepicker.ts b/public/app/features/dashboard/timepicker/timepicker.ts index c6d2680ce02..0f99210f3fa 100644 --- a/public/app/features/dashboard/timepicker/timepicker.ts +++ b/public/app/features/dashboard/timepicker/timepicker.ts @@ -115,7 +115,7 @@ export class TimePickerCtrl { this.timeSrv.setAutoRefresh(this.refresh.value); } - this.timeSrv.setTime(this.timeRaw); + this.timeSrv.setTime(this.timeRaw, true); this.$rootScope.appEvent('hide-dash-editor'); } diff --git a/public/test/specs/time_srv_specs.js b/public/test/specs/time_srv_specs.js index 8c110483b47..d645df3fd1e 100644 --- a/public/test/specs/time_srv_specs.js +++ b/public/test/specs/time_srv_specs.js @@ -92,10 +92,17 @@ define([ expect(_dashboard.refresh).to.be('30s'); }); + it('should restore refresh for absolute time range', function() { + _dashboard.refresh = '30s'; + + ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); + expect(_dashboard.refresh).to.be('30s'); + }); + it('should restore refresh after relative time range is set', function() { _dashboard.refresh = '10s'; ctx.service.setTime({from: moment([2011,1,1]), to: moment([2015,1,1])}); - expect(_dashboard.refresh).to.be('10s'); + expect(_dashboard.refresh).to.be(false); ctx.service.setTime({from: '2011-01-01', to: 'now' }); expect(_dashboard.refresh).to.be('10s'); }); From 8cdaa044e1eda21afa34f47caa18503d6a590e0d Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 29 Nov 2015 03:14:26 -0800 Subject: [PATCH 6/7] Removed repeating test --- public/test/specs/time_srv_specs.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/public/test/specs/time_srv_specs.js b/public/test/specs/time_srv_specs.js index d645df3fd1e..9943aae6cc3 100644 --- a/public/test/specs/time_srv_specs.js +++ b/public/test/specs/time_srv_specs.js @@ -92,13 +92,6 @@ define([ expect(_dashboard.refresh).to.be('30s'); }); - it('should restore refresh for absolute time range', function() { - _dashboard.refresh = '30s'; - - ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); - expect(_dashboard.refresh).to.be('30s'); - }); - it('should restore refresh after relative time range is set', function() { _dashboard.refresh = '10s'; ctx.service.setTime({from: moment([2011,1,1]), to: moment([2015,1,1])}); From 85ec70e92b2101f735a1045832e93f4e3dd19e74 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Mon, 30 Nov 2015 15:55:07 +0900 Subject: [PATCH 7/7] Use of `` seems to confuse angular so changing to DIMENSION_NAME --- .../plugins/datasource/cloudwatch/partials/query.editor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/cloudwatch/partials/query.editor.html b/public/app/plugins/datasource/cloudwatch/partials/query.editor.html index d05ffd8547f..0984bc521e2 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/query.editor.html +++ b/public/app/plugins/datasource/cloudwatch/partials/query.editor.html @@ -73,7 +73,7 @@