Skip to content

Commit

Permalink
Honor custom label, if set, in percentile and median metric visualiza…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ycombinator committed Apr 22, 2016
1 parent c579d88 commit 4680853
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/ui/public/agg_types/__tests__/metrics/percentiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import AggTypeMetricPercentilesProvider from 'ui/agg_types/metrics/percentiles';
import VisProvider from 'ui/vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('AggTypeMetricPercentilesProvider class', function () {

let Vis;
let indexPattern;
let aggTypeMetricPercentiles;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
aggTypeMetricPercentiles = Private(AggTypeMetricPercentilesProvider);
}));

it('uses the custom label if it is 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.customLabel = 'prince';
aggConfig.params.percents = [ 95 ];
aggConfig.params.field = {
displayName: 'bytes'
};

let responseAggs = aggTypeMetricPercentiles.getResponseAggs(aggConfig);
let ninetyFifthPercentileLabel = responseAggs[0].makeLabel();

expect(ninetyFifthPercentileLabel).to.be('95th prince of bytes');
});

});
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/percentiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default function AggTypeMetricPercentilesProvider(Private) {

let valueProps = {
makeLabel: function () {
return ordinalSuffix(this.key) + ' percentile of ' + this.fieldDisplayName();
let label = this.params.customLabel || 'percentile';
return ordinalSuffix(this.key) + ' ' + label + ' of ' + this.fieldDisplayName();
}
};

Expand Down

0 comments on commit 4680853

Please sign in to comment.