Permalink
Browse files

Merge pull request #3369 from spalger/fix/3286

Fix/3286
  • Loading branch information...
spalger committed Mar 17, 2015
2 parents f2c72c1 + a9a980c commit 7dbb0840b276f73f84f938b8ef3d8bf9b08776e4
@@ -1,5 +1,5 @@
define(function (require) {
- return function MetricAggTypeProvider(Private) {
+ return function MetricAggTypeProvider(Private, indexPatterns) {
var _ = require('lodash');
var AggType = Private(require('components/agg_types/_agg_type'));
@@ -21,6 +21,15 @@ define(function (require) {
return bucket[agg.id].value;
};
+ MetricAggType.prototype.getFormat = function (agg) {
+ var field = agg.field();
+ if (field && field.type === 'date' && field.format) {
+ return field.format;
+ } else {
+ return indexPatterns.fieldFormats.byName.number;
+ }
+ };
+
return MetricAggType;
};
});
@@ -11,7 +11,7 @@ define(function (require) {
params: [
{
name: 'field',
- filterFieldTypes: 'number'
+ filterFieldTypes: 'number,date'
}
]
});
@@ -11,7 +11,7 @@ define(function (require) {
params: [
{
name: 'field',
- filterFieldTypes: 'number'
+ filterFieldTypes: 'number,date'
}
]
});
@@ -264,12 +264,15 @@ define(function (require) {
};
AggConfig.prototype.fieldFormatter = function () {
- if (this.schema && this.schema.group === 'metrics') {
- return fieldFormats.defaultByType.number.convert;
+ var field = this.field();
+ var format = field && field.format;
+ var strFormat = fieldFormats.defaultByType.string;
+
+ if (this.type.getFormat) {
+ format = this.type.getFormat(this) || format;
}
- var field = this.field();
- return field ? field.format.convert : String;
+ return (format || strFormat).convert;
};
AggConfig.prototype.fieldName = function () {
@@ -9,7 +9,8 @@
//
//## Gray and brand colors for use across Bootstrap.
-@gray-darker: lighten(#000, 13.5%);
+@gray-base: #000;
+@gray-darker: lighten(@gray-base, 13.5%);
@gray-dark: #7b8a8b;
@gray: #95a5a6;
@gray-light: #b4bcc2;
@@ -208,6 +209,9 @@
//** Small `.form-control` height
@input-height-small: (floor(@font-size-small * @line-height-small) + (@padding-small-vertical * 2) + 2);
+//** `.form-group` margin
+@form-group-margin-bottom: 15px;
+
@legend-color: @text-color;
@legend-border-color: transparent;
@@ -262,11 +266,12 @@
@zindex-navbar: 1000;
@zindex-dropdown: 1000;
@zindex-popover: 1010;
-@zindex-typeahead: 1020;
-@zindex-tooltip: 1030;
-@zindex-navbar-fixed: 1030;
-@zindex-modal-background: 1040;
-@zindex-modal: 1050;
+@zindex-tooltip: 1020;
+@zindex-typeahead: 1030;
+@zindex-tooltip: 1040;
+@zindex-navbar-fixed: 1050;
+@zindex-modal-background: 1060;
+@zindex-modal: 1070;
//== Media queries breakpoints
@@ -6,13 +6,20 @@ define(function (require) {
var AggType;
var AggConfig;
var indexPattern;
+ var dateFormat;
+ var stringFormat;
+ var numberFormat;
beforeEach(module('kibana'));
beforeEach(inject(function (Private) {
Vis = Private(require('components/vis/vis'));
AggType = Private(require('components/agg_types/_agg_type'));
AggConfig = Private(require('components/vis/_agg_config'));
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
+
+ dateFormat = indexPattern.fields.byName['@timestamp'].format.convert;
+ stringFormat = indexPattern.fields.byName.extension.format.convert;
+ numberFormat = indexPattern.fields.byName.bytes.format.convert;
}));
describe('#toDsl', function () {
@@ -206,5 +213,105 @@ define(function (require) {
expect(state).to.have.property('schema', 'segment');
});
});
+
+ describe('#fieldFormatter', function () {
+ it('returns number formatter for metrics on boolean', function () {
+ var vis = new Vis(indexPattern, {
+ type: 'histogram',
+ aggs: [
+ {
+ type: 'avg',
+ schema: 'metric',
+ params: { field: 'ssl' }
+ },
+ {
+ type: 'terms',
+ schema: 'segment',
+ params: { field: 'ssl' }
+ }
+ ]
+ });
+
+ expect(vis.aggs[0].fieldFormatter()).to.be(numberFormat);
+ expect(vis.aggs[1].fieldFormatter()).to.be(stringFormat);
+ });
+
+ it('returns number formatter for metrics on strings', function () {
+ var vis = new Vis(indexPattern, {
+ type: 'histogram',
+ aggs: [
+ {
+ type: 'cardinality',
+ schema: 'metric',
+ params: { field: 'extension' }
+ },
+ {
+ type: 'terms',
+ schema: 'segment',
+ params: { field: 'extension' }
+ }
+ ]
+ });
+
+ expect(vis.aggs[0].fieldFormatter()).to.be(numberFormat);
+ expect(vis.aggs[1].fieldFormatter()).to.be(stringFormat);
+ });
+
+ it('returns date formatter for metrics on date fields', function () {
+ var vis = new Vis(indexPattern, {
+ type: 'histogram',
+ aggs: [
+ {
+ type: 'cardinality',
+ schema: 'metric',
+ params: { field: '@timestamp' }
+ },
+ {
+ type: 'date_histogram',
+ schema: 'segment',
+ params: { field: '@timestamp' }
+ }
+ ]
+ });
+
+ expect(vis.aggs[0].fieldFormatter()).to.be(dateFormat);
+ expect(vis.aggs[1].fieldFormatter()).to.be(dateFormat);
+ });
+
+ it('returns the string format if the field does not have a format', function () {
+ var vis = new Vis(indexPattern, {
+ type: 'histogram',
+ aggs: [
+ {
+ type: 'date_histogram',
+ schema: 'segment',
+ params: { field: '@timestamp' }
+ }
+ ]
+ });
+
+ var agg = vis.aggs[0];
+ agg.params.field = { type: 'date', format: null };
+ expect(agg.fieldFormatter()).to.be(stringFormat);
+ });
+
+
+ it('returns the string format if their is no field', function () {
+ var vis = new Vis(indexPattern, {
+ type: 'histogram',
+ aggs: [
+ {
+ type: 'date_histogram',
+ schema: 'segment',
+ params: { field: '@timestamp' }
+ }
+ ]
+ });
+
+ var agg = vis.aggs[0];
+ delete agg.params.field;
+ expect(agg.fieldFormatter()).to.be(stringFormat);
+ });
+ });
}];
});

0 comments on commit 7dbb084

Please sign in to comment.