-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import _ from 'lodash'; | ||
|
||
const makeNestedLabel = function (aggConfig, label) { | ||
const uppercaseLabel = _.startCase(label); | ||
if (aggConfig.params.customMetric) { | ||
let metricLabel = aggConfig.params.customMetric.makeLabel(); | ||
if (metricLabel.includes(`${uppercaseLabel} of `)) { | ||
metricLabel = metricLabel.substring(`${uppercaseLabel} of `.length); | ||
metricLabel = `2. ${label} of ${metricLabel}`; | ||
} | ||
else if (metricLabel.includes(`${label} of `)) { | ||
metricLabel = (parseInt(metricLabel.substring(0, 1)) + 1) + metricLabel.substring(1); | ||
} | ||
else { | ||
metricLabel = `${uppercaseLabel} of ${metricLabel}`; | ||
} | ||
return metricLabel; | ||
} | ||
const metric = aggConfig.vis.aggs.find(agg => agg.id === aggConfig.params.buckets_path); | ||
return `${uppercaseLabel} of ${metric.makeLabel()}`; | ||
}; | ||
|
||
export { makeNestedLabel }; |
62 changes: 62 additions & 0 deletions
62
src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const aggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev']; | ||
|
||
const parentPipelineAggController = function ($scope) { | ||
|
||
$scope.safeMakeLabel = function (agg) { | ||
try { | ||
return agg.makeLabel(); | ||
} catch (e) { | ||
return '- agg not valid -'; | ||
} | ||
}; | ||
|
||
$scope.$watch('responseValueAggs', updateOrderAgg); | ||
$scope.$watch('agg.params.metricAgg', updateOrderAgg); | ||
|
||
$scope.$on('$destroy', function () { | ||
if ($scope.aggForm && $scope.aggForm.agg) { | ||
$scope.aggForm.agg.$setValidity('bucket', true); | ||
} | ||
}); | ||
|
||
// Returns true if the agg is not compatible with the terms bucket | ||
$scope.rejectAgg = function (agg) { | ||
// aggFilter elements all starts with a '!' | ||
// so the index of agg.type.name in a filter is 1 if it is included | ||
return Boolean(aggFilter.find((filter) => filter.indexOf(agg.type.name) === 1)); | ||
}; | ||
|
||
function checkBuckets() { | ||
const buckets = $scope.vis.aggs.filter(agg => agg.schema.group === 'buckets'); | ||
const bucketIsHistogram = buckets.length && ['date_histogram', 'histogram'].includes(buckets[0].type.name); | ||
const canUseAggregation = buckets.length === 1 && bucketIsHistogram; | ||
if ($scope.aggForm.agg) $scope.aggForm.agg.$setValidity('bucket', canUseAggregation); | ||
if (canUseAggregation) { | ||
if (buckets[0].type.name === 'histogram') { | ||
buckets[0].params.min_doc_count = 1; | ||
} | ||
else { | ||
buckets[0].params.min_doc_count = 0; | ||
} | ||
} | ||
} | ||
|
||
function updateOrderAgg() { | ||
const agg = $scope.agg; | ||
const params = agg.params; | ||
const metricAgg = params.metricAgg; | ||
const paramDef = agg.type.params.byName.customMetric; | ||
|
||
checkBuckets(); | ||
|
||
// we aren't creating a custom aggConfig | ||
if (metricAgg !== 'custom') { | ||
params.customMetric = null; | ||
return; | ||
} | ||
|
||
params.customMetric = params.customMetric || paramDef.makeAgg(agg); | ||
} | ||
}; | ||
|
||
export { parentPipelineAggController }; |
17 changes: 17 additions & 0 deletions
17
src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const parentPipelineAggWritter = function (agg, output) { | ||
const vis = agg.vis; | ||
const orderAgg = agg.params.customMetric || vis.aggs.getResponseAggById(agg.params.metricAgg); | ||
|
||
if (agg.params.customMetric && agg.params.customMetric.type.name !== 'count') { | ||
output.parentAggs = (output.parentAggs || []).concat(orderAgg); | ||
} | ||
|
||
output.params = {}; | ||
if (orderAgg.type.name === 'count') { | ||
output.params.buckets_path = '_count'; | ||
} else { | ||
output.params.buckets_path = orderAgg.id; | ||
} | ||
}; | ||
|
||
export { parentPipelineAggWritter }; |