Skip to content

Commit

Permalink
Merge pull request #5142 from acs/metric-label
Browse files Browse the repository at this point in the history
Metric label
  • Loading branch information
Rashid Khan committed Feb 3, 2016
2 parents 618e23b + f0527aa commit 2a5cdae
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/plugins/kibana/public/visualize/editor/agg.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<!-- down button -->
<button
aria-lebl="Decrease Priority"
aria-label="Decrease Priority"
ng-if="stats.count > 1"
ng-class="{ disabled: $last }"
ng-click="moveDown(agg)"
Expand All @@ -65,7 +65,9 @@
class="btn btn-xs btn-danger">
<i aria-hidden="true" class="fa fa-times"></i>
</button>

</div>

</div>

<vis-editor-agg-params
Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/Vis/AggConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ define(function (require) {
};

AggConfig.prototype.makeLabel = function () {
if (this.params.customLabel) {
return this.params.customLabel;
}

if (!this.type) return '';
var pre = (_.get(this.vis, 'params.mode') === 'percentage') ? 'Percentage of ' : '';
return pre += this.type.makeLabel(this);
Expand Down
30 changes: 30 additions & 0 deletions src/ui/public/Vis/__tests__/_AggConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,36 @@ describe('AggConfig', function () {
});
});

describe('#makeLabel', function () {
it('uses the custom label if it is defined', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
aggConfig.params.customLabel = 'Custom label';
var label = aggConfig.makeLabel();
expect(label).to.be(aggConfig.params.customLabel);
});
it('default label should be "Count"', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
var label = aggConfig.makeLabel();
expect(label).to.be('Count');
});
it('default label should be "Percentage of Count" when Vis is in percentage mode', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
aggConfig.vis.params.mode = 'percentage';
var label = aggConfig.makeLabel();
expect(label).to.be('Percentage of Count');
});
it('empty label if the Vis type is not defined', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
aggConfig.type = undefined;
var label = aggConfig.makeLabel();
expect(label).to.be('');
});
});

describe('#fieldFormatter', function () {
it('returns the fields format unless the agg type has a custom getFormat handler', function () {
var vis = new Vis(indexPattern, {
Expand Down
6 changes: 6 additions & 0 deletions src/ui/public/agg_types/AggType.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ define(function (require) {
type: 'json',
advanced: true
});
// always append custom label
this.params.push({
name: 'customLabel',
type: 'string',
write: _.noop
});

this.params = new AggParams(this.params);
}
Expand Down
5 changes: 3 additions & 2 deletions src/ui/public/agg_types/__tests__/AggType.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,17 @@ describe('AggType Class', function () {
});

expect(aggType.params).to.be.an(AggParams);
expect(aggType.params.length).to.be(1);
expect(aggType.params.length).to.be(2);
expect(aggType.params[0].name).to.be('json');
expect(aggType.params[1].name).to.be('customLabel');
});

it('passes the params arg directly to the AggParams constructor', function () {
var params = [
{name: 'one'},
{name: 'two'}
];
var paramLength = params.length + 1; // json is always appended
var paramLength = params.length + 2; // json and custom label are always appended

var aggType = new AggType({
name: 'bucketeer',
Expand Down

0 comments on commit 2a5cdae

Please sign in to comment.