Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metric label #5142

Merged
merged 15 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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