Skip to content

Commit

Permalink
[Maps] support styles on aggregation fields with _of_ in name
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Nov 26, 2019
1 parent b5133b5 commit fb3ed56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
32 changes: 3 additions & 29 deletions x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ESAggMetricField } from '../fields/es_agg_field';
import { ESDocField } from '../fields/es_doc_field';
import { METRIC_TYPE, COUNT_AGG_TYPE, COUNT_PROP_LABEL, COUNT_PROP_NAME, FIELD_ORIGIN } from '../../../common/constants';

const AGG_DELIMITER = '_of_';
export const AGG_DELIMITER = '_of_';

export class AbstractESAggSource extends AbstractESSource {

Expand Down Expand Up @@ -46,34 +46,8 @@ export class AbstractESAggSource extends AbstractESSource {
}) : [];
}

createField({ fieldName, label }) {

//if there is a corresponding field with a custom label, use that one.
if (!label) {
const matchField = this._metricFields.find(field => field.getName() === fieldName);
if (matchField) {
label = matchField.getLabel();
}
}

if (fieldName === COUNT_PROP_NAME) {
return new ESAggMetricField({
aggType: COUNT_AGG_TYPE,
label: label,
source: this,
origin: this.getOriginForField()
});
}
//this only works because aggType is a fixed set and does not include the `_of_` string
const [aggType, docField] = fieldName.split(AGG_DELIMITER);
const esDocField = new ESDocField({ fieldName: docField, source: this });
return new ESAggMetricField({
label: label,
esDocField,
aggType,
source: this,
origin: this.getOriginForField()
});
createField({ fieldName }) {
return this.getMetricFieldForName(fieldName);
}

getMetricFieldForName(fieldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import _ from 'lodash';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { AggConfigs } from 'ui/agg_types';
import { i18n } from '@kbn/i18n';
import { ES_SIZE_LIMIT, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants';
import { ES_SIZE_LIMIT, FIELD_ORIGIN, METRIC_TYPE, COUNT_PROP_LABEL } from '../../../common/constants';
import { ESDocField } from '../fields/es_doc_field';
import { AbstractESAggSource } from './es_agg_source';
import { AbstractESAggSource, AGG_DELIMITER } from './es_agg_source';

const TERMS_AGG_NAME = 'join';

Expand Down Expand Up @@ -82,12 +82,12 @@ export class ESTermSource extends AbstractESAggSource {
}

formatMetricKey(aggType, fieldName) {
const metricKey = aggType !== METRIC_TYPE.COUNT ? `${aggType}_of_${fieldName}` : aggType;
const metricKey = aggType !== METRIC_TYPE.COUNT ? `${aggType}${AGG_DELIMITER}${fieldName}` : aggType;
return `${FIELD_NAME_PREFIX}${metricKey}${GROUP_BY_DELIMITER}${this._descriptor.indexPatternTitle}.${this._termField.getName()}`;
}

formatMetricLabel(type, fieldName) {
const metricLabel = type !== METRIC_TYPE.COUNT ? `${type} ${fieldName}` : 'count';
const metricLabel = type !== METRIC_TYPE.COUNT ? `${type} ${fieldName}` : COUNT_PROP_LABEL;
return `${metricLabel} of ${this._descriptor.indexPatternTitle}:${this._termField.getName()}`;
}

Expand Down

0 comments on commit fb3ed56

Please sign in to comment.