Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/ui/public/agg_types/__tests__/metrics/std_deviation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,29 @@ 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');
});

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');
});

});
9 changes: 4 additions & 5 deletions src/ui/public/agg_types/metrics/std_deviation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ 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;

@spalger spalger Apr 24, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be broken into a few lines and use lodash's get function like:

const fieldDisplay = this.fieldDisplayName();
const details = this.keyedDetails(this.param.customLabel, fieldDisplay);
return get(details, [this.key, 'title']);

Since the keyedDetails() function is defined so close by it probably won't matter, but it would make me feel better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about breaking it up too, for better readability. Thanks for nudging me over the fence :)

I'll use lodash's get function but could you educate me as to why that's preferable?

},
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'],
title: 'Lower ' + label
},
avg: {
valProp: 'avg',
title: 'Average'
title: 'Average of ' + fieldDisplayName
},
std_upper: {
valProp: ['std_deviation_bounds', 'upper'],
Expand Down