Skip to content

Commit

Permalink
Merge pull request #2492 from rashidkpc/fix/number-precision
Browse files Browse the repository at this point in the history
Configurable precision for numbers
  • Loading branch information
lukasolson committed Jan 3, 2015
2 parents 74a117f + cc51704 commit 6691a0b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
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

0 comments on commit 6691a0b

Please sign in to comment.