mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[visType/pie] filter the metric aggs again since slice sizing isn't easily fixable
This commit is contained in:
parent
f7ddf50a15
commit
0798c41ee1
3 changed files with 62 additions and 59 deletions
52
src/kibana/filters/_prop_filter.js
Normal file
52
src/kibana/filters/_prop_filter.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
|
||||
/**
|
||||
* Filters out a list by a given filter. This is currently used to impelment:
|
||||
* - fieldType filters a list of fields by their type property
|
||||
* - aggFilter filters a list of aggs by their name property
|
||||
*
|
||||
* @returns {function} - the filter function which can be registered with angular
|
||||
*/
|
||||
function propFilter(prop) {
|
||||
/**
|
||||
* List filtering function which accepts an array or list of values that a property
|
||||
* must contain
|
||||
*
|
||||
* @param {array} list - array of items to filter
|
||||
* @param {array|string} filters - the values to match against the list. Can be
|
||||
* an array, a single value as a string, or a comma
|
||||
* -seperated list of items
|
||||
* @return {array} - the filtered list
|
||||
*/
|
||||
return function (list, filters) {
|
||||
if (!filters) return filters;
|
||||
if (!_.isArray(filters)) filters = filters.split(',');
|
||||
if (_.contains(filters, '*')) return filters;
|
||||
|
||||
filters = filters.map(function (filter) {
|
||||
var match = true;
|
||||
var value = filter;
|
||||
|
||||
if (filter.charAt(0) === '!') {
|
||||
match = false;
|
||||
value = filter.substr(1);
|
||||
}
|
||||
|
||||
return {
|
||||
match: match,
|
||||
value: value
|
||||
};
|
||||
});
|
||||
|
||||
return list.filter(function (item) {
|
||||
for (var i = 0; i < filters.length; i++) {
|
||||
var filter = filters[i];
|
||||
if ((item[prop] === filter.value) === filter.match) return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return propFilter;
|
||||
});
|
|
@ -3,34 +3,11 @@
|
|||
// Or an array of types to get all fields of that type
|
||||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var propFilter = require('filters/_prop_filter');
|
||||
|
||||
require('modules')
|
||||
.get('kibana')
|
||||
.filter('fieldType', function () {
|
||||
return function (fields, types) {
|
||||
if (!types) return fields;
|
||||
if (!_.isArray(types)) types = [types];
|
||||
if (_.contains(types, '*')) return fields;
|
||||
|
||||
var filters = types.map(function (type) {
|
||||
var filter = {
|
||||
match: true,
|
||||
type: type
|
||||
};
|
||||
|
||||
if (type.charAt(0) === '!') {
|
||||
filter.match = false;
|
||||
filter.type = type.substr(1);
|
||||
}
|
||||
return filter;
|
||||
});
|
||||
|
||||
return fields.filter(function (field) {
|
||||
for (var i = 0; i < filters.length; i++) {
|
||||
var filter = filters[i];
|
||||
if ((field.type === filter.type) === filter.match) return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
.get('kibana')
|
||||
.filter('fieldType', function () {
|
||||
return propFilter('type');
|
||||
});
|
||||
});
|
|
@ -1,36 +1,10 @@
|
|||
// Gets all fields of a given type.
|
||||
// You may also pass "*" to get all types
|
||||
// Or an array of types to get all fields of that type
|
||||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var propFilter = require('filters/_prop_filter');
|
||||
|
||||
require('modules')
|
||||
.get('kibana')
|
||||
.filter('aggFilter', function () {
|
||||
return function (aggs, names) {
|
||||
if (!names) return aggs;
|
||||
if (!_.isArray(names)) names = [names];
|
||||
if (_.contains(names, '*')) return aggs;
|
||||
|
||||
var filters = names.map(function (name) {
|
||||
var filter = {
|
||||
match: true,
|
||||
name: name
|
||||
};
|
||||
|
||||
if (name.charAt(0) === '!') {
|
||||
filter.match = false;
|
||||
filter.name = name.substr(1);
|
||||
}
|
||||
return filter;
|
||||
});
|
||||
|
||||
return aggs.filter(function (agg) {
|
||||
for (var i = 0; i < filters.length; i++) {
|
||||
var filter = filters[i];
|
||||
if ((agg.name === filter.name) === filter.match) return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
.get('kibana')
|
||||
.filter('aggFilter', function () {
|
||||
return propFilter('name');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue