UNPKG

@spalger/kibana

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

52 lines (42 loc) 1.37 kB
define(function (require) { return function GetColumnsProvider(Private) { var _ = require('lodash'); var AggConfig = Private(require('ui/Vis/AggConfig')); return function getColumns(vis, minimal) { var 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 var columns = []; // seperate the metrics var 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; }; }; });