I'm trying to create a new field formatter for Kibana 5.4.1 that somehow mixes the "Color" and "Number" formatters. Specifically, I want to have a Color formatter that also rounds the numbers to three decimal points, in order to avoid huge numbers when calculating aggregations such as averages. To do that, I have slightly changed the "_convert" function in Color.js file under "/opt/kibana/src/ui/public/stringify/types", adding a substring function call:
_Color.prototype._convert = {
html(val) {
const color = _.findLast(this.param('colors'), ({ range }) => {
if (!range) return;
const [start, end] = range.split(':');
return val >= Number(start) && val <= Number(end);
});
if (!color) return _.asPrettyString(val);
// Substring the value before formatting it
val = val.substring(0,3);
const styleColor = color.text ? `color: ${color.text};` : '';
const styleBackgroundColor = color.background ? `background-color: ${color.background};` : '';
return `<span style="${styleColor}${styleBackgroundColor}">${_.escape(val)}</span>`;
}
};
However, after modifying the file and reloading the page and index, the field format remains the same (the numbers are colored (after configuring the formatter) but not rounded. Am I missing something here?
are you using production version if kibana? its very possible that the bundles were not rebuild and you are still running old code, you should try the dev version (https://github.com/elastic/kibana)
not sure about the code, would need to dive into it deeper to give you any valuable feedback
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.