Skip to content

Commit

Permalink
Merge pull request #7021 from ycombinator/gh-6246
Browse files Browse the repository at this point in the history
Honor custom label, if set, in percentile and median metric visualizations
  • Loading branch information
ycombinator committed Apr 28, 2016
2 parents 4ff67e0 + 7534b38 commit a63015d
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 () {
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 = 'prince';
aggConfig.params.percents = [ 95 ];
aggConfig.params.field = {
displayName: 'bytes'
};

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

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

});
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();
const label = this.params.customLabel || this.fieldDisplayName();
return ordinalSuffix(this.key) + ' percentile of ' + label;
}
};

Expand Down

0 comments on commit a63015d

Please sign in to comment.