Honor custom label in percentile ranks aggregation
This commit is contained in:
parent
950d6e2085
commit
48d040b579
|
@ -0,0 +1,40 @@
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import AggTypeMetricPercentileRanksProvider from 'ui/agg_types/metrics/percentile_ranks';
|
||||
import VisProvider from 'ui/vis';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
|
||||
describe('AggTypeMetricPercentileRanksProvider class', function () {
|
||||
|
||||
let Vis;
|
||||
let indexPattern;
|
||||
let aggTypeMetricPercentileRanks;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
Vis = Private(VisProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
aggTypeMetricPercentileRanks = Private(AggTypeMetricPercentileRanksProvider);
|
||||
}));
|
||||
|
||||
it('uses the custom label if it is set', function () {
|
||||
const vis = new Vis(indexPattern, {});
|
||||
|
||||
// Grab the aggConfig off the vis (we don't actually use the vis for
|
||||
// anything else)
|
||||
const aggConfig = vis.aggs[0];
|
||||
aggConfig.params.customLabel = 'my custom field label';
|
||||
aggConfig.params.values = [ 5000, 10000 ];
|
||||
aggConfig.params.field = {
|
||||
displayName: 'bytes'
|
||||
};
|
||||
|
||||
const responseAggs = aggTypeMetricPercentileRanks.getResponseAggs(aggConfig);
|
||||
const percentileRankLabelFor5kBytes = responseAggs[0].makeLabel();
|
||||
const percentileRankLabelFor10kBytes = responseAggs[1].makeLabel();
|
||||
|
||||
expect(percentileRankLabelFor5kBytes).to.be('Percentile rank 5,000 of "my custom field label"');
|
||||
expect(percentileRankLabelFor10kBytes).to.be('Percentile rank 10,000 of "my custom field label"');
|
||||
});
|
||||
|
||||
});
|
|
@ -17,8 +17,9 @@ export default function AggTypeMetricPercentileRanksProvider(Private) {
|
|||
makeLabel: function () {
|
||||
let field = this.field();
|
||||
let format = (field && field.format) || fieldFormats.getDefaultInstance('number');
|
||||
const label = this.params.customLabel || this.fieldDisplayName();
|
||||
|
||||
return 'Percentile rank ' + format.convert(this.key, 'text') + ' of "' + this.fieldDisplayName() + '"';
|
||||
return 'Percentile rank ' + format.convert(this.key, 'text') + ' of "' + label + '"';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue