From 450dd14d1ce4ea3b9422124d3ea17abf01bbba81 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 22 Apr 2016 17:47:37 -0700 Subject: [PATCH 1/3] Using the custom label correct, as specified by requirements --- .../public/agg_types/__tests__/metrics/std_deviation.js | 4 ++-- src/ui/public/agg_types/metrics/std_deviation.js | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ui/public/agg_types/__tests__/metrics/std_deviation.js b/src/ui/public/agg_types/__tests__/metrics/std_deviation.js index 96deddcf3b670..7c5fc67882e9a 100644 --- a/src/ui/public/agg_types/__tests__/metrics/std_deviation.js +++ b/src/ui/public/agg_types/__tests__/metrics/std_deviation.js @@ -33,9 +33,9 @@ describe('AggTypeMetricStandardDeviationProvider class', function () { let avgLabel = responseAggs[1].makeLabel(); let upperStdDevLabel = responseAggs[2].makeLabel(); - expect(lowerStdDevLabel).to.be('Lower custom label of memory'); + expect(lowerStdDevLabel).to.be('Lower custom label'); expect(avgLabel).to.be('Average of memory'); // not expected to use custom label - expect(upperStdDevLabel).to.be('Upper custom label of memory'); + expect(upperStdDevLabel).to.be('Upper custom label'); }); }); diff --git a/src/ui/public/agg_types/metrics/std_deviation.js b/src/ui/public/agg_types/metrics/std_deviation.js index 36340ee4fbc6b..c01318dd356b0 100644 --- a/src/ui/public/agg_types/metrics/std_deviation.js +++ b/src/ui/public/agg_types/metrics/std_deviation.js @@ -11,11 +11,10 @@ export default function AggTypeMetricStandardDeviationProvider(Private) { return details.valProp; }, makeLabel: function () { - let details = this.keyedDetails(this.params.customLabel)[this.key]; - return details.title + ' of ' + this.fieldDisplayName(); + return this.keyedDetails(this.params.customLabel, this.fieldDisplayName())[this.key].title; }, - keyedDetails: function (customLabel) { - const label = customLabel ? customLabel : 'Standard Deviation'; + keyedDetails: function (customLabel, fieldDisplayName) { + const label = customLabel ? customLabel : 'Standard Deviation of ' + fieldDisplayName; return { std_lower: { valProp: ['std_deviation_bounds', 'lower'], @@ -23,7 +22,7 @@ export default function AggTypeMetricStandardDeviationProvider(Private) { }, avg: { valProp: 'avg', - title: 'Average' + title: 'Average of ' + fieldDisplayName }, std_upper: { valProp: ['std_deviation_bounds', 'upper'], From dcbc5ca99ab30c042e061b54ac2003903bb0bd49 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 22 Apr 2016 17:48:06 -0700 Subject: [PATCH 2/3] Adding a unit test for when custom label is NOT set --- .../__tests__/metrics/std_deviation.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ui/public/agg_types/__tests__/metrics/std_deviation.js b/src/ui/public/agg_types/__tests__/metrics/std_deviation.js index 7c5fc67882e9a..c16d9691e9744 100644 --- a/src/ui/public/agg_types/__tests__/metrics/std_deviation.js +++ b/src/ui/public/agg_types/__tests__/metrics/std_deviation.js @@ -38,4 +38,24 @@ describe('AggTypeMetricStandardDeviationProvider class', function () { expect(upperStdDevLabel).to.be('Upper custom label'); }); + it('uses the default labels if custom label is not set', function () { + let vis = new Vis(indexPattern, {}); + + // Grab the aggConfig off the vis (we don't actually use the vis for + // anything else) + let aggConfig = vis.aggs[0]; + aggConfig.params.field = { + displayName: 'memory' + }; + + let responseAggs = aggTypeMetricStandardDeviation.getResponseAggs(aggConfig); + let lowerStdDevLabel = responseAggs[0].makeLabel(); + let avgLabel = responseAggs[1].makeLabel(); + let upperStdDevLabel = responseAggs[2].makeLabel(); + + expect(lowerStdDevLabel).to.be('Lower Standard Deviation of memory'); + expect(avgLabel).to.be('Average of memory'); // not expected to use custom label + expect(upperStdDevLabel).to.be('Upper Standard Deviation of memory'); + }); + }); From 3532d1a25a1f8a34efd47ac35c7c3b8ea38b031e Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sun, 24 Apr 2016 17:28:11 -0700 Subject: [PATCH 3/3] Breaking up the code for more readability + using _.get --- src/ui/public/agg_types/metrics/std_deviation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ui/public/agg_types/metrics/std_deviation.js b/src/ui/public/agg_types/metrics/std_deviation.js index c01318dd356b0..9982dd65a9a3c 100644 --- a/src/ui/public/agg_types/metrics/std_deviation.js +++ b/src/ui/public/agg_types/metrics/std_deviation.js @@ -11,7 +11,9 @@ export default function AggTypeMetricStandardDeviationProvider(Private) { return details.valProp; }, makeLabel: function () { - return this.keyedDetails(this.params.customLabel, this.fieldDisplayName())[this.key].title; + const fieldDisplayName = this.fieldDisplayName(); + const details = this.keyedDetails(this.params.customLabel, fieldDisplayName); + return _.get(details, [this.key, 'title']); }, keyedDetails: function (customLabel, fieldDisplayName) { const label = customLabel ? customLabel : 'Standard Deviation of ' + fieldDisplayName;