Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9fc4d03
[Maps] use style metadata to calculate symbolization bands
nreese Nov 26, 2019
9c756db
merge with master
nreese Nov 26, 2019
44b6bdc
only update style meta when fields change
nreese Nov 26, 2019
1aed323
load join source style meta
nreese Nov 26, 2019
9893f84
use style meta data request to populate range
nreese Nov 26, 2019
3315513
apply source filter to style meta request
nreese Nov 26, 2019
7df849f
Merge branch 'master' of github.com:elastic/kibana into style_meta2
nreese Dec 2, 2019
c5c5cbe
fix heatmap
nreese Dec 2, 2019
fe8615a
only use style meta range if field supports field meta
nreese Dec 2, 2019
69525f1
Merge branch 'master' of github.com:elastic/kibana into style_meta2
nreese Dec 2, 2019
569b946
add fieldMetaOptions to style prperty descriptor and add migration sc…
nreese Dec 2, 2019
3bf5b40
merge with master
nreese Dec 2, 2019
2d16a71
add UI for setting fieldMetaOptions.isEnabled
nreese Dec 2, 2019
467dca0
clean up
nreese Dec 2, 2019
e386597
review feedback
nreese Dec 3, 2019
edb9aed
fix can_skip_fetch tests
nreese Dec 3, 2019
3541149
review feedback
nreese Dec 3, 2019
5c8ed7d
only show field meta popover for fields that support field meta
nreese Dec 3, 2019
ba0bc74
avoid duplicate fields re-fetching style meta
nreese Dec 3, 2019
67ad76c
clean up problems when first creating grid source
nreese Dec 3, 2019
09d9a60
Merge branch 'master' of github.com:elastic/kibana into style_meta2
nreese Dec 4, 2019
a157eae
update text for enabling field meta toggle
nreese Dec 4, 2019
474d38f
provide UI for setting sigma
nreese Dec 4, 2019
1abd626
allow users to include global time in style meta request
nreese Dec 4, 2019
e9764e5
update SIEM saved objects
nreese Dec 4, 2019
84f694b
add less than and greater than symbols when styling by field stats
nreese Dec 4, 2019
f4ee834
fix functional tests
nreese Dec 4, 2019
6d943da
review feedback
nreese Dec 5, 2019
e80cb70
add support for date fields
nreese Dec 5, 2019
cc8b671
Merge branch 'master' of github.com:elastic/kibana into style_meta2
nreese Dec 5, 2019
ccabd81
review feedback
nreese Dec 5, 2019
820888f
only show less then and greater then in legend when values will be ou…
nreese Dec 5, 2019
b9974b3
unnest VectorStyle._getFieldRange
nreese Dec 5, 2019
e69b03f
remove unused function
nreese Dec 5, 2019
3bdac51
only show style isTimeAware switch when style fields use field meta
nreese Dec 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions x-pack/legacy/plugins/maps/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const FIELD_ORIGIN = {
};

export const SOURCE_DATA_ID_ORIGIN = 'source';
export const META_ID_ORIGIN_SUFFIX = 'meta';
export const SOURCE_META_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${META_ID_ORIGIN_SUFFIX}`;

export const GEOJSON_FILE = 'GEOJSON_FILE';

Expand Down Expand Up @@ -124,6 +126,11 @@ export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLab
export const COUNT_PROP_NAME = 'doc_count';

export const STYLE_TYPE = {
'STATIC': 'STATIC',
'DYNAMIC': 'DYNAMIC'
STATIC: 'STATIC',
DYNAMIC: 'DYNAMIC'
};

export const LAYER_STYLE_TYPE = {
VECTOR: 'VECTOR',
HEATMAP: 'HEATMAP'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { LAYER_TYPE, STYLE_TYPE } from '../constants';

function isVectorLayer(layerDescriptor) {
const layerType = _.get(layerDescriptor, 'type');
Comment thread
nreese marked this conversation as resolved.
return layerType === LAYER_TYPE.VECTOR;
}

export function addFieldMetaOptions({ attributes }) {
if (!attributes.layerListJSON) {
return attributes;
}

const layerList = JSON.parse(attributes.layerListJSON);
layerList.forEach((layerDescriptor) => {
if (isVectorLayer(layerDescriptor) && _.has(layerDescriptor, 'style.properties')) {
Object.values(layerDescriptor.style.properties).forEach(stylePropertyDescriptor => {
if (stylePropertyDescriptor.type === STYLE_TYPE.DYNAMIC) {
stylePropertyDescriptor.options.fieldMetaOptions = {
isEnabled: false, // turn off field metadata to avoid changing behavior of existing saved objects
sigma: 3,
};
}
});
}
});

return {
...attributes,
layerListJSON: JSON.stringify(layerList),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { addFieldMetaOptions } from './add_field_meta_options';
import { LAYER_TYPE, STYLE_TYPE } from '../constants';

describe('addFieldMetaOptions', () => {

test('Should handle missing layerListJSON attribute', () => {
const attributes = {
title: 'my map',
};
expect(addFieldMetaOptions({ attributes })).toEqual({
title: 'my map',
});
});

test('Should ignore non-vector layers', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.HEATMAP,
style: {
type: 'HEATMAP',
colorRampName: 'Greens'
}
}
]);
const attributes = {
title: 'my map',
layerListJSON
};
expect(addFieldMetaOptions({ attributes })).toEqual({
title: 'my map',
layerListJSON
});
});

test('Should ignore static style properties', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
style: {
type: 'VECTOR',
properties: {
lineColor: {
type: STYLE_TYPE.STATIC,
options: {
color: '#FFFFFF'
}
}
}
}
}
]);
const attributes = {
title: 'my map',
layerListJSON
};
expect(addFieldMetaOptions({ attributes })).toEqual({
title: 'my map',
layerListJSON
});
});

test('Should add field meta options to dynamic style properties', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
style: {
type: 'VECTOR',
properties: {
fillColor: {
type: STYLE_TYPE.DYNAMIC,
options: {
field: {
name: 'my_field',
origin: 'source'
},
color: 'Greys'
}
}
}
}
}
]);
const attributes = {
title: 'my map',
layerListJSON
};
expect(addFieldMetaOptions({ attributes })).toEqual({
title: 'my map',
layerListJSON: JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
style: {
type: 'VECTOR',
properties: {
fillColor: {
type: STYLE_TYPE.DYNAMIC,
options: {
field: {
name: 'my_field',
origin: 'source'
},
color: 'Greys',
fieldMetaOptions: {
isEnabled: false,
sigma: 3,
}
}
}
}
}
}
])
});
});
});
6 changes: 4 additions & 2 deletions x-pack/legacy/plugins/maps/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { extractReferences } from './common/migrations/references';
import { emsRasterTileToEmsVectorTile } from './common/migrations/ems_raster_tile_to_ems_vector_tile';
import { topHitsTimeToSort } from './common/migrations/top_hits_time_to_sort';
import { moveApplyGlobalQueryToSources } from './common/migrations/move_apply_global_query';
import { addFieldMetaOptions } from './common/migrations/add_field_meta_options';

export const migrations = {
'map': {
Expand Down Expand Up @@ -37,11 +38,12 @@ export const migrations = {
};
},
'7.6.0': (doc) => {
const attributes = moveApplyGlobalQueryToSources(doc);
const attributesPhase1 = moveApplyGlobalQueryToSources(doc);
const attributesPhase2 = addFieldMetaOptions({ attributes: attributesPhase1 });

return {
...doc,
attributes,
attributes: attributesPhase2,
};
}
},
Expand Down
17 changes: 15 additions & 2 deletions x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/


import { AbstractField } from './field';
import { COUNT_AGG_TYPE } from '../../../common/constants';
import { isMetricCountable } from '../util/is_metric_countable';
import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property';

export class ESAggMetricField extends AbstractField {
Expand Down Expand Up @@ -36,6 +36,11 @@ export class ESAggMetricField extends AbstractField {
return (this.getAggType() === COUNT_AGG_TYPE) ? true : !!this._esDocField;
}

async getDataType() {
// aggregations only provide numerical data
return 'number';
}

getESDocFieldName() {
return this._esDocField ? this._esDocField.getName() : '';
}
Expand All @@ -55,7 +60,6 @@ export class ESAggMetricField extends AbstractField {
);
}


makeMetricAggConfig() {
const metricAggConfig = {
id: this.getName(),
Expand All @@ -69,4 +73,13 @@ export class ESAggMetricField extends AbstractField {
}
return metricAggConfig;
}

supportsFieldMeta() {
// count and sum aggregations are not within field bounds so they do not support field meta.
return !isMetricCountable(this.getAggType());
}

async getFieldMetaRequest(config) {
return this._esDocField.getFieldMetaRequest(config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ESAggMetricField } from './es_agg_field';
import { METRIC_TYPE } from '../../../common/constants';

describe('supportsFieldMeta', () => {

test('Non-counting aggregations should support field meta', () => {
const avgMetric = new ESAggMetricField({ aggType: METRIC_TYPE.AVG });
expect(avgMetric.supportsFieldMeta()).toBe(true);
const maxMetric = new ESAggMetricField({ aggType: METRIC_TYPE.MAX });
expect(maxMetric.supportsFieldMeta()).toBe(true);
const minMetric = new ESAggMetricField({ aggType: METRIC_TYPE.MIN });
expect(minMetric.supportsFieldMeta()).toBe(true);
});

test('Counting aggregations should not support field meta', () => {
const countMetric = new ESAggMetricField({ aggType: METRIC_TYPE.COUNT });
expect(countMetric.supportsFieldMeta()).toBe(false);
const sumMetric = new ESAggMetricField({ aggType: METRIC_TYPE.SUM });
expect(sumMetric.supportsFieldMeta()).toBe(false);
const uniqueCountMetric = new ESAggMetricField({ aggType: METRIC_TYPE.UNIQUE_COUNT });
expect(uniqueCountMetric.supportsFieldMeta()).toBe(false);
});
});
27 changes: 27 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,31 @@ export class ESDocField extends AbstractField {
return field.type;
}

supportsFieldMeta() {
return true;
Comment thread
nreese marked this conversation as resolved.
}

async getFieldMetaRequest(/* config */) {
const field = await this._getField();

if (field.type !== 'number' && field.type !== 'date') {
return null;
}

const extendedStats = {};
if (field.scripted) {
extendedStats.script = {
source: field.script,
lang: field.lang
};
} else {
extendedStats.field = this._fieldName;
}
return {
[this._fieldName]: {
extended_stats: extendedStats
}
};
}

}
8 changes: 8 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/fields/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ export class AbstractField {
getOrigin() {
return this._origin;
}

supportsFieldMeta() {
return false;
}

async getFieldMetaRequest(/* config */) {
return null;
}
}
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { ESTermSource } from '../sources/es_term_source';
import { getComputedFieldNamePrefix } from '../styles/vector/style_util';
import { META_ID_ORIGIN_SUFFIX } from '../../../common/constants';

export class InnerJoin {

Expand Down Expand Up @@ -36,10 +37,14 @@ export class InnerJoin {
// Source request id must be static and unique because the re-fetch logic uses the id to locate the previous request.
// Elasticsearch sources have a static and unique id so that requests can be modified in the inspector.
// Using the right source id as the source request id because it meets the above criteria.
getSourceId() {
getSourceDataRequestId() {
return `join_source_${this._rightSource.getId()}`;
}

getSourceMetaDataRequestId() {
return `${this.getSourceDataRequestId()}_${META_ID_ORIGIN_SUFFIX}`;
}

getLeftField() {
return this._leftField;
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AbstractLayer {
}

supportsElasticsearchFilters() {
return this._source.supportsElasticsearchFilters();
return this._source.isESSource();
}

async supportsFitToBounds() {
Expand Down
Loading