mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
adjusted the shared kbn.top_field_values() function to preserve field values, specifically so that arrays are not flattened to strings
This commit is contained in:
parent
1989a30735
commit
b160700e68
16
js/shared.js
16
js/shared.js
@ -72,10 +72,20 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.top_field_values = function(docs,field,count) {
|
kbn.top_field_values = function(docs,field,count) {
|
||||||
var counts = _.countBy(_.pluck(docs,field),function(field){
|
var all_values = _.pluck(docs,field),
|
||||||
return _.isUndefined(field) ? '' : field;
|
groups = {};
|
||||||
|
|
||||||
|
// manually grouping into pairs allows us to keep the original value,
|
||||||
|
_.each(all_values, function (value) {
|
||||||
|
var key = _.isUndefined(value) ? '' : value.toString();
|
||||||
|
if (_.has(groups, key)) {
|
||||||
|
groups[key][1] ++;
|
||||||
|
} else {
|
||||||
|
groups[key] = [value, 1];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return _.pairs(counts).sort(function(a, b) {
|
|
||||||
|
return _.values(groups).sort(function(a, b) {
|
||||||
return a[1] - b[1];
|
return a[1] - b[1];
|
||||||
}).reverse().slice(0,count);
|
}).reverse().slice(0,count);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user