-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
6 changed files
with
171 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div ng-controller="aggParam.controller"> | ||
<div class="form-group" ng-if="agg.params[aggType]"> | ||
<label>{{aggTitle}}</label> | ||
<div class="vis-editor-agg-order-agg"> | ||
<ng-form name="{{aggType}}Form"> | ||
<vis-editor-agg-params | ||
agg="agg.params[aggType]" | ||
group-name="'{{aggGroup}}'"> | ||
</vis-editor-agg-params> | ||
</ng-form> | ||
</div> | ||
</div> | ||
|
||
</div> |
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,18 @@ | ||
import AggTypesMetricsMetricAggTypeProvider from 'ui/agg_types/metrics/metric_agg_type'; | ||
import { makeNestedLabel } from './lib/make_nested_label'; | ||
import SiblingPipelineAggHelperProvider from './lib/sibling_pipeline_agg_helper'; | ||
|
||
|
||
export default function AggTypeMetricDerivativeProvider(Private) { | ||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider); | ||
const siblingPipelineHelper = Private(SiblingPipelineAggHelperProvider); | ||
|
||
return new MetricAggType({ | ||
name: 'sum_bucket', | ||
title: 'Bucket Sum', | ||
makeLabel: agg => makeNestedLabel(agg, 'overall sum'), | ||
params: [ | ||
...siblingPipelineHelper.params() | ||
] | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/ui/public/agg_types/metrics/lib/sibling_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,31 @@ | ||
import safeMakeLabel from './safe_make_label'; | ||
|
||
const siblingPipelineAggController = function (type) { | ||
return function ($scope) { | ||
|
||
$scope.aggType = type; | ||
//$scope.aggParam = $scope.agg.params[type]; | ||
$scope.aggTitle = type === 'customMetric' ? 'Metric' : 'Bucket'; | ||
$scope.aggGroup = type === 'customMetric' ? 'metrics' : 'buckets'; | ||
$scope.safeMakeLabel = safeMakeLabel; | ||
|
||
$scope.rejectAgg = function (agg) { | ||
const invalidAggs = ['top_hits', 'percentiles', 'percentile_ranks', 'median', 'std_dev']; | ||
return Boolean(invalidAggs.find(agg.type.name)); | ||
}; | ||
|
||
//$scope.$watch(`agg.params.${type}`, updateAgg); | ||
|
||
function updateAgg() { | ||
const agg = $scope.agg; | ||
const params = agg.params; | ||
const paramDef = agg.type.params.byName[type]; | ||
|
||
params[type] = params[type] || paramDef.makeAgg(agg); | ||
} | ||
|
||
updateAgg(); | ||
}; | ||
}; | ||
|
||
export { siblingPipelineAggController }; |
86 changes: 86 additions & 0 deletions
86
src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_helper.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,86 @@ | ||
import _ from 'lodash'; | ||
import VisAggConfigProvider from 'ui/vis/agg_config'; | ||
import VisSchemasProvider from 'ui/vis/schemas'; | ||
|
||
import { siblingPipelineAggController } from './sibling_pipeline_agg_controller'; | ||
import { siblingPipelineAggWritter } from './sibling_pipeline_agg_writter'; | ||
import metricAggTemplate from 'ui/agg_types/controls/sub_metric.html'; | ||
|
||
const SiblingPipelineAggHelperProvider = function (Private) { | ||
|
||
const AggConfig = Private(VisAggConfigProvider); | ||
const Schemas = Private(VisSchemasProvider); | ||
|
||
const metricAggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev']; | ||
const metricAggSchema = (new Schemas([ | ||
{ | ||
group: 'none', | ||
name: 'metricAgg', | ||
title: 'Metric Agg', | ||
aggFilter: metricAggFilter | ||
} | ||
])).all[0]; | ||
|
||
const bucketAggFilter = []; | ||
const bucketAggSchema = (new Schemas([ | ||
{ | ||
group: 'none', | ||
title: 'Bucket Agg', | ||
name: 'bucketAgg', | ||
aggFilter: bucketAggFilter | ||
} | ||
])).all[0]; | ||
|
||
return { | ||
params: function () { | ||
return [ | ||
{ | ||
name: 'customBucket', | ||
type: AggConfig, | ||
default: null, | ||
serialize: function (customMetric) { | ||
return customMetric.toJSON(); | ||
}, | ||
deserialize: function (state, agg) { | ||
return this.makeAgg(agg, state); | ||
}, | ||
makeAgg: function (agg, state) { | ||
state = state || {}; | ||
state.schema = bucketAggSchema; | ||
const orderAgg = new AggConfig(agg.vis, state); | ||
orderAgg.id = agg.id + '-bucket'; | ||
return orderAgg; | ||
}, | ||
editor: metricAggTemplate, | ||
controller: siblingPipelineAggController('customBucket'), | ||
write: _.noop | ||
}, | ||
{ | ||
name: 'customMetric', | ||
type: AggConfig, | ||
default: null, | ||
serialize: function (customMetric) { | ||
return customMetric.toJSON(); | ||
}, | ||
deserialize: function (state, agg) { | ||
return this.makeAgg(agg, state); | ||
}, | ||
makeAgg: function (agg, state) { | ||
state = state || {}; | ||
state.schema = metricAggSchema; | ||
const orderAgg = new AggConfig(agg.vis, state); | ||
orderAgg.id = agg.id + '-metric'; | ||
return orderAgg; | ||
}, | ||
editor: metricAggTemplate, | ||
controller: siblingPipelineAggController('customMetric'), | ||
write: siblingPipelineAggWritter | ||
} | ||
]; | ||
} | ||
}; | ||
|
||
|
||
}; | ||
|
||
export default SiblingPipelineAggHelperProvider; |
19 changes: 19 additions & 0 deletions
19
src/ui/public/agg_types/metrics/lib/sibling_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,19 @@ | ||
const siblingPipelineAggWritter = function (agg, output) { | ||
if (!agg.params.customMetric) return; | ||
|
||
const metricAgg = agg.params.customMetric; | ||
const bucketAgg = agg.params.customBucket; | ||
|
||
// if a bucket is selected, we must add this agg as a sibling to it, and add a metric to that bucket (or select one of its) | ||
if (metricAgg.type.name !== 'count') { | ||
bucketAgg.subAggs = (output.subAggs || []).concat(metricAgg); | ||
output.params.buckets_path = `${bucketAgg.id}>${metricAgg.id}`; | ||
} else { | ||
output.params.buckets_path = bucketAgg.id + '>_count'; | ||
} | ||
|
||
output.parentAggs = (output.parentAggs || []).concat(bucketAgg); | ||
|
||
}; | ||
|
||
export { siblingPipelineAggWritter }; |