From 468085324fe5f4230cc9a682e1110965cd5dda8b Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 21 Apr 2016 19:15:31 -0700 Subject: [PATCH] Honor custom label, if set, in percentile and median metric visualizations --- .../__tests__/metrics/percentiles.js | 38 +++++++++++++++++++ .../public/agg_types/metrics/percentiles.js | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/ui/public/agg_types/__tests__/metrics/percentiles.js diff --git a/src/ui/public/agg_types/__tests__/metrics/percentiles.js b/src/ui/public/agg_types/__tests__/metrics/percentiles.js new file mode 100644 index 0000000000000..0745f08f1bdf0 --- /dev/null +++ b/src/ui/public/agg_types/__tests__/metrics/percentiles.js @@ -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'); + }); + +}); diff --git a/src/ui/public/agg_types/metrics/percentiles.js b/src/ui/public/agg_types/metrics/percentiles.js index d14401143e7c0..e9f0ea142a3c3 100644 --- a/src/ui/public/agg_types/metrics/percentiles.js +++ b/src/ui/public/agg_types/metrics/percentiles.js @@ -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(); } };