kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
51 lines (41 loc) • 1.31 kB
JavaScript
import _ from 'lodash';
import VisAggConfigProvider from 'ui/vis/agg_config';
export default function GetColumnsProvider(Private) {
let AggConfig = Private(VisAggConfigProvider);
return function getColumns(vis, minimal) {
let aggs = vis.aggs.getResponseAggs();
if (minimal == null) minimal = !vis.isHierarchical();
if (!vis.aggs.bySchemaGroup.metrics) {
aggs.push(new AggConfig(vis, {
type: 'count',
schema: vis.type.schemas.metrics[0].name
}));
}
// pick the columns
if (minimal) {
return aggs.map(function (agg) {
return { aggConfig: agg };
});
}
// supposed to be bucket,...metrics,bucket,...metrics
let columns = [];
// seperate the metrics
let grouped = _.groupBy(aggs, function (agg) {
return agg.schema.group;
});
if (!grouped.buckets) {
// return just the metrics, in column format
return grouped.metrics.map(function (agg) {
return { aggConfig: agg };
});
}
// return the buckets, and after each place all of the metrics
grouped.buckets.forEach(function (agg, i) {
columns.push({ aggConfig: agg });
grouped.metrics.forEach(function (metric) {
columns.push({ aggConfig: metric });
});
});
return columns;
};
};