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

Configurable precision for numbers #2492

Merged
merged 2 commits into from
Jan 3, 2015
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: 4 additions & 0 deletions src/kibana/components/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ define(function (require) {
value: 10,
description: 'The top N most popular fields to show',
},
'format:numberPrecision': {
value: 3,
description: 'Round numbers to this many decimal places',
},
'histogram:barTarget': {
value: 50,
description: 'Attempt to generate around this many bar when using "auto" interval in date histograms',
Expand Down
47 changes: 32 additions & 15 deletions src/kibana/components/index_patterns/_field_formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ define(function (require) {
var _ = require('lodash');
var moment = require('moment');

function stringConverter(val) {
return formatField(val, function (val) {
if (_.isObject(val)) {
return JSON.stringify(val);
}
else if (val == null) {
return '';
}
else {
return '' + val;
}
});
}

var formats = [
{
types: [
Expand All @@ -47,19 +61,7 @@ define(function (require) {
'conflict'
],
name: 'string',
convert: function (val) {
return formatField(val, function (val) {
if (_.isObject(val)) {
return JSON.stringify(val);
}
else if (val == null) {
return '';
}
else {
return '' + val;
}
});
}
convert: stringConverter
},
{
types: [
Expand Down Expand Up @@ -95,7 +97,22 @@ define(function (require) {
name: 'kilobytes',
convert: function (val) {
return formatField(val, function (val) {
return (val / 1024).toFixed(3) + ' kb';
return (val / 1024).toFixed(config.get('format:numberPrecision')) + ' kb';
});
}
},
{
types: [
'number'
],
name: 'number',
convert: function (val) {
return formatField(val, function (val) {
if (_.isNumber(val)) {
return +val.toFixed(config.get('format:numberPrecision'));
} else {
return stringConverter(val);
}
});
}
}
Expand Down Expand Up @@ -123,7 +140,7 @@ define(function (require) {
formats.byName = _.indexBy(formats, 'name');

formats.defaultByType = {
number: formats.byName.string,
number: formats.byName.number,
date: formats.byName.date,
boolean: formats.byName.string,
ip: formats.byName.ip,
Expand Down