From 659280e8dc3c6371e3879c10757afa7c4da32bcc Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 12:00:42 -0400 Subject: [PATCH 001/112] lint --- x-pack/legacy/plugins/maps/junk.txt | 22 ++++++++ .../public/layers/fields/ems_region_field.js | 12 ++++ .../maps/public/layers/fields/es_agg_field.js | 16 ++++++ .../maps/public/layers/fields/es_doc_field.js | 20 +++++++ .../maps/public/layers/fields/field.js | 56 +++++++++++++++++++ .../layers/fields/kibana_region_field.js | 12 ++++ .../es_search_source/es_search_source.js | 37 +++++++++--- .../tooltips/es_aggmetric_tooltip_property.js | 1 + .../maps/public/layers/vector_layer.js | 5 +- .../sample_data/web_logs_saved_objects.js | 1 - 10 files changed, 169 insertions(+), 13 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/junk.txt create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js diff --git a/x-pack/legacy/plugins/maps/junk.txt b/x-pack/legacy/plugins/maps/junk.txt new file mode 100644 index 0000000000000..b8fc99851b82f --- /dev/null +++ b/x-pack/legacy/plugins/maps/junk.txt @@ -0,0 +1,22 @@ + + +- tooltip properties + +- joins +-- left field (anything) +-- right field (agg) + +- style props (anything) + +- agg metrics +-- for grid layers +-- for point2point + + +getLeftJoinFields + + +VECTOR_LAYEWR#getFieldSource + + +stylePropertyLegendRow getFieldFormatter (why not just on state (?)) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js new file mode 100644 index 0000000000000..61f788d266fc9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js @@ -0,0 +1,12 @@ +/* + * 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 { AbstractField } from './field'; + +export class EMSRegionLayerField extends AbstractField { + static type = 'EMS_REGION_LAYER' +} diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js new file mode 100644 index 0000000000000..5e5fba90f2a9f --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -0,0 +1,16 @@ +/* + * 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 { AbstractField } from './field'; + +export class ESAggField extends AbstractField { + static type = 'ES_AGG'; + + getAggType() { + + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js new file mode 100644 index 0000000000000..2234ca56541bb --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -0,0 +1,20 @@ +/* + * 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 { AbstractField } from './field'; +import { ESTooltipProperty } from '../tooltips/es_tooltip_property'; + +export class ESDocField extends AbstractField { + + static type = 'ES_DOC'; + + async createTooltipProperty(value) { + const indexPattern = await this._source.getIndexPattern(); + return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); + } + +} diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js new file mode 100644 index 0000000000000..37532ef01494a --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -0,0 +1,56 @@ +/* + * 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. + */ + + +export class AbstractField { + + constructor({ fieldName, source }) { + this._fieldName = fieldName; + this._source = source; + } + + getName() { + return this._fieldName; + } + + getLabel() { + return this._fieldName; + } + + async isIdField() { + //todo + } + + async isDisplayField() { + //todo + } + + createTooltipProperty() { + throw new Error('must implement Field#createTooltipProperty'); + } + + getSource() { + return this._source; + } + + isOrdinal() { + return false; + } + + isDate() { + return false; + } + +} + + + + + + + + + diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js new file mode 100644 index 0000000000000..bd768c8dcfba5 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js @@ -0,0 +1,12 @@ +/* + * 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 { AbstractField } from './field'; + +export class KibanaRegionField extends AbstractField { + static type = 'KIBANA_REGION'; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 7c248e332d403..4ac7aa8e27f72 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -22,10 +22,10 @@ import { } from '../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; -import { ESTooltipProperty } from '../../tooltips/es_tooltip_property'; import { getSourceFields } from '../../../index_pattern_util'; import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants'; +import { ESDocField } from '../../fields/es_doc_field'; export class ESSearchSource extends AbstractESSource { @@ -67,15 +67,28 @@ export class ESSearchSource extends AbstractESSource { topHitsSplitField: descriptor.topHitsSplitField, topHitsSize: _.get(descriptor, 'topHitsSize', 1), }, inspectorAdapters); + + this._tooltipFields = this._descriptor.tooltipProperties.map((property) => { + return new ESDocField({ + fieldName: property, + source: this + }); + }); + } + + _getTooltipPropertyNames() { + return this._tooltipFields.map(field => field.getName()); } renderSourceSettingsEditor({ onChange }) { + + return ( 0; + return this._tooltipFields.length > 0; } async _loadTooltipProperties(docId, index, indexPattern) { - if (this._descriptor.tooltipProperties.length === 0) { + if (this._tooltipFields.length === 0) { return {}; } @@ -376,7 +394,7 @@ export class ESSearchSource extends AbstractESSource { query: `_id:"${docId}" and _index:${index}` }; searchSource.setField('query', query); - searchSource.setField('fields', this._descriptor.tooltipProperties); + searchSource.setField('fields', this._getTooltipPropertyNames()); const resp = await searchSource.fetch(); @@ -392,7 +410,7 @@ export class ESSearchSource extends AbstractESSource { const properties = indexPattern.flattenHit(hit); indexPattern.metaFields.forEach(metaField => { - if (!this._descriptor.tooltipProperties.includes(metaField)) { + if (!this._getTooltipPropertyNames().includes(metaField)) { delete properties[metaField]; } }); @@ -402,10 +420,11 @@ export class ESSearchSource extends AbstractESSource { async filterAndFormatPropertiesToHtml(properties) { const indexPattern = await this._getIndexPattern(); const propertyValues = await this._loadTooltipProperties(properties._id, properties._index, indexPattern); - - return this._descriptor.tooltipProperties.map(propertyName => { - return new ESTooltipProperty(propertyName, propertyName, propertyValues[propertyName], indexPattern); + const tooltipProperties = this._tooltipFields.map(field => { + const value = propertyValues[field.getName()]; + return field.createTooltipProperty(value); }); + return Promise.all(tooltipProperties); } isFilterByMapBounds() { diff --git a/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js b/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js index 11cbb36f49593..b1a21c7896185 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js @@ -13,6 +13,7 @@ export class ESAggMetricTooltipProperty extends ESTooltipProperty { super(propertyKey, propertyName, rawValue, indexPattern); this._metricField = metricField; } + isFilterable() { return false; } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 81f4f3b388d56..0a6312fe8b750 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -91,7 +91,8 @@ export class VectorLayer extends AbstractLayer { this._joins = []; if (options.layerDescriptor.joins) { options.layerDescriptor.joins.forEach((joinDescriptor) => { - this._joins.push(new InnerJoin(joinDescriptor, this._source.getInspectorAdapters())); + const join = new InnerJoin(joinDescriptor, this._source.getInspectorAdapters()); + this._joins.push(join); }); } } @@ -253,7 +254,6 @@ export class VectorLayer extends AbstractLayer { return this._source.getDisplayName(); } - async getDateFields() { const timeFields = await this._source.getDateFields(); return timeFields.map(({ label, name }) => { @@ -265,7 +265,6 @@ export class VectorLayer extends AbstractLayer { }); } - async getNumberFields() { const numberFields = await this._source.getNumberFields(); const numberFieldOptions = numberFields.map(({ label, name }) => { diff --git a/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js b/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js index 2ac1de70b17d3..c6d78a5020f6f 100644 --- a/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js +++ b/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js @@ -100,7 +100,6 @@ const layerList = [ 'type': 'ES_SEARCH', 'geoField': 'geo.coordinates', 'limit': 2048, - 'filterByMapBounds': true, 'tooltipProperties': [ 'clientip', 'timestamp', From 4387b7582920a4058f7a5ebeee854da666fc18bf Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 12:06:59 -0400 Subject: [PATCH 002/112] delete junk --- x-pack/legacy/plugins/maps/junk.txt | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/junk.txt diff --git a/x-pack/legacy/plugins/maps/junk.txt b/x-pack/legacy/plugins/maps/junk.txt deleted file mode 100644 index b8fc99851b82f..0000000000000 --- a/x-pack/legacy/plugins/maps/junk.txt +++ /dev/null @@ -1,22 +0,0 @@ - - -- tooltip properties - -- joins --- left field (anything) --- right field (agg) - -- style props (anything) - -- agg metrics --- for grid layers --- for point2point - - -getLeftJoinFields - - -VECTOR_LAYEWR#getFieldSource - - -stylePropertyLegendRow getFieldFormatter (why not just on state (?)) From 259f7275e8eae435acc6f37a0fd93766a867d3a4 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 13:39:54 -0400 Subject: [PATCH 003/112] add ems fields --- .../public/layers/fields/ems_region_field.js | 18 ++++++++- .../maps/public/layers/fields/field.js | 2 +- .../ems_file_source/ems_file_source.js | 40 +++++++++---------- .../ems_file_source/ems_file_source.test.js | 2 +- .../es_search_source/es_search_source.js | 4 -- .../public/layers/sources/vector_source.js | 4 ++ 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js index 61f788d266fc9..77e5b3a33da53 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js @@ -6,7 +6,23 @@ import { AbstractField } from './field'; +import { TooltipProperty } from '../tooltips/tooltip_property'; export class EMSRegionLayerField extends AbstractField { - static type = 'EMS_REGION_LAYER' + static type = 'EMS_REGION_LAYER'; + + async getLabel() { + const emsFileLayer = await this._source.getEMSFileLayer(); + const emsFields = emsFileLayer.getFieldsInLanguage(); + // Map EMS field name to language specific label + const emsField = emsFields.find(field => { + return field.name === this.getName(); + }); + return emsField ? emsField.description : this.getName(); + } + + async createTooltipProperty(value) { + const label = await this.getLabel(); + return new TooltipProperty(this.getName(), label, value); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 37532ef01494a..048d740532566 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -16,7 +16,7 @@ export class AbstractField { return this._fieldName; } - getLabel() { + async getLabel() { return this._fieldName; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index 3af1378e8e016..e1b3b6d2ac241 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -13,7 +13,7 @@ import { EMSFileCreateSourceEditor } from './create_source_editor'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { UpdateSourceEditor } from './update_source_editor'; -import { TooltipProperty } from '../../tooltips/tooltip_property'; +import { EMSRegionLayerField } from '../../fields/ems_region_field'; export class EMSFileSource extends AbstractVectorSource { @@ -45,19 +45,25 @@ export class EMSFileSource extends AbstractVectorSource { constructor(descriptor, inspectorAdapters) { super(EMSFileSource.createDescriptor(descriptor), inspectorAdapters); + this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => { + return new EMSRegionLayerField({ + fieldName: propertyKey, + source: this + }); + }); } renderSourceSettingsEditor({ onChange }) { return ( ); } - async _getEMSFileLayer() { + async getEMSFileLayer() { const emsClient = getEMSClient(); const emsFileLayers = await emsClient.getFileLayers(); const emsFileLayer = emsFileLayers.find((fileLayer => fileLayer.getId() === this._descriptor.id)); @@ -73,7 +79,7 @@ export class EMSFileSource extends AbstractVectorSource { } async getGeoJsonWithMeta() { - const emsFileLayer = await this._getEMSFileLayer(); + const emsFileLayer = await this.getEMSFileLayer(); const featureCollection = await AbstractVectorSource.getGeoJson({ format: emsFileLayer.getDefaultFormatType(), featureCollectionPath: 'data', @@ -98,7 +104,7 @@ export class EMSFileSource extends AbstractVectorSource { async getImmutableProperties() { let emsLink; try { - const emsFileLayer = await this._getEMSFileLayer(); + const emsFileLayer = await this.getEMSFileLayer(); emsLink = emsFileLayer.getEMSHotLink(); } catch(error) { // ignore error if EMS layer id could not be found @@ -121,7 +127,7 @@ export class EMSFileSource extends AbstractVectorSource { async getDisplayName() { try { - const emsFileLayer = await this._getEMSFileLayer(); + const emsFileLayer = await this.getEMSFileLayer(); return emsFileLayer.getDisplayName(); } catch (error) { return this._descriptor.id; @@ -129,13 +135,13 @@ export class EMSFileSource extends AbstractVectorSource { } async getAttributions() { - const emsFileLayer = await this._getEMSFileLayer(); + const emsFileLayer = await this.getEMSFileLayer(); return emsFileLayer.getAttributions(); } async getLeftJoinFields() { - const emsFileLayer = await this._getEMSFileLayer(); + const emsFileLayer = await this.getEMSFileLayer(); const fields = emsFileLayer.getFieldsInLanguage(); return fields.map(f => { return { name: f.name, label: f.description }; @@ -143,22 +149,16 @@ export class EMSFileSource extends AbstractVectorSource { } canFormatFeatureProperties() { - return this._descriptor.tooltipProperties.length; + return this._tooltipFields.length > 0; } async filterAndFormatPropertiesToHtml(properties) { - const emsFileLayer = await this._getEMSFileLayer(); - const emsFields = emsFileLayer.getFieldsInLanguage(); - - return this._descriptor.tooltipProperties.map(propertyName => { - // Map EMS field name to language specific label - const emsField = emsFields.find(field => { - return field.name === propertyName; - }); - const label = emsField ? emsField.description : propertyName; - - return new TooltipProperty(propertyName, label, properties[propertyName]); + const tooltipProperties = this._tooltipFields.map(field => { + const value = properties[field.getName()]; + return field.createTooltipProperty(value); }); + + return Promise.all(tooltipProperties); } async getSupportedShapeTypes() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.test.js index d9f759bdcc2cd..15581f1cfbacb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.test.js @@ -13,7 +13,7 @@ function makeEMSFileSource(tooltipProperties) { const emsFileSource = new EMSFileSource({ tooltipProperties: tooltipProperties }); - emsFileSource._getEMSFileLayer = () => { + emsFileSource.getEMSFileLayer = () => { return { getFieldsInLanguage() { return [{ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 4ac7aa8e27f72..90844b015fb8c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -76,10 +76,6 @@ export class ESSearchSource extends AbstractESSource { }); } - _getTooltipPropertyNames() { - return this._tooltipFields.map(field => field.getName()); - } - renderSourceSettingsEditor({ onChange }) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index b3e8c1b019f28..ee678ef68f5ca 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -57,6 +57,10 @@ export class AbstractVectorSource extends AbstractSource { mapColors); } + _getTooltipPropertyNames() { + return this._tooltipFields.map(field => field.getName()); + } + createDefaultLayer(options, mapColors) { const layerDescriptor = this._createDefaultLayerDescriptor(options, mapColors); const style = new VectorStyle(layerDescriptor.style, this); From f8df6bf16bb6a5fe7b62f21fe42aedacb3427ccb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 15:02:47 -0400 Subject: [PATCH 004/112] use fields in the tooltipproperties selector --- .../public/components/tooltip_selector.js | 31 +++++++++++-------- .../components/tooltip_selector.test.js | 31 ++++++++++++++++--- .../ems_file_source/ems_file_source.js | 2 +- .../ems_file_source/update_source_editor.js | 2 +- .../es_search_source/es_search_source.js | 2 +- .../es_search_source/update_source_editor.js | 4 +-- .../update_source_editor.test.js | 2 +- 7 files changed, 50 insertions(+), 24 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index f5a4b94072a4d..baebfb2a5214a 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -46,19 +46,24 @@ export class TooltipSelector extends Component { : propertyName; } + _getTooltipProperties() { + return this.props.tooltipFields.map(field => field.getName()); + } + _onAdd = (properties) => { - if (!this.props.tooltipProperties) { + if (!this.props.tooltipFields) { this.props.onChange([...properties]); } else { - this.props.onChange([...this.props.tooltipProperties, ...properties]); + const existingProperties = this._getTooltipProperties(); + this.props.onChange([...existingProperties, ...properties]); } } _removeProperty = (index) => { - if (!this.props.tooltipProperties) { + if (!this.props.tooltipFields) { this.props.onChange([]); } else { - const tooltipProperties = [...this.props.tooltipProperties]; + const tooltipProperties = this._getTooltipProperties(); tooltipProperties.splice(index, 1); this.props.onChange(tooltipProperties); } @@ -70,11 +75,11 @@ export class TooltipSelector extends Component { return; } - this.props.onChange(reorder(this.props.tooltipProperties, source.index, destination.index)); + this.props.onChange(reorder(this._getTooltipProperties(), source.index, destination.index)); }; _renderProperties() { - if (!this.props.tooltipProperties) { + if (!this.props.tooltipFields) { return null; } @@ -82,12 +87,12 @@ export class TooltipSelector extends Component { {(provided, snapshot) => ( - this.props.tooltipProperties.map((propertyName, idx) => ( + this.props.tooltipFields.map((field, idx) => ( @@ -99,7 +104,7 @@ export class TooltipSelector extends Component { })} > - {this._getPropertyLabel(propertyName)} + {this._getPropertyLabel(field.getName())}
{ - return { name: propertyName }; + const selectedFields = this.props.tooltipFields + ? this.props.tooltipFields.map(field => { + return { name: field.getName() }; }) : []; diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js index 10488640af99c..8d62d2946c188 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js @@ -9,19 +9,40 @@ import { shallow } from 'enzyme'; import { TooltipSelector } from './tooltip_selector'; + +class MockField { + constructor({ name, label, type }) { + this._name = name; + this._label = label; + this._type = type; + } + + getName() { + return this._name; + } + + async getLabel() { + return this._label; + } + + async getType() { + return this._type; + } +} + const defaultProps = { - tooltipProperties: ['iso2'], + tooltipFields: [new MockField({ name: 'iso2' })], onChange: (()=>{}), fields: [ - { + new MockField({ name: 'iso2', label: 'ISO 3166-1 alpha-2 code', type: 'string' - }, - { + }), + new MockField({ name: 'iso3', type: 'string' - }, + }) ] }; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index e1b3b6d2ac241..2575e62fe6230 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -57,7 +57,7 @@ export class EMSFileSource extends AbstractVectorSource { return ( ); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index ccd7592649e21..a2ee8dc7acc01 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -58,7 +58,7 @@ export class UpdateSourceEditor extends Component { render() { return ( diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 90844b015fb8c..290009e91c3ff 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -84,7 +84,7 @@ export class ESSearchSource extends AbstractESSource { indexPatternId={this._descriptor.indexPatternId} onChange={onChange} filterByMapBounds={this._descriptor.filterByMapBounds} - tooltipProperties={this._getTooltipPropertyNames()} + tooltipFields={this._tooltipFields} sortField={this._descriptor.sortField} sortOrder={this._descriptor.sortOrder} useTopHits={this._descriptor.useTopHits} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index 3678af4d54940..d96c26df17522 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -27,7 +27,7 @@ export class UpdateSourceEditor extends Component { indexPatternId: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, filterByMapBounds: PropTypes.bool.isRequired, - tooltipProperties: PropTypes.arrayOf(PropTypes.string).isRequired, + tooltipFields: PropTypes.arrayOf(PropTypes.object).isRequired, sortField: PropTypes.string, sortOrder: PropTypes.string.isRequired, useTopHits: PropTypes.bool.isRequired, @@ -168,7 +168,7 @@ export class UpdateSourceEditor extends Component { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.test.js index 9a3a74e0ed680..5a1b83589a1ee 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.test.js @@ -15,7 +15,7 @@ const defaultProps = { indexPatternId: 'indexPattern1', onChange: () => {}, filterByMapBounds: true, - tooltipProperties: [], + tooltipFields: [], sortOrder: 'DESC', useTopHits: false, topHitsSplitField: 'trackId', From 9ffdd30dde04e268a725e48acf405193ce184714 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 16:45:15 -0400 Subject: [PATCH 005/112] tooltip props for ems --- .../public/components/tooltip_selector.js | 94 +++++++++++++++---- .../maps/public/layers/fields/es_doc_field.js | 4 + .../maps/public/layers/fields/field.js | 10 ++ .../layers/fields/kibana_region_field.js | 6 ++ .../ems_file_source/ems_file_source.js | 1 + .../ems_file_source/update_source_editor.js | 21 +++-- 6 files changed, 109 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index baebfb2a5214a..7058725ca2f51 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -19,6 +19,7 @@ import { import { AddTooltipFieldPopover } from './add_tooltip_field_popover'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; +import _ from 'lodash'; // TODO import reorder from EUI once its exposed as service // https://github.com/elastic/eui/issues/2372 @@ -32,18 +33,74 @@ const reorder = (list, startIndex, endIndex) => { export class TooltipSelector extends Component { + state = { + fieldProps: [], + selectedFieldProps: [] + }; + + constructor() { + super(); + this._isMounted = false; + } + + componentDidMount() { + this._isMounted = true; + this._loadFieldProps(); + } + + componentWillUnmount() { + this._isMounted = false; + } + + componentDidUpdate() { + this._loadFieldProps(); + } + + async _loadFieldProps() { + + const getProps = async field => { + return new Promise(async (resolve, reject) => { + console.log('f', field); + try { + const label = await field.getLabel(); + const type = await field.getType(); + resolve({ + label: label, + type: type, + name: field.getName() + }); + }catch(e) { + reject(e); + } + }); + }; + + const props = this.props.fields.map(getProps); + const selectedProps = this.props.tooltipFields.map(getProps); + + const newState = { + fieldProps: await Promise.all(props), + selectedFieldProps: await Promise.all(selectedProps) + }; + + + if (this._isMounted) { + if (!_.isEqual(this.state, newState)) { + console.log('set the atate', newState); + this.setState(newState); + } + } + + } + _getPropertyLabel = (propertyName) => { - if (!this.props.fields) { + if (!this.state.fieldProps.length) { return propertyName; } - - const field = this.props.fields.find(field => { + const prop = this.state.fieldProps.find((field) => { return field.name === propertyName; }); - - return field && field.label - ? field.label - : propertyName; + return prop.label ? prop.label : propertyName; } _getTooltipProperties() { @@ -79,20 +136,22 @@ export class TooltipSelector extends Component { }; _renderProperties() { - if (!this.props.tooltipFields) { + console.log('r', this.state); + if (!this.state.selectedFieldProps.length) { return null; } + console.log('render selectio'); return ( {(provided, snapshot) => ( - this.props.tooltipFields.map((field, idx) => ( + this.state.selectedFieldProps.map((field, idx) => ( @@ -104,7 +163,7 @@ export class TooltipSelector extends Component { })} > - {this._getPropertyLabel(field.getName())} + {this._getPropertyLabel(field.name)}
{ - return { name: field.getName() }; - }) - : []; + console.log('render!'); return (
@@ -165,8 +219,8 @@ export class TooltipSelector extends Component {
diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 2234ca56541bb..b854a6a7427e7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -17,4 +17,8 @@ export class ESDocField extends AbstractField { return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); } + async getType() { + + } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 048d740532566..542d361ca93dd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -7,6 +7,12 @@ export class AbstractField { + static FIELD_TYPE = { + STRING: 'string', + NUMBER: 'number', + DATE: 'date' + } + constructor({ fieldName, source }) { this._fieldName = fieldName; this._source = source; @@ -16,6 +22,10 @@ export class AbstractField { return this._fieldName; } + async getType() { + return AbstractField.FIELD_TYPE.STRING; + } + async getLabel() { return this._fieldName; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js index bd768c8dcfba5..7f15b38f7a3e6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js @@ -8,5 +8,11 @@ import { AbstractField } from './field'; export class KibanaRegionField extends AbstractField { + static type = 'KIBANA_REGION'; + + async getType() { + return AbstractField.FIELD_TYPE.STRING; + } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index 2575e62fe6230..23e382a85f383 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -59,6 +59,7 @@ export class EMSFileSource extends AbstractVectorSource { onChange={onChange} tooltipFields={this._tooltipFields} layerId={this._descriptor.id} + source={this} /> ); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index a2ee8dc7acc01..053bd2a5c938a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -8,12 +8,14 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { TooltipSelector } from '../../../components/tooltip_selector'; import { getEMSClient } from '../../../meta'; +import { EMSRegionLayerField } from '../../fields/ems_region_field'; export class UpdateSourceEditor extends Component { static propTypes = { onChange: PropTypes.func.isRequired, - tooltipProperties: PropTypes.arrayOf(PropTypes.string).isRequired + tooltipFields: PropTypes.arrayOf(PropTypes.object).isRequired, + source: PropTypes.object }; state = { @@ -36,26 +38,31 @@ export class UpdateSourceEditor extends Component { const emsFiles = await emsClient.getFileLayers(); const emsFile = emsFiles.find((emsFile => emsFile.getId() === this.props.layerId)); const emsFields = emsFile.getFieldsInLanguage(); - fields = emsFields.map(field => { - return { - name: field.name, - label: field.description - }; - }); + fields = emsFields.map(field => new EMSRegionLayerField({ + fieldName: field.name, + source: this.props.source + })); } catch(e) { //swallow this error. when a matching EMS-config cannot be found, the source already will have thrown errors during the data request. This will propagate to the vector-layer and be displayed in the UX fields = []; } + if (this._isMounted) { this.setState({ fields: fields }); } } _onTooltipPropertiesSelect = (propertyNames) => { + console.log('on select', propertyNames); this.props.onChange({ propName: 'tooltipProperties', value: propertyNames }); }; render() { + + if (!this.state.fields) { + return null; + } + return ( Date: Wed, 23 Oct 2019 17:09:02 -0400 Subject: [PATCH 006/112] add fields for for es tooltips --- .../public/components/tooltip_selector.js | 4 ++++ .../maps/public/layers/fields/es_doc_field.js | 8 +++++++- .../es_search_source/es_search_source.js | 2 +- .../es_search_source/update_source_editor.js | 20 ++++++++++++++++--- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 7058725ca2f51..56283d7aba161 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -58,6 +58,10 @@ export class TooltipSelector extends Component { async _loadFieldProps() { + if (!this.props.fields || !this.props.tooltipFields) { + return; + } + const getProps = async field => { return new Promise(async (resolve, reject) => { console.log('f', field); diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index b854a6a7427e7..fa6323386f766 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -12,13 +12,19 @@ export class ESDocField extends AbstractField { static type = 'ES_DOC'; + async _getField() { + const indexPattern = await this._source.getIndexPattern(); + return indexPattern.fields.find((field) => field.name === this._fieldName); + } + async createTooltipProperty(value) { const indexPattern = await this._source.getIndexPattern(); return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); } async getType() { - + const type = await this._getField(); + return type.type; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 290009e91c3ff..c3c2b7921576b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -81,6 +81,7 @@ export class ESSearchSource extends AbstractESSource { return ( { + return new ESDocField({ + fieldName: field.name, + source: this.props.source + }); + }); + this.setState({ - tooltipFields: getSourceFields(indexPattern.fields), - termFields: getTermsFields(indexPattern.fields), - sortFields: indexPattern.fields.filter(field => field.sortable), + tooltipFields: tooltipFields, + termFields: getTermsFields(indexPattern.fields), //todo change term fields to use fields + sortFields: indexPattern.fields.filter(field => field.sortable), //todo change sort fields to use fields }); } _onTooltipPropertiesChange = propertyNames => { @@ -164,6 +175,9 @@ export class UpdateSourceEditor extends Component { } render() { + + console.log(this.state); + return ( From ced272e2e58d305f98737a386885cc1bea2126e8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 17:11:43 -0400 Subject: [PATCH 007/112] remove logs --- .../plugins/maps/public/components/tooltip_selector.js | 6 ------ .../layers/sources/ems_file_source/update_source_editor.js | 1 - .../layers/sources/es_search_source/update_source_editor.js | 3 --- 3 files changed, 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 56283d7aba161..1d524c20ead8d 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -64,7 +64,6 @@ export class TooltipSelector extends Component { const getProps = async field => { return new Promise(async (resolve, reject) => { - console.log('f', field); try { const label = await field.getLabel(); const type = await field.getType(); @@ -90,7 +89,6 @@ export class TooltipSelector extends Component { if (this._isMounted) { if (!_.isEqual(this.state, newState)) { - console.log('set the atate', newState); this.setState(newState); } } @@ -140,12 +138,10 @@ export class TooltipSelector extends Component { }; _renderProperties() { - console.log('r', this.state); if (!this.state.selectedFieldProps.length) { return null; } - console.log('render selectio'); return ( @@ -205,8 +201,6 @@ export class TooltipSelector extends Component { } render() { - console.log('render!'); - return (
diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index 053bd2a5c938a..705f45a9d69b6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -53,7 +53,6 @@ export class UpdateSourceEditor extends Component { } _onTooltipPropertiesSelect = (propertyNames) => { - console.log('on select', propertyNames); this.props.onChange({ propName: 'tooltipProperties', value: propertyNames }); }; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index b0ea8968ca4f8..05bdfe701e356 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -175,9 +175,6 @@ export class UpdateSourceEditor extends Component { } render() { - - console.log(this.state); - return ( From 99cd3844bf31ac5732a03c15a255de2acf177921 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 17:35:57 -0400 Subject: [PATCH 008/112] remove cruft --- .../public/layers/fields/ems_region_field.js | 4 +--- .../maps/public/layers/fields/es_agg_field.js | 4 ---- .../maps/public/layers/fields/es_doc_field.js | 4 ++-- .../maps/public/layers/fields/field.js | 22 +------------------ 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js index 77e5b3a33da53..4b1dfce242a12 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js @@ -15,9 +15,7 @@ export class EMSRegionLayerField extends AbstractField { const emsFileLayer = await this._source.getEMSFileLayer(); const emsFields = emsFileLayer.getFieldsInLanguage(); // Map EMS field name to language specific label - const emsField = emsFields.find(field => { - return field.name === this.getName(); - }); + const emsField = emsFields.find(field => field.name === this.getName()); return emsField ? emsField.description : this.getName(); } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 5e5fba90f2a9f..70fdeba2f346b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -9,8 +9,4 @@ import { AbstractField } from './field'; export class ESAggField extends AbstractField { static type = 'ES_AGG'; - - getAggType() { - - } } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index fa6323386f766..187e046a2eb6c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -23,8 +23,8 @@ export class ESDocField extends AbstractField { } async getType() { - const type = await this._getField(); - return type.type; + const field = await this._getField(); + return field.type; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 542d361ca93dd..c21d45df729df 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -11,7 +11,7 @@ export class AbstractField { STRING: 'string', NUMBER: 'number', DATE: 'date' - } + }; constructor({ fieldName, source }) { this._fieldName = fieldName; @@ -30,30 +30,10 @@ export class AbstractField { return this._fieldName; } - async isIdField() { - //todo - } - - async isDisplayField() { - //todo - } - createTooltipProperty() { throw new Error('must implement Field#createTooltipProperty'); } - getSource() { - return this._source; - } - - isOrdinal() { - return false; - } - - isDate() { - return false; - } - } From 64ceb0d6642dbbac0e013bb5ff2ff8fc1b25f098 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 18:05:51 -0400 Subject: [PATCH 009/112] fields for term sources --- .../features_tooltip/feature_properties.js | 1 + .../maps/public/layers/fields/es_doc_field.js | 11 +++++-- .../es_geo_grid_source/es_geo_grid_source.js | 4 +-- .../es_pew_pew_source/es_pew_pew_source.js | 6 ++-- .../es_search_source/es_search_source.js | 19 ++++------- .../maps/public/layers/sources/es_source.js | 16 ++++----- .../public/layers/sources/es_term_source.js | 33 ++++++++----------- .../layers/tooltips/join_tooltip_property.js | 6 ++-- 8 files changed, 45 insertions(+), 51 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_properties.js b/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_properties.js index 866c099b841a1..7843770327011 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_properties.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_properties.js @@ -155,6 +155,7 @@ export class FeatureProperties extends React.Component { } const rows = this.state.properties.map(tooltipProperty => { + const label = tooltipProperty.getPropertyName(); return ( diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 187e046a2eb6c..2dc8d2785229b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -18,8 +18,15 @@ export class ESDocField extends AbstractField { } async createTooltipProperty(value) { - const indexPattern = await this._source.getIndexPattern(); - return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); + try { + const indexPattern = await this._source.getIndexPattern(); + if (!indexPattern) { + return null; + } + return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); + } catch (e) { + return null; + } } async getType() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 8416ef5709e30..97411c9030217 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -102,7 +102,7 @@ export class ESGeoGridSource extends AbstractESSource { async getImmutableProperties() { let indexPatternTitle = this._descriptor.indexPatternId; try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); indexPatternTitle = indexPattern.title; } catch (error) { // ignore error, title will just default to id @@ -184,7 +184,7 @@ export class ESGeoGridSource extends AbstractESSource { } async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const searchSource = await this._makeSearchSource(searchFilters, 0); const aggConfigs = new AggConfigs(indexPattern, this._makeAggConfigs(searchFilters.geogridPrecision), aggSchemas.all); searchSource.setField('aggs', aggConfigs.toDsl()); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 4c081d386b3d7..2f0cc451008f7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -109,7 +109,7 @@ export class ESPewPewSource extends AbstractESSource { async getImmutableProperties() { let indexPatternTitle = this._descriptor.indexPatternId; try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); indexPatternTitle = indexPattern.title; } catch (error) { // ignore error, title will just default to id @@ -184,7 +184,7 @@ export class ESPewPewSource extends AbstractESSource { } async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const metricAggConfigs = this.getMetricFields().map(metric => { const metricAggConfig = { id: metric.propertyKey, @@ -260,7 +260,7 @@ export class ESPewPewSource extends AbstractESSource { } async _getGeoField() { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const geoField = indexPattern.fields.getByName(this._descriptor.destGeoField); if (!geoField) { throw new Error(i18n.translate('xpack.maps.source.esSource.noGeoFieldErrorMessage', { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index c3c2b7921576b..ee2b95ff48942 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -97,7 +97,7 @@ export class ESSearchSource extends AbstractESSource { async getNumberFields() { try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); return indexPattern.fields.getByType('number').map(field => { return { name: field.name, label: field.name }; }); @@ -106,14 +106,9 @@ export class ESSearchSource extends AbstractESSource { } } - async getIndexPattern() { - //todo rename _getIndexPattern to getIndexPattern - return await this._getIndexPattern(); - } - async getDateFields() { try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); return indexPattern.fields.getByType('date').map(field => { return { name: field.name, label: field.name }; }); @@ -134,7 +129,7 @@ export class ESSearchSource extends AbstractESSource { let indexPatternTitle = this._descriptor.indexPatternId; let geoFieldType = ''; try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); indexPatternTitle = indexPattern.title; const geoField = await this._getGeoField(); geoFieldType = geoField.type; @@ -211,7 +206,7 @@ export class ESSearchSource extends AbstractESSource { topHitsSize, } = this._descriptor; - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const geoField = await this._getGeoField(); const scriptFields = {}; @@ -342,7 +337,7 @@ export class ESSearchSource extends AbstractESSource { ? await this._getTopHits(layerName, searchFilters, registerCancelCallback) : await this._getSearchHits(layerName, searchFilters, registerCancelCallback); - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const unusedMetaFields = indexPattern.metaFields.filter(metaField => { return !['_id', '_index'].includes(metaField); }); @@ -415,7 +410,7 @@ export class ESSearchSource extends AbstractESSource { } async filterAndFormatPropertiesToHtml(properties) { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const propertyValues = await this._loadTooltipProperties(properties._id, properties._index, indexPattern); const tooltipProperties = this._tooltipFields.map(field => { const value = propertyValues[field.getName()]; @@ -429,7 +424,7 @@ export class ESSearchSource extends AbstractESSource { } async getLeftJoinFields() { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); // Left fields are retrieved from _source. return getSourceFields(indexPattern.fields) .map(field => { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 0670474df89bb..1e41cad4515ce 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -99,7 +99,7 @@ export class AbstractESSource extends AbstractVectorSource { async filterAndFormatPropertiesToHtmlForMetricFields(properties) { let indexPattern; try { - indexPattern = await this._getIndexPattern(); + indexPattern = await this.getIndexPattern(); } catch(error) { console.warn(`Unable to find Index pattern ${this._descriptor.indexPatternId}, values are not formatted`); return properties; @@ -158,7 +158,7 @@ export class AbstractESSource extends AbstractVectorSource { } async _makeSearchSource(searchFilters, limit, initialSearchContext) { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const isTimeAware = await this.isTimeAware(); const applyGlobalQuery = _.get(searchFilters, 'applyGlobalQuery', true); const globalFilters = applyGlobalQuery ? searchFilters.filters : []; @@ -193,7 +193,7 @@ export class AbstractESSource extends AbstractVectorSource { const searchSource = await this._makeSearchSource({ sourceQuery, query, timeFilters, filters, applyGlobalQuery }, 0); const geoField = await this._getGeoField(); - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const geoBoundsAgg = [{ type: 'geo_bounds', @@ -234,7 +234,7 @@ export class AbstractESSource extends AbstractVectorSource { async isTimeAware() { try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const timeField = indexPattern.timeFieldName; return !!timeField; } catch (error) { @@ -242,7 +242,7 @@ export class AbstractESSource extends AbstractVectorSource { } } - async _getIndexPattern() { + async getIndexPattern() { if (this.indexPattern) { return this.indexPattern; } @@ -271,7 +271,7 @@ export class AbstractESSource extends AbstractVectorSource { async _getGeoField() { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const geoField = indexPattern.fields.getByName(this._descriptor.geoField); if (!geoField) { throw new Error(i18n.translate('xpack.maps.source.esSource.noGeoFieldErrorMessage', { @@ -284,7 +284,7 @@ export class AbstractESSource extends AbstractVectorSource { async getDisplayName() { try { - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); return indexPattern.title; } catch (error) { // Unable to load index pattern, just return id as display name @@ -317,7 +317,7 @@ export class AbstractESSource extends AbstractVectorSource { let indexPattern; try { - indexPattern = await this._getIndexPattern(); + indexPattern = await this.getIndexPattern(); } catch(error) { return null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 5d876dbbd011f..9ca9cd96c1526 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -12,6 +12,7 @@ import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; import { ESTooltipProperty } from '../tooltips/es_tooltip_property'; import { ES_SIZE_LIMIT } from '../../../common/constants'; +import { ESDocField } from '../fields/es_doc_field'; const TERMS_AGG_NAME = 'join'; @@ -58,6 +59,10 @@ export class ESTermSource extends AbstractESSource { static type = 'ES_TERM_SOURCE'; + constructor(descriptor, inspectorAdapters) { + super(descriptor, inspectorAdapters); + this._termField = new ESDocField({ fieldName: descriptor.term, source: this }); + } static renderEditor({}) { //no need to localize. this editor is never rendered. @@ -72,8 +77,8 @@ export class ESTermSource extends AbstractESSource { return [this._descriptor.indexPatternId]; } - getTerm() { - return this._descriptor.term; + getTermField() { + return this._termField; } getWhereQuery() { @@ -82,12 +87,12 @@ export class ESTermSource extends AbstractESSource { _formatMetricKey(metric) { const metricKey = metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : metric.type; - return `__kbnjoin__${metricKey}_groupby_${this._descriptor.indexPatternTitle}.${this._descriptor.term}`; + return `__kbnjoin__${metricKey}_groupby_${this._descriptor.indexPatternTitle}.${this._termField.getName()}`; } _formatMetricLabel(metric) { const metricLabel = metric.type !== 'count' ? `${metric.type} ${metric.field}` : 'count'; - return `${metricLabel} of ${this._descriptor.indexPatternTitle}:${this._descriptor.term}`; + return `${metricLabel} of ${this._descriptor.indexPatternTitle}:${this._termField.getName()}`; } async getPropertiesMap(searchFilters, leftSourceName, leftFieldName, registerCancelCallback) { @@ -96,13 +101,13 @@ export class ESTermSource extends AbstractESSource { return []; } - const indexPattern = await this._getIndexPattern(); + const indexPattern = await this.getIndexPattern(); const searchSource = await this._makeSearchSource(searchFilters, 0); const configStates = this._makeAggConfigs(); const aggConfigs = new AggConfigs(indexPattern, configStates, aggSchemas.all); searchSource.setField('aggs', aggConfigs.toDsl()); - const requestName = `${this._descriptor.indexPatternTitle}.${this._descriptor.term}`; + const requestName = `${this._descriptor.indexPatternTitle}.${this._termField.getName()}`; const requestDesc = this._getRequestDescription(leftSourceName, leftFieldName); const rawEsData = await this._runEsQuery(requestName, searchSource, registerCancelCallback, requestDesc); @@ -135,7 +140,7 @@ export class ESTermSource extends AbstractESSource { defaultMessage: `Join {leftSourceName}:{leftFieldName} with`, values: { leftSourceName, leftFieldName } })); - joinStatement.push(`${this._descriptor.indexPatternTitle}:${this._descriptor.term}`); + joinStatement.push(`${this._descriptor.indexPatternTitle}:${this._termField.getName()}`); joinStatement.push(i18n.translate('xpack.maps.source.esJoin.joinMetricsDescription', { defaultMessage: `for metrics {metrics}`, values: { metrics: metrics.join(',') } @@ -171,7 +176,7 @@ export class ESTermSource extends AbstractESSource { type: 'terms', schema: 'segment', params: { - field: this._descriptor.term, + field: this._termField.getName(), size: ES_SIZE_LIMIT } } @@ -187,18 +192,6 @@ export class ESTermSource extends AbstractESSource { return await this.filterAndFormatPropertiesToHtmlForMetricFields(properties); } - async createESTooltipProperty(propertyName, rawValue) { - try { - const indexPattern = await this._getIndexPattern(); - if (!indexPattern) { - return null; - } - return new ESTooltipProperty(propertyName, propertyName, rawValue, indexPattern); - } catch (e) { - return null; - } - } - getFieldNames() { return this.getMetricFields().map(({ propertyKey }) => { return propertyKey; diff --git a/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js b/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js index cc19521063f36..6a95165da7566 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js @@ -38,10 +38,8 @@ export class JoinTooltipProperty extends TooltipProperty { for (let i = 0; i < this._leftInnerJoins.length; i++) { const rightSource = this._leftInnerJoins[i].getRightJoinSource(); - const esTooltipProperty = await rightSource.createESTooltipProperty( - rightSource.getTerm(), - this._tooltipProperty.getRawValue() - ); + const termField = rightSource.getTermField(); + const esTooltipProperty = await termField.createTooltipProperty(this._tooltipProperty.getRawValue()); if (esTooltipProperty) { esFilters.push(...(await esTooltipProperty.getESFilters())); } From 3cbe940dec4051e175fa2fe55ef60b52b92ffde8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Oct 2019 18:29:03 -0400 Subject: [PATCH 010/112] fieldify left field --- .../maps/public/layers/fields/es_doc_field.js | 11 ++--------- .../plugins/maps/public/layers/joins/inner_join.js | 10 ++++++---- .../sources/ems_file_source/ems_file_source.js | 12 +++++++----- .../sources/es_search_source/es_search_source.js | 12 +++++++----- .../plugins/maps/public/layers/sources/es_source.js | 4 ++++ .../maps/public/layers/sources/es_term_source.js | 1 - .../public/layers/tooltips/join_tooltip_property.js | 10 +++++++--- .../plugins/maps/public/layers/vector_layer.js | 2 +- 8 files changed, 34 insertions(+), 28 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 2dc8d2785229b..187e046a2eb6c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -18,15 +18,8 @@ export class ESDocField extends AbstractField { } async createTooltipProperty(value) { - try { - const indexPattern = await this._source.getIndexPattern(); - if (!indexPattern) { - return null; - } - return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); - } catch (e) { - return null; - } + const indexPattern = await this._source.getIndexPattern(); + return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); } async getType() { diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 8d1d1439a967e..5849248141fe4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -10,9 +10,11 @@ import { VectorStyle } from '../styles/vector_style'; export class InnerJoin { - constructor(joinDescriptor, inspectorAdapters) { + constructor(joinDescriptor, leftSource) { this._descriptor = joinDescriptor; + const inspectorAdapters = leftSource.getInspectorAdapters(); this._rightSource = new ESTermSource(joinDescriptor.right, inspectorAdapters); + this._leftField = this._descriptor.leftField ? leftSource.createField(joinDescriptor.leftField) : null; } destroy() { @@ -20,7 +22,7 @@ export class InnerJoin { } hasCompleteConfig() { - if (this._descriptor.leftField && this._rightSource) { + if (this._leftField && this._rightSource) { return this._rightSource.hasCompleteConfig(); } @@ -45,7 +47,7 @@ export class InnerJoin { } getLeftFieldName() { - return this._descriptor.leftField; + return this._leftField ? this._leftField.getName() : null; } joinPropertiesToFeature(feature, propertiesMap, rightMetricFields) { @@ -64,7 +66,7 @@ export class InnerJoin { }); } - const joinKey = feature.properties[this._descriptor.leftField]; + const joinKey = feature.properties[this._leftField.getName()]; const coercedKey = typeof joinKey === 'undefined' || joinKey === null ? null : joinKey.toString(); if (propertiesMap && coercedKey !== null && propertiesMap.has(coercedKey)) { Object.assign(feature.properties, propertiesMap.get(coercedKey)); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index 23e382a85f383..6c4c1752798e5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -45,11 +45,13 @@ export class EMSFileSource extends AbstractVectorSource { constructor(descriptor, inspectorAdapters) { super(EMSFileSource.createDescriptor(descriptor), inspectorAdapters); - this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => { - return new EMSRegionLayerField({ - fieldName: propertyKey, - source: this - }); + this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => this.createField(propertyKey)); + } + + createField(fieldName) { + return new EMSRegionLayerField({ + fieldName, + source: this }); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index ee2b95ff48942..e938276e866f3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -68,11 +68,13 @@ export class ESSearchSource extends AbstractESSource { topHitsSize: _.get(descriptor, 'topHitsSize', 1), }, inspectorAdapters); - this._tooltipFields = this._descriptor.tooltipProperties.map((property) => { - return new ESDocField({ - fieldName: property, - source: this - }); + this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField(property)); + } + + createField(fieldName) { + return new ESDocField({ + fieldName, + source: this }); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 1e41cad4515ce..1f0661bc162c0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -329,4 +329,8 @@ export class AbstractESSource extends AbstractVectorSource { return fieldFromIndexPattern.format.getConverterFor('text'); } + + createField() { + throw new Error('Child must implement Source#createField'); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 9ca9cd96c1526..740ac200610c1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -10,7 +10,6 @@ import { AbstractESSource } from './es_source'; import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; -import { ESTooltipProperty } from '../tooltips/es_tooltip_property'; import { ES_SIZE_LIMIT } from '../../../common/constants'; import { ESDocField } from '../fields/es_doc_field'; diff --git a/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js b/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js index 6a95165da7566..ed9b284c12826 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js @@ -39,9 +39,13 @@ export class JoinTooltipProperty extends TooltipProperty { for (let i = 0; i < this._leftInnerJoins.length; i++) { const rightSource = this._leftInnerJoins[i].getRightJoinSource(); const termField = rightSource.getTermField(); - const esTooltipProperty = await termField.createTooltipProperty(this._tooltipProperty.getRawValue()); - if (esTooltipProperty) { - esFilters.push(...(await esTooltipProperty.getESFilters())); + try { + const esTooltipProperty = await termField.createTooltipProperty(this._tooltipProperty.getRawValue()); + if (esTooltipProperty) { + esFilters.push(...(await esTooltipProperty.getESFilters())); + } + } catch(e) { + console.error('Cannot create joined filter', e); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 0a6312fe8b750..f8478a43b49cf 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -91,7 +91,7 @@ export class VectorLayer extends AbstractLayer { this._joins = []; if (options.layerDescriptor.joins) { options.layerDescriptor.joins.forEach((joinDescriptor) => { - const join = new InnerJoin(joinDescriptor, this._source.getInspectorAdapters()); + const join = new InnerJoin(joinDescriptor, this._source); this._joins.push(join); }); } From 940abdcfb8d296906bde765a1b1033baca6d15ed Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 09:46:04 -0400 Subject: [PATCH 011/112] fix test --- .../public/layers/joins/inner_join.test.js | 18 +++++++++++++++--- .../es_search_source/es_search_source.js | 2 -- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js index c493062723470..4eb50e900fb52 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js @@ -25,10 +25,22 @@ const rightSource = { term: 'geo.dest', }; +const mockSource = { + getInspectorAdapters() { + }, + createField(name) { + return { + getName() { + return name; + } + }; + } +}; + const leftJoin = new InnerJoin({ leftField: 'iso2', right: rightSource -}); +}, mockSource); const COUNT_PROPERTY_NAME = '__kbnjoin__count_groupby_kibana_sample_data_logs.geo.dest'; describe('joinPropertiesToFeature', () => { @@ -76,7 +88,7 @@ describe('joinPropertiesToFeature', () => { const leftJoin = new InnerJoin({ leftField: 'zipcode', right: rightSource - }); + }, mockSource); const feature = { properties: { @@ -118,7 +130,7 @@ describe('joinPropertiesToFeature', () => { const leftJoin = new InnerJoin({ leftField: 'code', right: rightSource - }); + }, mockSource); const feature = { properties: { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index e938276e866f3..ca7b396c149aa 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -79,8 +79,6 @@ export class ESSearchSource extends AbstractESSource { } renderSourceSettingsEditor({ onChange }) { - - return ( Date: Thu, 24 Oct 2019 09:54:09 -0400 Subject: [PATCH 012/112] fix tooltip test --- .../__snapshots__/tooltip_selector.test.js.snap | 3 +++ .../public/components/tooltip_selector.test.js | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/__snapshots__/tooltip_selector.test.js.snap b/x-pack/legacy/plugins/maps/public/components/__snapshots__/tooltip_selector.test.js.snap index 97dd1f6566e07..4524f66c0642c 100644 --- a/x-pack/legacy/plugins/maps/public/components/__snapshots__/tooltip_selector.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/components/__snapshots__/tooltip_selector.test.js.snap @@ -41,6 +41,7 @@ exports[`TooltipSelector should render component 1`] = ` "type": "string", }, Object { + "label": "foobar_label", "name": "iso3", "type": "string", }, @@ -50,7 +51,9 @@ exports[`TooltipSelector should render component 1`] = ` selectedFields={ Array [ Object { + "label": "foobar_label", "name": "iso2", + "type": "foobar_type", }, ] } diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js index 8d62d2946c188..c5ba55676bbb7 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js @@ -22,11 +22,11 @@ class MockField { } async getLabel() { - return this._label; + return this._label || 'foobar_label'; } async getType() { - return this._type; + return this._type || 'foobar_type'; } } @@ -48,15 +48,22 @@ const defaultProps = { describe('TooltipSelector', () => { - test('should render component', async () => { + test('should render component', (done) => { + const component = shallow( ); - expect(component) - .toMatchSnapshot(); + setTimeout(() => { + component.update(); + expect(component) + .toMatchSnapshot(); + done(); + }); + + }); }); From ab9bd8ea5d3a29f2d3ecc54e216001c39d5e8c83 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 09:56:38 -0400 Subject: [PATCH 013/112] update search source test --- .../__snapshots__/update_source_editor.test.js.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/__snapshots__/update_source_editor.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/__snapshots__/update_source_editor.test.js.snap index c0e443758ada6..4bfa1ef79cc99 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/__snapshots__/update_source_editor.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/__snapshots__/update_source_editor.test.js.snap @@ -13,7 +13,7 @@ exports[`should enable sort order select when sort field provided 1`] = ` Date: Thu, 24 Oct 2019 11:09:55 -0400 Subject: [PATCH 014/112] start on aggmetrics --- .../maps/public/layers/fields/es_agg_field.js | 26 ++++++++++++++++++- .../maps/public/layers/fields/field.js | 2 +- .../maps/public/layers/joins/inner_join.js | 4 +-- .../public/layers/sources/es_agg_source.js | 16 ++++++++++++ .../es_geo_grid_source/es_geo_grid_source.js | 4 +-- .../es_search_source/es_search_source.js | 2 +- .../maps/public/layers/sources/es_source.js | 9 +------ .../maps/public/layers/vector_layer.js | 8 +++--- 8 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 70fdeba2f346b..03b33fbd59a59 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -7,6 +7,30 @@ import { AbstractField } from './field'; -export class ESAggField extends AbstractField { + +export class ESAggMetricField extends AbstractField { + static type = 'ES_AGG'; + + constructor({ fieldName, label, source, aggType, esDocField }) { + super({ fieldName, source }); + this._label = label; + this._aggType = aggType; + this._esDocField = esDocField; + } + + async getLabel() { + return this._label; + } + + getAggType() { + return this._aggType; + } + + getESDocField() { + return this._esDocField; + } + + + } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index c21d45df729df..dfe9f9ac52ad5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -30,7 +30,7 @@ export class AbstractField { return this._fieldName; } - createTooltipProperty() { + async createTooltipProperty() { throw new Error('must implement Field#createTooltipProperty'); } diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 5849248141fe4..3c5e3c8508dc5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -46,8 +46,8 @@ export class InnerJoin { return `join_source_${this._rightSource.getId()}`; } - getLeftFieldName() { - return this._leftField ? this._leftField.getName() : null; + getLeftField() { + return this._leftField; } joinPropertiesToFeature(feature, propertiesMap, rightMetricFields) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js new file mode 100644 index 0000000000000..42986b2fd7001 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -0,0 +1,16 @@ +/* + * 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 { AbstractESSource } from './es_source'; + +export class AbstractESAggSource extends AbstractESSource { + + constructor(descriptor, inspectorAdapters) { + super(descriptor, inspectorAdapters); + this._metricFields = []; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 97411c9030217..5ce3199f111ba 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -8,7 +8,6 @@ import React from 'react'; import uuid from 'uuid/v4'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; -import { AbstractESSource } from '../es_source'; import { HeatmapLayer } from '../../heatmap_layer'; import { VectorLayer } from '../../vector_layer'; import { Schemas } from 'ui/vis/editors/default/schemas'; @@ -24,6 +23,7 @@ import { GRID_RESOLUTION } from '../../grid_resolution'; import { SOURCE_DATA_ID_ORIGIN, ES_GEO_GRID } from '../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; +import { AbstractESAggSource } from '../es_agg_source'; const COUNT_PROP_LABEL = 'count'; const COUNT_PROP_NAME = 'doc_count'; @@ -51,7 +51,7 @@ const aggSchemas = new Schemas([ } ]); -export class ESGeoGridSource extends AbstractESSource { +export class ESGeoGridSource extends AbstractESAggSource { static type = ES_GEO_GRID; static title = i18n.translate('xpack.maps.source.esGridTitle', { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index ca7b396c149aa..c1a1c60904ad0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -118,7 +118,7 @@ export class ESSearchSource extends AbstractESSource { } getMetricFields() { - return []; + throw new Error('todo remove unused method'); } getFieldNames() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 1f0661bc162c0..abf3a94bac8d9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -59,14 +59,7 @@ export class AbstractESSource extends AbstractVectorSource { _getValidMetrics() { const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => { - if (type === 'count') { - return true; - } - - if (field) { - return true; - } - return false; + return (type === 'count') ? true : !!field; }); if (metrics.length === 0) { metrics.push({ type: 'count' }); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index f8478a43b49cf..01d0903916427 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -421,7 +421,7 @@ export class VectorLayer extends AbstractLayer { } = await joinSource.getPropertiesMap( searchFilters, leftSourceName, - join.getLeftFieldName(), + join.getLeftField().getName(), registerCancelCallback.bind(null, requestToken)); stopLoading(sourceDataId, requestToken, propertiesMap); return { @@ -453,9 +453,7 @@ export class VectorLayer extends AbstractLayer { const fieldNames = [ ...this._source.getFieldNames(), ...this._style.getSourceFieldNames(), - ...this.getValidJoins().map(join => { - return join.getLeftFieldName(); - }) + ...this.getValidJoins().map(join => join.getLeftField().getName()) ]; return { @@ -786,7 +784,7 @@ export class VectorLayer extends AbstractLayer { const tooltipProperty = tooltipsFromSource[i]; const matchingJoins = []; for (let j = 0; j < this._joins.length; j++) { - if (this._joins[j].getLeftFieldName() === tooltipProperty.getPropertyKey()) { + if (this._joins[j].getLeftField().getName() === tooltipProperty.getPropertyKey()) { matchingJoins.push(this._joins[j]); } } From 1552260ba26a7c383e992fc454a5d4c7cf0fc5e2 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 11:16:36 -0400 Subject: [PATCH 015/112] isolate metrics --- .../public/layers/sources/es_agg_source.js | 69 +++++++++++++++++++ .../es_pew_pew_source/es_pew_pew_source.js | 4 +- .../maps/public/layers/sources/es_source.js | 69 ------------------- .../public/layers/sources/es_term_source.js | 4 +- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 42986b2fd7001..83e6af28db0ab 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -6,6 +6,8 @@ import { AbstractESSource } from './es_source'; +import _ from 'lodash'; +import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; export class AbstractESAggSource extends AbstractESSource { @@ -13,4 +15,71 @@ export class AbstractESAggSource extends AbstractESSource { super(descriptor, inspectorAdapters); this._metricFields = []; } + + _getValidMetrics() { + const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => { + return (type === 'count') ? true : !!field; + }); + if (metrics.length === 0) { + metrics.push({ type: 'count' }); + } + return metrics; + } + + _formatMetricKey() { + throw new Error('should implement'); + } + + _formatMetricLabel() { + throw new Error('should implement'); + } + + getMetricFields() { + return this._getValidMetrics().map(metric => { + const metricKey = this._formatMetricKey(metric); + const metricLabel = metric.label ? metric.label : this._formatMetricLabel(metric); + const metricCopy = { ...metric }; + delete metricCopy.label; + return { + ...metricCopy, + propertyKey: metricKey, + propertyLabel: metricLabel + }; + }); + } + + async filterAndFormatPropertiesToHtmlForMetricFields(properties) { + let indexPattern; + try { + indexPattern = await this.getIndexPattern(); + } catch(error) { + console.warn(`Unable to find Index pattern ${this._descriptor.indexPatternId}, values are not formatted`); + return properties; + } + + + const metricFields = this.getMetricFields(); + const tooltipProperties = []; + metricFields.forEach((metricField) => { + let value; + for (const key in properties) { + if (properties.hasOwnProperty(key) && metricField.propertyKey === key) { + value = properties[key]; + break; + } + } + + const tooltipProperty = new ESAggMetricTooltipProperty( + metricField.propertyKey, + metricField.propertyLabel, + value, + indexPattern, + metricField + ); + tooltipProperties.push(tooltipProperty); + }); + + return tooltipProperties; + + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 2f0cc451008f7..5ea949588ba0b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -8,7 +8,6 @@ import React from 'react'; import uuid from 'uuid/v4'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; -import { AbstractESSource } from '../es_source'; import { VectorLayer } from '../../vector_layer'; import { CreateSourceEditor } from './create_source_editor'; import { UpdateSourceEditor } from './update_source_editor'; @@ -20,6 +19,7 @@ import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { convertToLines } from './convert_to_lines'; import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; +import { AbstractESAggSource } from '../es_agg_source'; const COUNT_PROP_LABEL = 'count'; const COUNT_PROP_NAME = 'doc_count'; @@ -39,7 +39,7 @@ const aggSchemas = new Schemas([ } ]); -export class ESPewPewSource extends AbstractESSource { +export class ESPewPewSource extends AbstractESAggSource { static type = ES_PEW_PEW; static title = i18n.translate('xpack.maps.source.pewPewTitle', { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index abf3a94bac8d9..f420c78de98be 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -15,8 +15,6 @@ import { timefilter } from 'ui/timefilter'; import _ from 'lodash'; import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; -import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; - import uuid from 'uuid/v4'; import { copyPersistentState } from '../../reducers/util'; import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; @@ -57,73 +55,6 @@ export class AbstractESSource extends AbstractVectorSource { return clonedDescriptor; } - _getValidMetrics() { - const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => { - return (type === 'count') ? true : !!field; - }); - if (metrics.length === 0) { - metrics.push({ type: 'count' }); - } - return metrics; - } - - _formatMetricKey() { - throw new Error('should implement'); - } - - _formatMetricLabel() { - throw new Error('should implement'); - } - - getMetricFields() { - return this._getValidMetrics().map(metric => { - const metricKey = this._formatMetricKey(metric); - const metricLabel = metric.label ? metric.label : this._formatMetricLabel(metric); - const metricCopy = { ...metric }; - delete metricCopy.label; - return { - ...metricCopy, - propertyKey: metricKey, - propertyLabel: metricLabel - }; - }); - } - - async filterAndFormatPropertiesToHtmlForMetricFields(properties) { - let indexPattern; - try { - indexPattern = await this.getIndexPattern(); - } catch(error) { - console.warn(`Unable to find Index pattern ${this._descriptor.indexPatternId}, values are not formatted`); - return properties; - } - - - const metricFields = this.getMetricFields(); - const tooltipProperties = []; - metricFields.forEach((metricField) => { - let value; - for (const key in properties) { - if (properties.hasOwnProperty(key) && metricField.propertyKey === key) { - value = properties[key]; - break; - } - } - - const tooltipProperty = new ESAggMetricTooltipProperty( - metricField.propertyKey, - metricField.propertyLabel, - value, - indexPattern, - metricField - ); - tooltipProperties.push(tooltipProperty); - }); - - return tooltipProperties; - - } - async _runEsQuery(requestName, searchSource, registerCancelCallback, requestDescription) { const abortController = new AbortController(); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 740ac200610c1..4cd8dd69df7f0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -6,12 +6,12 @@ import _ from 'lodash'; -import { AbstractESSource } from './es_source'; import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; import { ES_SIZE_LIMIT } from '../../../common/constants'; import { ESDocField } from '../fields/es_doc_field'; +import { AbstractESAggSource } from './es_agg_source'; const TERMS_AGG_NAME = 'join'; @@ -54,7 +54,7 @@ export function extractPropertiesMap(rawEsData, propertyNames, countPropertyName return propertiesMap; } -export class ESTermSource extends AbstractESSource { +export class ESTermSource extends AbstractESAggSource { static type = 'ES_TERM_SOURCE'; From b6607e4e3ff3fc5825c9a94e23d0143501c98fe3 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 14:10:34 -0400 Subject: [PATCH 016/112] temp --- .../maps/public/layers/fields/es_agg_field.js | 7 ++-- .../public/layers/sources/es_agg_source.js | 36 +++++++++++++++---- .../es_geo_grid_source/es_geo_grid_source.js | 24 +++---------- .../es_pew_pew_source/es_pew_pew_source.js | 24 +++---------- .../public/layers/sources/es_term_source.js | 8 ++--- 5 files changed, 44 insertions(+), 55 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 03b33fbd59a59..d003f2a368bd1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -12,11 +12,12 @@ export class ESAggMetricField extends AbstractField { static type = 'ES_AGG'; - constructor({ fieldName, label, source, aggType, esDocField }) { - super({ fieldName, source }); + constructor({ label, source, aggType, esDocField }) { + super({}); this._label = label; this._aggType = aggType; this._esDocField = esDocField; + this._source = source; } async getLabel() { @@ -31,6 +32,4 @@ export class ESAggMetricField extends AbstractField { return this._esDocField; } - - } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 83e6af28db0ab..03884af5e01db 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -8,12 +8,28 @@ import { AbstractESSource } from './es_source'; import _ from 'lodash'; import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; +import { ESAggMetricField } from '../fields/es_agg_field'; +import { ESDocField } from '../fields/es_doc_field'; + +const COUNT_PROP_LABEL = 'count'; +const COUNT_PROP_NAME = 'doc_count'; export class AbstractESAggSource extends AbstractESSource { + static COUNT_PROP_LABEL = COUNT_PROP_LABEL; + static COUNT_PROP_NANE = COUNT_PROP_NAME; + constructor(descriptor, inspectorAdapters) { super(descriptor, inspectorAdapters); - this._metricFields = []; + this._metricFields = this._descriptor.metrics ? this._descriptor.metrics.map(metric => { + const esDocField = new ESDocField({ fieldName: metric.field }); + return new ESAggMetricField({ + label: metric.label, + esDocField: esDocField, + aggType: metric.type, + source: this + }); + }) : []; } _getValidMetrics() { @@ -26,18 +42,18 @@ export class AbstractESAggSource extends AbstractESSource { return metrics; } - _formatMetricKey() { - throw new Error('should implement'); + formatMetricKey(type, fieldName) { + return type !== 'count' ? `${type}_of_${fieldName}` : COUNT_PROP_NAME; } - _formatMetricLabel() { - throw new Error('should implement'); + formatMetricLabel(type, fieldName) { + return type !== 'count' ? `${type} of ${fieldName}` : COUNT_PROP_LABEL; } getMetricFields() { return this._getValidMetrics().map(metric => { - const metricKey = this._formatMetricKey(metric); - const metricLabel = metric.label ? metric.label : this._formatMetricLabel(metric); + const metricKey = this.formatMetricKey(metric.type, metric.field); + const metricLabel = metric.label ? metric.label : this.formatMetricLabel(metric.type, metric.field); const metricCopy = { ...metric }; delete metricCopy.label; return { @@ -48,6 +64,12 @@ export class AbstractESAggSource extends AbstractESSource { }); } + async getNumberFields() { + return this.getMetricFields().map(({ propertyKey: name, propertyLabel: label }) => { + return { label, name }; + }); + } + async filterAndFormatPropertiesToHtmlForMetricFields(properties) { let indexPattern; try { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 5ce3199f111ba..90be9cc900333 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -25,8 +25,6 @@ import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { AbstractESAggSource } from '../es_agg_source'; -const COUNT_PROP_LABEL = 'count'; -const COUNT_PROP_NAME = 'doc_count'; const MAX_GEOTILE_LEVEL = 29; const aggSchemas = new Schemas([ @@ -177,12 +175,6 @@ export class ESGeoGridSource extends AbstractESAggSource { })); } - async getNumberFields() { - return this.getMetricFields().map(({ propertyKey: name, propertyLabel: label }) => { - return { label, name }; - }); - } - async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { const indexPattern = await this.getIndexPattern(); const searchSource = await this._makeSearchSource(searchFilters, 0); @@ -214,14 +206,6 @@ export class ESGeoGridSource extends AbstractESAggSource { return true; } - _formatMetricKey(metric) { - return metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : COUNT_PROP_NAME; - } - - _formatMetricLabel(metric) { - return metric.type !== 'count' ? `${metric.type} of ${metric.field}` : COUNT_PROP_LABEL; - } - _makeAggConfigs(precision) { const metricAggConfigs = this.getMetricFields().map(metric => { const metricAggConfig = { @@ -270,8 +254,8 @@ export class ESGeoGridSource extends AbstractESAggSource { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { - label: COUNT_PROP_LABEL, - name: COUNT_PROP_NAME, + label: AbstractESAggSource.COUNT_PROP_LABEL, + name: AbstractESAggSource.COUNT_PROP_NANE, origin: SOURCE_DATA_ID_ORIGIN }, color: 'Blues' @@ -281,8 +265,8 @@ export class ESGeoGridSource extends AbstractESAggSource { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { - label: COUNT_PROP_LABEL, - name: COUNT_PROP_NAME, + label: AbstractESAggSource.COUNT_PROP_LABEL, + name: AbstractESAggSource.COUNT_PROP_NANE, origin: SOURCE_DATA_ID_ORIGIN }, minSize: 4, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 5ea949588ba0b..0c3d83c935dcf 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -21,8 +21,6 @@ import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; import { AbstractESAggSource } from '../es_agg_source'; -const COUNT_PROP_LABEL = 'count'; -const COUNT_PROP_NAME = 'doc_count'; const MAX_GEOTILE_LEVEL = 29; const aggSchemas = new Schemas([ @@ -96,12 +94,6 @@ export class ESPewPewSource extends AbstractESAggSource { return true; } - async getNumberFields() { - return this.getMetricFields().map(({ propertyKey: name, propertyLabel: label }) => { - return { label, name }; - }); - } - async getSupportedShapeTypes() { return [VECTOR_SHAPE_TYPES.LINE]; } @@ -146,8 +138,8 @@ export class ESPewPewSource extends AbstractESAggSource { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { - label: COUNT_PROP_LABEL, - name: COUNT_PROP_NAME, + label: AbstractESAggSource.COUNT_PROP_LABEL, + name: AbstractESAggSource.COUNT_PROP_NANE, origin: SOURCE_DATA_ID_ORIGIN }, color: 'Blues' @@ -157,8 +149,8 @@ export class ESPewPewSource extends AbstractESAggSource { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { - label: COUNT_PROP_LABEL, - name: COUNT_PROP_NAME, + label: AbstractESAggSource.COUNT_PROP_LABEL, + name: AbstractESAggSource.COUNT_PROP_NANE, origin: SOURCE_DATA_ID_ORIGIN }, minSize: 4, @@ -251,14 +243,6 @@ export class ESPewPewSource extends AbstractESAggSource { }; } - _formatMetricKey(metric) { - return metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : COUNT_PROP_NAME; - } - - _formatMetricLabel(metric) { - return metric.type !== 'count' ? `${metric.type} of ${metric.field}` : COUNT_PROP_LABEL; - } - async _getGeoField() { const indexPattern = await this.getIndexPattern(); const geoField = indexPattern.fields.getByName(this._descriptor.destGeoField); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 4cd8dd69df7f0..71fbcb94d76b3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -84,13 +84,13 @@ export class ESTermSource extends AbstractESAggSource { return this._descriptor.whereQuery; } - _formatMetricKey(metric) { - const metricKey = metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : metric.type; + formatMetricKey(type, fieldName) { + const metricKey = type !== 'count' ? `${type}_of_${fieldName}` : type; return `__kbnjoin__${metricKey}_groupby_${this._descriptor.indexPatternTitle}.${this._termField.getName()}`; } - _formatMetricLabel(metric) { - const metricLabel = metric.type !== 'count' ? `${metric.type} ${metric.field}` : 'count'; + formatMetricLabel(type, fieldName) { + const metricLabel = type !== 'count' ? `${type} ${fieldName}` : 'count'; return `${metricLabel} of ${this._descriptor.indexPatternTitle}:${this._termField.getName()}`; } From 373a362aa31874099f477843e1e72d7cb83a34a3 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 14:40:21 -0400 Subject: [PATCH 017/112] tmp --- .../maps/public/layers/fields/es_agg_field.js | 21 ++++++++++++++-- .../public/layers/sources/es_agg_source.js | 25 +++++++++++-------- .../public/layers/sources/es_term_source.js | 4 +-- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index d003f2a368bd1..e17fb96507bf5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -13,17 +13,20 @@ export class ESAggMetricField extends AbstractField { static type = 'ES_AGG'; constructor({ label, source, aggType, esDocField }) { - super({}); + super({ source }); this._label = label; this._aggType = aggType; this._esDocField = esDocField; - this._source = source; } async getLabel() { return this._label; } + getLabelSync() { + return this._label; + } + getAggType() { return this._aggType; } @@ -32,4 +35,18 @@ export class ESAggMetricField extends AbstractField { return this._esDocField; } + getPropertyKey() { + } + + getPropertyLabel() { + } + + _getESDocFieldName() { + return this._esDocField ? this._esDocField.getName() : ''; + } + + getRequestDescription() { + return this.getAggType() !== 'count' ? `${this.getAggType()} ${this._getESDocFieldName()}` : 'count'; + } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 03884af5e01db..01426023d1800 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -6,7 +6,6 @@ import { AbstractESSource } from './es_source'; -import _ from 'lodash'; import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; import { ESAggMetricField } from '../fields/es_agg_field'; import { ESDocField } from '../fields/es_doc_field'; @@ -22,7 +21,7 @@ export class AbstractESAggSource extends AbstractESSource { constructor(descriptor, inspectorAdapters) { super(descriptor, inspectorAdapters); this._metricFields = this._descriptor.metrics ? this._descriptor.metrics.map(metric => { - const esDocField = new ESDocField({ fieldName: metric.field }); + const esDocField = metric.field ? new ESDocField({ fieldName: metric.field }) : null; return new ESAggMetricField({ label: metric.label, esDocField: esDocField, @@ -33,11 +32,15 @@ export class AbstractESAggSource extends AbstractESSource { } _getValidMetrics() { - const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => { - return (type === 'count') ? true : !!field; + const metrics = this._metricFields.filter(esAggField => { + return (esAggField.getAggType() === 'count') ? true : !!esAggField.getESDocField(); }); if (metrics.length === 0) { - metrics.push({ type: 'count' }); + // metrics.push({ type: 'count' }); + metrics.push(new ESAggMetricField({ + aggType: 'count', + source: this + })); } return metrics; } @@ -51,13 +54,13 @@ export class AbstractESAggSource extends AbstractESSource { } getMetricFields() { - return this._getValidMetrics().map(metric => { - const metricKey = this.formatMetricKey(metric.type, metric.field); - const metricLabel = metric.label ? metric.label : this.formatMetricLabel(metric.type, metric.field); - const metricCopy = { ...metric }; - delete metricCopy.label; + return this._getValidMetrics().map(esAggMetric => { + const metricKey = this.formatMetricKey(esAggMetric.getAggType(), esAggMetric._getESDocFieldName()); + // eslint-disable-next-line max-len + const metricLabel = esAggMetric.getLabelSync() ? esAggMetric.getLabelSync() : this.formatMetricLabel(esAggMetric.getAggType(), esAggMetric._getESDocFieldName()); return { - ...metricCopy, + type: esAggMetric.getAggType(), + field: esAggMetric._getESDocFieldName(), propertyKey: metricKey, propertyLabel: metricLabel }; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 71fbcb94d76b3..44e5ffc4d5205 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -131,9 +131,7 @@ export class ESTermSource extends AbstractESAggSource { } _getRequestDescription(leftSourceName, leftFieldName) { - const metrics = this._getValidMetrics().map(metric => { - return metric.type !== 'count' ? `${metric.type} ${metric.field}` : 'count'; - }); + const metrics = this._getValidMetrics().map(esAggMetric => esAggMetric.getRequestDescription()); const joinStatement = []; joinStatement.push(i18n.translate('xpack.maps.source.esJoin.joinLeftDescription', { defaultMessage: `Join {leftSourceName}:{leftFieldName} with`, From f883bfc305f94f365b1b22d4ec574ea0692bd335 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 14:45:27 -0400 Subject: [PATCH 018/112] more IOC --- .../plugins/maps/public/layers/fields/es_agg_field.js | 6 ++---- .../plugins/maps/public/layers/sources/es_agg_source.js | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index e17fb96507bf5..8aa739327745e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -23,10 +23,6 @@ export class ESAggMetricField extends AbstractField { return this._label; } - getLabelSync() { - return this._label; - } - getAggType() { return this._aggType; } @@ -36,9 +32,11 @@ export class ESAggMetricField extends AbstractField { } getPropertyKey() { + return this._source.formatMetricKey(this.getAggType(), this._getESDocFieldName()); } getPropertyLabel() { + return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this._getESDocFieldName()); } _getESDocFieldName() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 01426023d1800..38c2261380207 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -55,9 +55,8 @@ export class AbstractESAggSource extends AbstractESSource { getMetricFields() { return this._getValidMetrics().map(esAggMetric => { - const metricKey = this.formatMetricKey(esAggMetric.getAggType(), esAggMetric._getESDocFieldName()); - // eslint-disable-next-line max-len - const metricLabel = esAggMetric.getLabelSync() ? esAggMetric.getLabelSync() : this.formatMetricLabel(esAggMetric.getAggType(), esAggMetric._getESDocFieldName()); + const metricKey = esAggMetric.getPropertyKey(); + const metricLabel = esAggMetric.getPropertyLabel(); return { type: esAggMetric.getAggType(), field: esAggMetric._getESDocFieldName(), From f9c82f3addc1ddf7044628bb519124bd4d041cb4 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:04:53 -0400 Subject: [PATCH 019/112] tmp --- .../plugins/maps/public/layers/fields/es_agg_field.js | 8 ++++---- x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js | 8 ++++---- .../plugins/maps/public/layers/sources/es_agg_source.js | 6 +++++- .../plugins/maps/public/layers/sources/es_source.js | 7 ++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 8aa739327745e..47dc947734451 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -32,19 +32,19 @@ export class ESAggMetricField extends AbstractField { } getPropertyKey() { - return this._source.formatMetricKey(this.getAggType(), this._getESDocFieldName()); + return this._source.formatMetricKey(this.getAggType(), this.getESDocFieldName()); } getPropertyLabel() { - return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this._getESDocFieldName()); + return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this.getESDocFieldName()); } - _getESDocFieldName() { + getESDocFieldName() { return this._esDocField ? this._esDocField.getName() : ''; } getRequestDescription() { - return this.getAggType() !== 'count' ? `${this.getAggType()} ${this._getESDocFieldName()}` : 'count'; + return this.getAggType() !== 'count' ? `${this.getAggType()} ${this.getESDocFieldName()}` : 'count'; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 629fb3284ff11..5772b18e1dc7a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import _ from 'lodash'; import { AbstractLayer } from './layer'; import { VectorLayer } from './vector_layer'; import { HeatmapStyle } from './styles/heatmap_style'; @@ -32,8 +31,8 @@ export class HeatmapLayer extends VectorLayer { } _getPropKeyOfSelectedMetric() { - const metricfields = this._source.getMetricFields(); - return metricfields[0].propertyKey; + const metricfields = this._source.getMetricFields2(); + return metricfields[0].getPropertyKey(); } _getHeatmapLayerId() { @@ -102,7 +101,8 @@ export class HeatmapLayer extends VectorLayer { } getLegendDetails() { - const label = _.get(this._source.getMetricFields(), '[0].propertyLabel', ''); + const metricFields = this._source.getMetricFields2(); + const label = metricFields[0].getPropertyLabel(); return this._style.getLegendDetails(label); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 38c2261380207..2777422fce03d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -59,13 +59,17 @@ export class AbstractESAggSource extends AbstractESSource { const metricLabel = esAggMetric.getPropertyLabel(); return { type: esAggMetric.getAggType(), - field: esAggMetric._getESDocFieldName(), + field: esAggMetric.getESDocFieldName(), propertyKey: metricKey, propertyLabel: metricLabel }; }); } + getMetricFields2() { + return this._getValidMetrics(); + } + async getNumberFields() { return this.getMetricFields().map(({ propertyKey: name, propertyLabel: label }) => { return { label, name }; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index f420c78de98be..416d994445522 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -225,11 +225,8 @@ export class AbstractESSource extends AbstractVectorSource { } _getRawFieldName(fieldName) { - const metricField = this.getMetricFields().find(({ propertyKey }) => { - return propertyKey === fieldName; - }); - - return metricField ? metricField.field : null; + const metricField = this.getMetricFields2().find((esAggMetricField) => esAggMetricField.getPropertyKey() === fieldName); + return metricField ? metricField.getESDocFieldName() : null; } async getFieldFormatter(fieldName) { From 26ff04237e64d434d29b6c988a88674a415a09c5 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:24:51 -0400 Subject: [PATCH 020/112] tmp --- .../maps/public/layers/sources/es_agg_source.js | 8 ++++---- .../es_geo_grid_source/es_geo_grid_source.js | 4 +--- .../maps/public/layers/sources/es_term_source.js | 14 ++++++-------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 2777422fce03d..1c60cd6bd4816 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -86,20 +86,20 @@ export class AbstractESAggSource extends AbstractESSource { } - const metricFields = this.getMetricFields(); + const metricFields = this.getMetricFields2(); const tooltipProperties = []; metricFields.forEach((metricField) => { let value; for (const key in properties) { - if (properties.hasOwnProperty(key) && metricField.propertyKey === key) { + if (properties.hasOwnProperty(key) && metricField.getPropertyKey() === key) { value = properties[key]; break; } } const tooltipProperty = new ESAggMetricTooltipProperty( - metricField.propertyKey, - metricField.propertyLabel, + metricField.getPropertyKey(), + metricField.getPropertyLabel(), value, indexPattern, metricField diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 90be9cc900333..a936ae00067c2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -132,9 +132,7 @@ export class ESGeoGridSource extends AbstractESAggSource { } getFieldNames() { - return this.getMetricFields().map(({ propertyKey }) => { - return propertyKey; - }); + return this.getMetricFields2().map((esAggMetricField => esAggMetricField.getPropertyKey())); } isGeoGridPrecisionAware() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 44e5ffc4d5205..cd6ea928b3ad8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -151,16 +151,16 @@ export class ESTermSource extends AbstractESAggSource { } _makeAggConfigs() { - const metricAggConfigs = this.getMetricFields().map(metric => { + const metricAggConfigs = this.getMetricFields2().map(esAggMetric => { const metricAggConfig = { - id: metric.propertyKey, + id: esAggMetric.getPropertyKey(), enabled: true, - type: metric.type, + type: esAggMetric.getAggType(), schema: 'metric', params: {} }; - if (metric.type !== 'count') { - metricAggConfig.params = { field: metric.field }; + if (esAggMetric.getAggType() !== 'count') { + metricAggConfig.params = { field: esAggMetric.getESDocFieldName() }; } return metricAggConfig; }); @@ -190,8 +190,6 @@ export class ESTermSource extends AbstractESAggSource { } getFieldNames() { - return this.getMetricFields().map(({ propertyKey }) => { - return propertyKey; - }); + return this.getMetricFields2().map(esAggMetricField => esAggMetricField.getPropertyKey()); } } From 850686af1dae34914504e454fd6c94b385bafa6b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:30:35 -0400 Subject: [PATCH 021/112] more removal --- .../sources/es_geo_grid_source/es_geo_grid_source.js | 10 +++++----- .../sources/es_pew_pew_source/es_pew_pew_source.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index a936ae00067c2..e2813ec63fee3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -205,16 +205,16 @@ export class ESGeoGridSource extends AbstractESAggSource { } _makeAggConfigs(precision) { - const metricAggConfigs = this.getMetricFields().map(metric => { + const metricAggConfigs = this.getMetricFields2().map(esAggMetricField => { const metricAggConfig = { - id: metric.propertyKey, + id: esAggMetricField.getPropertyKey(), enabled: true, - type: metric.type, + type: esAggMetricField.getAggType(), schema: 'metric', params: {} }; - if (metric.type !== 'count') { - metricAggConfig.params = { field: metric.field }; + if (esAggMetricField.getAggType() !== 'count') { + metricAggConfig.params = { field: esAggMetricField.getESDocFieldName() }; } return metricAggConfig; }); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 0c3d83c935dcf..c0baf1c6e0f72 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -177,16 +177,16 @@ export class ESPewPewSource extends AbstractESAggSource { async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { const indexPattern = await this.getIndexPattern(); - const metricAggConfigs = this.getMetricFields().map(metric => { + const metricAggConfigs = this.getMetricFields2().map(esAggMetricField => { const metricAggConfig = { - id: metric.propertyKey, + id: esAggMetricField.getPropertyKey(), enabled: true, - type: metric.type, + type: esAggMetricField.getAggType(), schema: 'metric', params: {} }; - if (metric.type !== 'count') { - metricAggConfig.params = { field: metric.field }; + if (esAggMetricField.getAggType() !== 'count') { + metricAggConfig.params = { field: esAggMetricField.getESDocFieldName() }; } return metricAggConfig; }); From 581dc7b475ed5778ed88925ffc31e8e7ecc11eb9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:39:51 -0400 Subject: [PATCH 022/112] remove dupes --- .../maps/public/layers/fields/es_agg_field.js | 14 ++++++++++++++ .../maps/public/layers/sources/es_agg_source.js | 4 ++++ .../es_geo_grid_source/es_geo_grid_source.js | 15 +-------------- .../es_pew_pew_source/es_pew_pew_source.js | 15 ++------------- .../maps/public/layers/sources/es_term_source.js | 15 +-------------- 5 files changed, 22 insertions(+), 41 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 47dc947734451..7962ad33c621f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -47,4 +47,18 @@ export class ESAggMetricField extends AbstractField { return this.getAggType() !== 'count' ? `${this.getAggType()} ${this.getESDocFieldName()}` : 'count'; } + makeMetricAggConfig() { + const metricAggConfig = { + id: this.getPropertyKey(), + enabled: true, + type: this.getAggType(), + schema: 'metric', + params: {} + }; + if (this.getAggType() !== 'count') { + metricAggConfig.params = { field: this.getESDocFieldName() }; + } + return metricAggConfig; + } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 1c60cd6bd4816..a07f0b23862fc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -53,6 +53,10 @@ export class AbstractESAggSource extends AbstractESSource { return type !== 'count' ? `${type} of ${fieldName}` : COUNT_PROP_LABEL; } + createMetricAggConfigs() { + return this.getMetricFields2().map(esAggMetric => esAggMetric.makeMetricAggConfig()); + } + getMetricFields() { return this._getValidMetrics().map(esAggMetric => { const metricKey = esAggMetric.getPropertyKey(); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index e2813ec63fee3..5f7c4fb321e00 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -205,20 +205,7 @@ export class ESGeoGridSource extends AbstractESAggSource { } _makeAggConfigs(precision) { - const metricAggConfigs = this.getMetricFields2().map(esAggMetricField => { - const metricAggConfig = { - id: esAggMetricField.getPropertyKey(), - enabled: true, - type: esAggMetricField.getAggType(), - schema: 'metric', - params: {} - }; - if (esAggMetricField.getAggType() !== 'count') { - metricAggConfig.params = { field: esAggMetricField.getESDocFieldName() }; - } - return metricAggConfig; - }); - + const metricAggConfigs = this.createMetricAggConfigs(); return [ ...metricAggConfigs, { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index c0baf1c6e0f72..f443acaf346f5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -176,20 +176,9 @@ export class ESPewPewSource extends AbstractESAggSource { } async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) { + + const metricAggConfigs = this.createMetricAggConfigs(); const indexPattern = await this.getIndexPattern(); - const metricAggConfigs = this.getMetricFields2().map(esAggMetricField => { - const metricAggConfig = { - id: esAggMetricField.getPropertyKey(), - enabled: true, - type: esAggMetricField.getAggType(), - schema: 'metric', - params: {} - }; - if (esAggMetricField.getAggType() !== 'count') { - metricAggConfig.params = { field: esAggMetricField.getESDocFieldName() }; - } - return metricAggConfig; - }); const aggConfigs = new AggConfigs(indexPattern, metricAggConfigs, aggSchemas.all); const searchSource = await this._makeSearchSource(searchFilters, 0); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index cd6ea928b3ad8..3a982748ed792 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -151,20 +151,7 @@ export class ESTermSource extends AbstractESAggSource { } _makeAggConfigs() { - const metricAggConfigs = this.getMetricFields2().map(esAggMetric => { - const metricAggConfig = { - id: esAggMetric.getPropertyKey(), - enabled: true, - type: esAggMetric.getAggType(), - schema: 'metric', - params: {} - }; - if (esAggMetric.getAggType() !== 'count') { - metricAggConfig.params = { field: esAggMetric.getESDocFieldName() }; - } - return metricAggConfig; - }); - + const metricAggConfigs = this.createMetricAggConfigs(); return [ ...metricAggConfigs, { From 4335c719d6f42abf5648f02de8a6a68ba2ecabfd Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:46:18 -0400 Subject: [PATCH 023/112] more removal --- x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js | 4 ++-- .../plugins/maps/public/layers/sources/es_agg_source.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 3c5e3c8508dc5..26a52958c1cfb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -34,8 +34,8 @@ export class InnerJoin { } getJoinFields() { - return this.getRightMetricFields().map(({ propertyKey: name, propertyLabel: label }) => { - return { label, name }; + return this._rightSource.getMetricFields2().map(esAggMetricField => { + return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getPropertyKey() }; }); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index a07f0b23862fc..411c3003b8826 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -75,8 +75,8 @@ export class AbstractESAggSource extends AbstractESSource { } async getNumberFields() { - return this.getMetricFields().map(({ propertyKey: name, propertyLabel: label }) => { - return { label, name }; + return this.getMetricFields2().map(esAggMetricField => { + return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getPropertyKey() }; }); } From f984ce9eeeae9b1b6fb134f17a550da1eab0f85e Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:54:07 -0400 Subject: [PATCH 024/112] more removal --- .../legacy/plugins/maps/public/layers/joins/inner_join.js | 7 ++++--- .../plugins/maps/public/layers/joins/inner_join.test.js | 1 + x-pack/legacy/plugins/maps/public/layers/vector_layer.js | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 26a52958c1cfb..b2f04dea7f881 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -30,7 +30,7 @@ export class InnerJoin { } getRightMetricFields() { - return this._rightSource.getMetricFields(); + return this._rightSource.getMetricFields2(); } getJoinFields() { @@ -50,10 +50,11 @@ export class InnerJoin { return this._leftField; } - joinPropertiesToFeature(feature, propertiesMap, rightMetricFields) { + joinPropertiesToFeature(feature, propertiesMap) { + const rightMetricFields = this._rightSource.getMetricFields2(); // delete feature properties added by previous join for (let j = 0; j < rightMetricFields.length; j++) { - const { propertyKey: metricPropertyKey } = rightMetricFields[j]; + const metricPropertyKey = rightMetricFields[j].getPropertyKey(); delete feature.properties[metricPropertyKey]; // delete all dynamic properties for metric field diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js index 4eb50e900fb52..12790cae42ba2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js @@ -23,6 +23,7 @@ const rightSource = { indexPatternId: '90943e30-9a47-11e8-b64d-95841ca0b247', indexPatternTitle: 'kibana_sample_data_logs', term: 'geo.dest', + metrics: [{ type: 'count' }] }; const mockSource = { diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 01d0903916427..166d8a1e005eb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -485,9 +485,8 @@ export class VectorLayer extends AbstractLayer { let isFeatureVisible = true; for (let j = 0; j < joinStates.length; j++) { const joinState = joinStates[j]; - const InnerJoin = joinState.join; - const rightMetricFields = InnerJoin.getRightMetricFields(); - const canJoinOnCurrent = InnerJoin.joinPropertiesToFeature(feature, joinState.propertiesMap, rightMetricFields); + const innerJoin = joinState.join; + const canJoinOnCurrent = innerJoin.joinPropertiesToFeature(feature, joinState.propertiesMap); isFeatureVisible = isFeatureVisible && canJoinOnCurrent; } From c52ce3d9279502b8029d572314448d4f866478f3 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 15:57:58 -0400 Subject: [PATCH 025/112] rename --- .../maps/public/layers/joins/inner_join.js | 6 ++--- .../public/layers/sources/es_agg_source.js | 25 +++---------------- .../es_geo_grid_source/es_geo_grid_source.js | 2 +- .../public/layers/sources/es_term_source.js | 4 +-- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index b2f04dea7f881..04e43e592283e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -30,11 +30,11 @@ export class InnerJoin { } getRightMetricFields() { - return this._rightSource.getMetricFields2(); + return this._rightSource.getMetricFields(); } getJoinFields() { - return this._rightSource.getMetricFields2().map(esAggMetricField => { + return this._rightSource.getMetricFields().map(esAggMetricField => { return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getPropertyKey() }; }); } @@ -51,7 +51,7 @@ export class InnerJoin { } joinPropertiesToFeature(feature, propertiesMap) { - const rightMetricFields = this._rightSource.getMetricFields2(); + const rightMetricFields = this._rightSource.getMetricFields(); // delete feature properties added by previous join for (let j = 0; j < rightMetricFields.length; j++) { const metricPropertyKey = rightMetricFields[j].getPropertyKey(); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 411c3003b8826..04dcd0ba9d306 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -31,12 +31,11 @@ export class AbstractESAggSource extends AbstractESSource { }) : []; } - _getValidMetrics() { + getMetricFields() { const metrics = this._metricFields.filter(esAggField => { return (esAggField.getAggType() === 'count') ? true : !!esAggField.getESDocField(); }); if (metrics.length === 0) { - // metrics.push({ type: 'count' }); metrics.push(new ESAggMetricField({ aggType: 'count', source: this @@ -54,28 +53,12 @@ export class AbstractESAggSource extends AbstractESSource { } createMetricAggConfigs() { - return this.getMetricFields2().map(esAggMetric => esAggMetric.makeMetricAggConfig()); - } - - getMetricFields() { - return this._getValidMetrics().map(esAggMetric => { - const metricKey = esAggMetric.getPropertyKey(); - const metricLabel = esAggMetric.getPropertyLabel(); - return { - type: esAggMetric.getAggType(), - field: esAggMetric.getESDocFieldName(), - propertyKey: metricKey, - propertyLabel: metricLabel - }; - }); + return this.getMetricFields().map(esAggMetric => esAggMetric.makeMetricAggConfig()); } - getMetricFields2() { - return this._getValidMetrics(); - } async getNumberFields() { - return this.getMetricFields2().map(esAggMetricField => { + return this.getMetricFields().map(esAggMetricField => { return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getPropertyKey() }; }); } @@ -90,7 +73,7 @@ export class AbstractESAggSource extends AbstractESSource { } - const metricFields = this.getMetricFields2(); + const metricFields = this.getMetricFields(); const tooltipProperties = []; metricFields.forEach((metricField) => { let value; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 5f7c4fb321e00..d2d14783ac168 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -132,7 +132,7 @@ export class ESGeoGridSource extends AbstractESAggSource { } getFieldNames() { - return this.getMetricFields2().map((esAggMetricField => esAggMetricField.getPropertyKey())); + return this.getMetricFields().map((esAggMetricField => esAggMetricField.getPropertyKey())); } isGeoGridPrecisionAware() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 3a982748ed792..fa803ae3b93c3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -131,7 +131,7 @@ export class ESTermSource extends AbstractESAggSource { } _getRequestDescription(leftSourceName, leftFieldName) { - const metrics = this._getValidMetrics().map(esAggMetric => esAggMetric.getRequestDescription()); + const metrics = this.getMetricFields().map(esAggMetric => esAggMetric.getRequestDescription()); const joinStatement = []; joinStatement.push(i18n.translate('xpack.maps.source.esJoin.joinLeftDescription', { defaultMessage: `Join {leftSourceName}:{leftFieldName} with`, @@ -177,6 +177,6 @@ export class ESTermSource extends AbstractESAggSource { } getFieldNames() { - return this.getMetricFields2().map(esAggMetricField => esAggMetricField.getPropertyKey()); + return this.getMetricFields().map(esAggMetricField => esAggMetricField.getPropertyKey()); } } From 60c1aa20025a09f0dc8a1a337a2e90fac132cef8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 16:05:54 -0400 Subject: [PATCH 026/112] tmp --- .../plugins/maps/public/layers/fields/es_agg_field.js | 6 +++++- x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js | 4 ++-- .../legacy/plugins/maps/public/layers/sources/es_source.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 7962ad33c621f..ca093d0de3140 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -19,8 +19,12 @@ export class ESAggMetricField extends AbstractField { this._esDocField = esDocField; } + getName() { + return this.getPropertyKey(); + } + async getLabel() { - return this._label; + return this.getPropertyLabel(); } getAggType() { diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 5772b18e1dc7a..2a93610613245 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -31,7 +31,7 @@ export class HeatmapLayer extends VectorLayer { } _getPropKeyOfSelectedMetric() { - const metricfields = this._source.getMetricFields2(); + const metricfields = this._source.getMetricFields(); return metricfields[0].getPropertyKey(); } @@ -101,7 +101,7 @@ export class HeatmapLayer extends VectorLayer { } getLegendDetails() { - const metricFields = this._source.getMetricFields2(); + const metricFields = this._source.getMetricFields(); const label = metricFields[0].getPropertyLabel(); return this._style.getLegendDetails(label); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 416d994445522..01beadc2e6ed2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -225,7 +225,7 @@ export class AbstractESSource extends AbstractVectorSource { } _getRawFieldName(fieldName) { - const metricField = this.getMetricFields2().find((esAggMetricField) => esAggMetricField.getPropertyKey() === fieldName); + const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getPropertyKey() === fieldName); return metricField ? metricField.getESDocFieldName() : null; } From d7c4a5081e97bad03369962e8d8a5a7546e78457 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 16:16:16 -0400 Subject: [PATCH 027/112] remove shim --- .../plugins/maps/public/layers/fields/es_agg_field.js | 8 ++------ x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js | 2 +- .../legacy/plugins/maps/public/layers/joins/inner_join.js | 8 ++------ .../plugins/maps/public/layers/sources/es_agg_source.js | 6 +++--- .../sources/es_geo_grid_source/es_geo_grid_source.js | 2 +- .../layers/sources/es_search_source/es_search_source.js | 4 ---- .../plugins/maps/public/layers/sources/es_source.js | 2 +- .../plugins/maps/public/layers/sources/es_term_source.js | 2 +- 8 files changed, 11 insertions(+), 23 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index ca093d0de3140..29d77334cff8d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -20,7 +20,7 @@ export class ESAggMetricField extends AbstractField { } getName() { - return this.getPropertyKey(); + return this._source.formatMetricKey(this.getAggType(), this.getESDocFieldName()); } async getLabel() { @@ -35,10 +35,6 @@ export class ESAggMetricField extends AbstractField { return this._esDocField; } - getPropertyKey() { - return this._source.formatMetricKey(this.getAggType(), this.getESDocFieldName()); - } - getPropertyLabel() { return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this.getESDocFieldName()); } @@ -53,7 +49,7 @@ export class ESAggMetricField extends AbstractField { makeMetricAggConfig() { const metricAggConfig = { - id: this.getPropertyKey(), + id: this.getName(), enabled: true, type: this.getAggType(), schema: 'metric', diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 2a93610613245..6a75f388522cd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -32,7 +32,7 @@ export class HeatmapLayer extends VectorLayer { _getPropKeyOfSelectedMetric() { const metricfields = this._source.getMetricFields(); - return metricfields[0].getPropertyKey(); + return metricfields[0].getName(); } _getHeatmapLayerId() { diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 04e43e592283e..9d902ae3e3288 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -29,13 +29,9 @@ export class InnerJoin { return false; } - getRightMetricFields() { - return this._rightSource.getMetricFields(); - } - getJoinFields() { return this._rightSource.getMetricFields().map(esAggMetricField => { - return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getPropertyKey() }; + return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getName() }; }); } @@ -54,7 +50,7 @@ export class InnerJoin { const rightMetricFields = this._rightSource.getMetricFields(); // delete feature properties added by previous join for (let j = 0; j < rightMetricFields.length; j++) { - const metricPropertyKey = rightMetricFields[j].getPropertyKey(); + const metricPropertyKey = rightMetricFields[j].getName(); delete feature.properties[metricPropertyKey]; // delete all dynamic properties for metric field diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 04dcd0ba9d306..b3c1ef242b477 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -59,7 +59,7 @@ export class AbstractESAggSource extends AbstractESSource { async getNumberFields() { return this.getMetricFields().map(esAggMetricField => { - return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getPropertyKey() }; + return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getName() }; }); } @@ -78,14 +78,14 @@ export class AbstractESAggSource extends AbstractESSource { metricFields.forEach((metricField) => { let value; for (const key in properties) { - if (properties.hasOwnProperty(key) && metricField.getPropertyKey() === key) { + if (properties.hasOwnProperty(key) && metricField.getName() === key) { value = properties[key]; break; } } const tooltipProperty = new ESAggMetricTooltipProperty( - metricField.getPropertyKey(), + metricField.getName(), metricField.getPropertyLabel(), value, indexPattern, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index d2d14783ac168..02e41e634a4ef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -132,7 +132,7 @@ export class ESGeoGridSource extends AbstractESAggSource { } getFieldNames() { - return this.getMetricFields().map((esAggMetricField => esAggMetricField.getPropertyKey())); + return this.getMetricFields().map((esAggMetricField => esAggMetricField.getName())); } isGeoGridPrecisionAware() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index c1a1c60904ad0..ad710019265e7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -117,10 +117,6 @@ export class ESSearchSource extends AbstractESSource { } } - getMetricFields() { - throw new Error('todo remove unused method'); - } - getFieldNames() { return [this._descriptor.geoField]; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 01beadc2e6ed2..647d98e96202a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -225,7 +225,7 @@ export class AbstractESSource extends AbstractVectorSource { } _getRawFieldName(fieldName) { - const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getPropertyKey() === fieldName); + const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getName() === fieldName); return metricField ? metricField.getESDocFieldName() : null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index fa803ae3b93c3..68f0e15347d13 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -177,6 +177,6 @@ export class ESTermSource extends AbstractESAggSource { } getFieldNames() { - return this.getMetricFields().map(esAggMetricField => esAggMetricField.getPropertyKey()); + return this.getMetricFields().map(esAggMetricField => esAggMetricField.getName()); } } From 53957c6fc9399473802a7041259dde4c6b8086a2 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 18:19:37 -0400 Subject: [PATCH 028/112] start refactor, this has errors --- .../maps/public/layers/heatmap_layer.js | 2 +- .../es_geo_grid_source/es_geo_grid_source.js | 5 ++-- .../es_pew_pew_source/es_pew_pew_source.js | 5 ++-- .../components/static_dynamic_style_row.js | 9 ++++---- .../legend/style_property_legend_row.js | 4 ++-- .../components/vector/legend/vector_icon.js | 4 ++-- .../vector/legend/vector_icon.test.js | 7 +++--- .../styles/{ => heatmap}/heatmap_style.js | 12 +++++----- .../properties/dynamic_style_property.js | 12 ++++++++++ .../properties/static_style_property.js | 12 ++++++++++ .../vector/properties/style_property.js | 14 +++++++++++ .../maps/public/layers/styles/vector_style.js | 16 ++++++++----- .../public/layers/styles/vector_style.test.js | 13 +++++++---- .../layers/styles/vector_style_defaults.js | 23 ++++++++++--------- .../maps/public/selectors/map_selectors.js | 2 +- 15 files changed, 95 insertions(+), 45 deletions(-) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => heatmap}/heatmap_style.js (88%) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 6a75f388522cd..c766fc5df1faf 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -6,7 +6,7 @@ import { AbstractLayer } from './layer'; import { VectorLayer } from './vector_layer'; -import { HeatmapStyle } from './styles/heatmap_style'; +import { HeatmapStyle } from './styles/heatmap/heatmap_style'; import { EMPTY_FEATURE_COLLECTION, LAYER_TYPE } from '../../common/constants'; const SCALED_PROPERTY_NAME = '__kbn_heatmap_weight__';//unique name to store scaled value for weighting diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 02e41e634a4ef..ad0c1e762883f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -24,6 +24,7 @@ import { SOURCE_DATA_ID_ORIGIN, ES_GEO_GRID } from '../../../../common/constants import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { AbstractESAggSource } from '../es_agg_source'; +import { DynamicStyleProperty } from '../../styles/vector/properties/dynamic_style_property'; const MAX_GEOTILE_LEVEL = 29; @@ -236,7 +237,7 @@ export class ESGeoGridSource extends AbstractESAggSource { }); descriptor.style = VectorStyle.createDescriptor({ [vectorStyles.FILL_COLOR]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { field: { label: AbstractESAggSource.COUNT_PROP_LABEL, @@ -247,7 +248,7 @@ export class ESGeoGridSource extends AbstractESAggSource { } }, [vectorStyles.ICON_SIZE]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { field: { label: AbstractESAggSource.COUNT_PROP_LABEL, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index f443acaf346f5..29671b1e272fe 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -20,6 +20,7 @@ import { convertToLines } from './convert_to_lines'; import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; import { AbstractESAggSource } from '../es_agg_source'; +import { DynamicStyleProperty } from '../../styles/vector/properties/dynamic_style_property'; const MAX_GEOTILE_LEVEL = 29; @@ -135,7 +136,7 @@ export class ESPewPewSource extends AbstractESAggSource { createDefaultLayer(options) { const styleDescriptor = VectorStyle.createDescriptor({ [vectorStyles.LINE_COLOR]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { field: { label: AbstractESAggSource.COUNT_PROP_LABEL, @@ -146,7 +147,7 @@ export class ESPewPewSource extends AbstractESAggSource { } }, [vectorStyles.LINE_WIDTH]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { field: { label: AbstractESAggSource.COUNT_PROP_LABEL, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js index cfe7a0741a194..8c3d415407011 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js @@ -5,7 +5,8 @@ */ import React from 'react'; -import { VectorStyle } from '../vector_style'; +import { DynamicStyleProperty } from '../vector/properties/dynamic_style_property'; +import { StaticStyleProperty } from '../vector/properties/static_style_property'; import _ from 'lodash'; import { i18n } from '@kbn/i18n'; @@ -25,7 +26,7 @@ export class StaticDynamicStyleRow extends React.Component { if (!this.props.styleDescriptor) { return false; } - return this.props.styleDescriptor.type === VectorStyle.STYLE_TYPE.DYNAMIC; + return this.props.styleDescriptor.type === DynamicStyleProperty.type; } _getStyleOptions() { @@ -34,7 +35,7 @@ export class StaticDynamicStyleRow extends React.Component { _onStaticStyleChange = options => { const styleDescriptor = { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options, }; this.props.handlePropertyChange(this.props.property, styleDescriptor); @@ -42,7 +43,7 @@ export class StaticDynamicStyleRow extends React.Component { _onDynamicStyleChange = options => { const styleDescriptor = { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options, }; this.props.handlePropertyChange(this.props.property, styleDescriptor); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js index 2f8a603c290ab..ee66d859449d1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js @@ -9,7 +9,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { styleOptionShapes, rangeShape } from '../style_option_shapes'; -import { VectorStyle } from '../../../vector_style'; +import { StaticStyleProperty } from '../../../vector/properties/static_style_property'; import { ColorGradient } from '../../color_gradient'; import { CircleIcon } from './circle_icon'; import { getVectorStyleLabel } from '../get_vector_style_label'; @@ -121,7 +121,7 @@ export class StylePropertyLegendRow extends Component { } _isStatic() { - return this.props.type === VectorStyle.STYLE_TYPE.STATIC || + return this.props.type === StaticStyleProperty.type || !this.props.options.field || !this.props.options.field.name; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js index 0f9e76c3e74d9..d393ed1c85c3f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js @@ -12,7 +12,7 @@ import { CircleIcon } from './circle_icon'; import { LineIcon } from './line_icon'; import { PolygonIcon } from './polygon_icon'; import { SymbolIcon } from './symbol_icon'; -import { VectorStyle } from '../../../vector_style'; +import { StaticStyleProperty } from '../../../vector/properties/static_style_property'; import { getColorRampCenterColor } from '../../../color_utils'; export class VectorIcon extends Component { @@ -87,7 +87,7 @@ function extractColorFromStyleProperty(colorStyleProperty, defaultColor) { return defaultColor; } - if (colorStyleProperty.type === VectorStyle.STYLE_TYPE.STATIC) { + if (colorStyleProperty.type === StaticStyleProperty.type) { return colorStyleProperty.options.color; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js index 221b6268c55df..f924c6f3149d3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js @@ -8,7 +8,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import { VectorIcon } from './vector_icon'; -import { VectorStyle } from '../../../vector_style'; +import { StaticStyleProperty } from '../../../vector/properties/static_style_property'; +import { DynamicStyleProperty } from '../../../vector/properties/dynamic_style_property'; let isPointsOnly = false; let isLinesOnly = false; @@ -16,13 +17,13 @@ const defaultProps = { loadIsPointsOnly: () => { return isPointsOnly; }, loadIsLinesOnly: () => { return isLinesOnly; }, fillColor: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { color: '#ff0000', } }, lineColor: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { color: 'Blues', field: { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js similarity index 88% rename from x-pack/legacy/plugins/maps/public/layers/styles/heatmap_style.js rename to x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js index 5ccabe610a120..6bcab95be75fb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js @@ -5,12 +5,12 @@ */ import React from 'react'; -import { GRID_RESOLUTION } from '../grid_resolution'; -import { AbstractStyle } from './abstract_style'; -import { HeatmapStyleEditor } from './components/heatmap/heatmap_style_editor'; -import { HeatmapLegend } from './components/heatmap/legend/heatmap_legend'; -import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from './components/heatmap/heatmap_constants'; -import { getColorRampStops } from './color_utils'; +import { GRID_RESOLUTION } from '../../grid_resolution'; +import { AbstractStyle } from '../abstract_style'; +import { HeatmapStyleEditor } from '../components/heatmap/heatmap_style_editor'; +import { HeatmapLegend } from '../components/heatmap/legend/heatmap_legend'; +import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from '../components/heatmap/heatmap_constants'; +import { getColorRampStops } from '../color_utils'; import { i18n } from '@kbn/i18n'; import { EuiIcon } from '@elastic/eui'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js new file mode 100644 index 0000000000000..8200ede3e3523 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -0,0 +1,12 @@ +/* + * 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 { AbstractStyleProperty } from './style_property'; + +export class DynamicStyleProperty extends AbstractStyleProperty { + static type = 'DYNAMIC'; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js new file mode 100644 index 0000000000000..7898959956aff --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js @@ -0,0 +1,12 @@ +/* + * 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 { AbstractStyleProperty } from './style_property'; + +export class StaticStyleProperty extends AbstractStyleProperty { + static type = 'STATIC'; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js new file mode 100644 index 0000000000000..8b05645afb3c6 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -0,0 +1,14 @@ +/* + * 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. + */ + + + + + +export class AbstractStyleProperty { + + +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js index f26f4df0b1753..ba621361e3b18 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js @@ -22,6 +22,7 @@ import { SMALL_MAKI_ICON_SIZE, HALF_LARGE_MAKI_ICON_SIZE } from './symbol_utils'; +import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; export class VectorStyle extends AbstractStyle { @@ -43,6 +44,9 @@ export class VectorStyle extends AbstractStyle { ...descriptor, ...VectorStyle.createDescriptor(descriptor.properties), }; + + + } static createDescriptor(properties = {}) { @@ -116,7 +120,7 @@ export class VectorStyle extends AbstractStyle { } updatedProperties[propertyName] = { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { ...originalProperties[propertyName].options } @@ -248,7 +252,7 @@ export class VectorStyle extends AbstractStyle { _isPropertyDynamic(propertyName) { const { type, options } = _.get(this._descriptor, ['properties', propertyName], {}); - return type === VectorStyle.STYLE_TYPE.DYNAMIC && options.field && options.field.name; + return type === DynamicStyleProperty.type && options.field && options.field.name; } _checkIfOnlyFeatureType = async (featureType) => { @@ -462,7 +466,7 @@ export class VectorStyle extends AbstractStyle { } _getMBColor(styleName, styleDescriptor) { - const isStatic = styleDescriptor.type === VectorStyle.STYLE_TYPE.STATIC; + const isStatic = styleDescriptor.type === DynamicStyleProperty.type; if (isStatic) { return _.get(styleDescriptor, 'options.color', null); } @@ -503,7 +507,7 @@ export class VectorStyle extends AbstractStyle { } _getMbSize(styleName, styleDescriptor) { - if (styleDescriptor.type === VectorStyle.STYLE_TYPE.STATIC) { + if (styleDescriptor.type === DynamicStyleProperty.type) { return styleDescriptor.options.size; } @@ -595,7 +599,7 @@ export class VectorStyle extends AbstractStyle { // circle sizing is by radius // to make icons be similiar in size to circles then have to deal with icon in half width measurements const iconSize = this._descriptor.properties.iconSize; - if (iconSize.type === VectorStyle.STYLE_TYPE.STATIC) { + if (iconSize.type === DynamicStyleProperty.type) { const iconPixels = iconSize.options.size >= HALF_LARGE_MAKI_ICON_SIZE ? LARGE_MAKI_ICON_SIZE : SMALL_MAKI_ICON_SIZE; @@ -622,7 +626,7 @@ export class VectorStyle extends AbstractStyle { } const iconOrientation = this._descriptor.properties.iconOrientation; - if (iconOrientation.type === VectorStyle.STYLE_TYPE.STATIC) { + if (iconOrientation.type === DynamicStyleProperty.type) { mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', iconOrientation.options.orientation); } else if (_.has(iconOrientation, 'options.field.name')) { const targetName = VectorStyle.getComputedFieldName(vectorStyles.ICON_ORIENTATION, iconOrientation.options.field.name); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js index 7c993564018aa..9cd0250c4978a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js @@ -7,20 +7,23 @@ import { VectorStyle } from './vector_style'; import { DataRequest } from '../util/data_request'; import { VECTOR_SHAPE_TYPES } from '../sources/vector_feature_types'; +import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; +import { StaticStyleProperty } from './vector/properties/static_style_property'; + describe('getDescriptorWithMissingStylePropsRemoved', () => { const fieldName = 'doIStillExist'; const properties = { fillColor: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: {} }, lineColor: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: {} }, iconSize: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { color: 'a color', field: { name: fieldName } @@ -180,7 +183,7 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { const vectorStyle = new VectorStyle({ properties: { fillColor: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { field: { name: 'myDynamicFieldWithNoValues' @@ -202,7 +205,7 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { const vectorStyle = new VectorStyle({ properties: { fillColor: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { field: { name: 'myDynamicField' diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js index dfd0c1ca1b86b..af17775f86bda 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { VectorStyle } from './vector_style'; +import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; +import { StaticStyleProperty } from './vector/properties/static_style_property'; import { SYMBOLIZE_AS_CIRCLE, DEFAULT_ICON_SIZE } from './vector_constants'; import { COLOR_GRADIENTS, @@ -49,31 +50,31 @@ export function getDefaultStaticProperties(mapColors = []) { return { [vectorStyles.FILL_COLOR]: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { color: nextFillColor, } }, [vectorStyles.LINE_COLOR]: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { color: nextLineColor } }, [vectorStyles.LINE_WIDTH]: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { size: 1 } }, [vectorStyles.ICON_SIZE]: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { size: DEFAULT_ICON_SIZE } }, [vectorStyles.ICON_ORIENTATION]: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { orientation: 0 } @@ -84,21 +85,21 @@ export function getDefaultStaticProperties(mapColors = []) { export function getDefaultDynamicProperties() { return { [vectorStyles.FILL_COLOR]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { color: COLOR_GRADIENTS[0].value, field: undefined, } }, [vectorStyles.LINE_COLOR]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { color: COLOR_GRADIENTS[0].value, field: undefined, } }, [vectorStyles.LINE_WIDTH]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { minSize: DEFAULT_MIN_SIZE, maxSize: DEFAULT_MAX_SIZE, @@ -106,7 +107,7 @@ export function getDefaultDynamicProperties() { } }, [vectorStyles.ICON_SIZE]: { - type: VectorStyle.STYLE_TYPE.DYNAMIC, + type: DynamicStyleProperty.type, options: { minSize: DEFAULT_MIN_SIZE, maxSize: DEFAULT_MAX_SIZE, @@ -114,7 +115,7 @@ export function getDefaultDynamicProperties() { } }, [vectorStyles.ICON_ORIENTATION]: { - type: VectorStyle.STYLE_TYPE.STATIC, + type: StaticStyleProperty.type, options: { field: undefined, } diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index efcac8a9175ca..c9a0eda3aef87 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -12,7 +12,7 @@ import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; import { VectorStyle } from '../layers/styles/vector_style'; -import { HeatmapStyle } from '../layers/styles/heatmap_style'; +import { HeatmapStyle } from '../layers/styles/heatmap/heatmap_style'; import { timefilter } from 'ui/timefilter'; import { getInspectorAdapters } from '../reducers/non_serializable_instances'; import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/util'; From aa6674734a5ccb9787df40bb4018f3d6bab784d9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 18:24:47 -0400 Subject: [PATCH 029/112] fix issues --- .../plugins/maps/public/layers/styles/vector_style.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js index ba621361e3b18..a2dd598a7a353 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js @@ -23,11 +23,11 @@ import { HALF_LARGE_MAKI_ICON_SIZE } from './symbol_utils'; import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; +import { StaticStyleProperty } from './vector/properties/static_style_property'; export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - static STYLE_TYPE = { 'DYNAMIC': 'DYNAMIC', 'STATIC': 'STATIC' }; static getComputedFieldName(styleName, fieldName) { return `${VectorStyle.getComputedFieldNamePrefix(fieldName)}__${styleName}`; @@ -466,7 +466,7 @@ export class VectorStyle extends AbstractStyle { } _getMBColor(styleName, styleDescriptor) { - const isStatic = styleDescriptor.type === DynamicStyleProperty.type; + const isStatic = styleDescriptor.type === StaticStyleProperty.type; if (isStatic) { return _.get(styleDescriptor, 'options.color', null); } @@ -507,7 +507,7 @@ export class VectorStyle extends AbstractStyle { } _getMbSize(styleName, styleDescriptor) { - if (styleDescriptor.type === DynamicStyleProperty.type) { + if (styleDescriptor.type === StaticStyleProperty.type) { return styleDescriptor.options.size; } From ef977868b61fd2cfd599af5e5d8969be40bc8c34 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 24 Oct 2019 18:26:23 -0400 Subject: [PATCH 030/112] add icons --- x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js index a2dd598a7a353..fc4822fe48b4a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js @@ -599,7 +599,7 @@ export class VectorStyle extends AbstractStyle { // circle sizing is by radius // to make icons be similiar in size to circles then have to deal with icon in half width measurements const iconSize = this._descriptor.properties.iconSize; - if (iconSize.type === DynamicStyleProperty.type) { + if (iconSize.type === StaticStyleProperty.type) { const iconPixels = iconSize.options.size >= HALF_LARGE_MAKI_ICON_SIZE ? LARGE_MAKI_ICON_SIZE : SMALL_MAKI_ICON_SIZE; From 4e98af5eccc8689e936acdc2f877eee4a26d7cf4 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 27 Oct 2019 17:55:58 -0400 Subject: [PATCH 031/112] move folders --- .../maps/public/layers/joins/inner_join.js | 2 +- .../es_geo_grid_source/es_geo_grid_source.js | 4 ++-- .../es_pew_pew_source/es_pew_pew_source.js | 4 ++-- .../maps/public/layers/sources/es_source.js | 3 --- .../maps/public/layers/sources/vector_source.js | 2 +- .../styles/{components => }/_color_gradient.scss | 0 .../maps/public/layers/styles/_index.scss | 6 +++--- .../styles/{components => }/color_gradient.js | 2 +- .../maps/public/layers/styles/color_utils.js | 2 +- .../heatmap_style_editor.test.js.snap | 0 .../components}/heatmap_constants.js | 0 .../components}/heatmap_style_editor.js | 2 +- .../components}/heatmap_style_editor.test.js | 0 .../components}/legend/heatmap_legend.js | 4 ++-- .../layers/styles/heatmap/heatmap_style.js | 6 +++--- .../components/_static_dynamic_style_row.scss | 0 .../components/static_dynamic_style_row.js | 4 ++-- .../{ => vector}/components/style_legend_row.js | 0 .../vector_style_symbol_editor.test.js.snap | 0 .../components/vector/color/_color_stops.scss | 0 .../components/vector/color/color_ramp_select.js | 2 +- .../components/vector/color/color_stops.js | 0 .../components/vector/color/color_stops_utils.js | 0 .../vector/color/dynamic_color_selection.js | 0 .../vector/color/static_color_selection.js | 0 .../vector/color/vector_style_color_editor.js | 0 .../components/vector/field_select.js | 2 +- .../components/vector/get_vector_style_label.js | 0 .../__snapshots__/vector_icon.test.js.snap | 0 .../components/vector/legend/circle_icon.js | 0 .../components/vector/legend/line_icon.js | 0 .../components/vector/legend/polygon_icon.js | 0 .../vector/legend/style_property_legend_row.js | 4 ++-- .../components/vector/legend/symbol_icon.js | 0 .../components/vector/legend/vector_icon.js | 4 ++-- .../components/vector/legend/vector_icon.test.js | 4 ++-- .../vector/legend/vector_style_legend.js | 0 .../orientation/dynamic_orientation_selection.js | 0 .../vector/orientation/orientation_editor.js | 0 .../orientation/static_orientation_selection.js | 2 +- .../vector/size/dynamic_size_selection.js | 0 .../vector/size/size_range_selector.js | 0 .../vector/size/static_size_selection.js | 2 +- .../vector/size/vector_style_size_editor.js | 0 .../components/vector/style_option_shapes.js | 0 .../components/vector/vector_style_editor.js | 4 ++-- .../vector/vector_style_symbol_editor.js | 0 .../vector/vector_style_symbol_editor.test.js | 0 .../vector/properties/dynamic_color_property.js | 15 +++++++++++++++ .../vector/properties/dynamic_size_property.js | 16 ++++++++++++++++ .../vector/properties/static_color_property.js | 15 +++++++++++++++ .../vector/properties/static_size_property.js | 15 +++++++++++++++ .../styles/vector/properties/style_property.js | 2 -- .../layers/styles/{ => vector}/symbol_utils.js | 2 +- .../styles/{ => vector}/symbol_utils.test.js | 0 .../styles/{ => vector}/vector_constants.js | 0 .../layers/styles/{ => vector}/vector_style.js | 12 ++++++------ .../styles/{ => vector}/vector_style.test.js | 8 ++++---- .../styles/{ => vector}/vector_style_defaults.js | 6 +++--- .../plugins/maps/public/layers/vector_layer.js | 2 +- .../maps/public/selectors/map_selectors.js | 2 +- 61 files changed, 108 insertions(+), 52 deletions(-) rename x-pack/legacy/plugins/maps/public/layers/styles/{components => }/_color_gradient.scss (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{components => }/color_gradient.js (96%) rename x-pack/legacy/plugins/maps/public/layers/styles/{components/heatmap => heatmap/components}/__snapshots__/heatmap_style_editor.test.js.snap (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{components/heatmap => heatmap/components}/heatmap_constants.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{components/heatmap => heatmap/components}/heatmap_style_editor.js (95%) rename x-pack/legacy/plugins/maps/public/layers/styles/{components/heatmap => heatmap/components}/heatmap_style_editor.test.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{components/heatmap => heatmap/components}/legend/heatmap_legend.js (88%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/_static_dynamic_style_row.scss (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/static_dynamic_style_row.js (95%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/style_legend_row.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/__snapshots__/vector_style_symbol_editor.test.js.snap (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/_color_stops.scss (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/color_ramp_select.js (97%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/color_stops.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/color_stops_utils.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/dynamic_color_selection.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/static_color_selection.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/color/vector_style_color_editor.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/field_select.js (96%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/get_vector_style_label.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/__snapshots__/vector_icon.test.js.snap (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/circle_icon.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/line_icon.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/polygon_icon.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/style_property_legend_row.js (96%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/symbol_icon.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/vector_icon.js (95%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/vector_icon.test.js (93%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/legend/vector_style_legend.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/orientation/dynamic_orientation_selection.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/orientation/orientation_editor.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/orientation/static_orientation_selection.js (91%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/size/dynamic_size_selection.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/size/size_range_selector.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/size/static_size_selection.js (92%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/size/vector_style_size_editor.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/style_option_shapes.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/vector_style_editor.js (98%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/vector_style_symbol_editor.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/components/vector/vector_style_symbol_editor.test.js (100%) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/symbol_utils.js (97%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/symbol_utils.test.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/vector_constants.js (100%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/vector_style.js (98%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/vector_style.test.js (96%) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => vector}/vector_style_defaults.js (94%) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 9d902ae3e3288..692a2983e82d3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -6,7 +6,7 @@ import { ESTermSource } from '../sources/es_term_source'; -import { VectorStyle } from '../styles/vector_style'; +import { VectorStyle } from '../styles/vector/vector_style'; export class InnerJoin { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index ad0c1e762883f..8221e70a002fc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -14,8 +14,8 @@ import { Schemas } from 'ui/vis/editors/default/schemas'; import { AggConfigs } from 'ui/agg_types'; import { tabifyAggResponse } from 'ui/agg_response/tabify'; import { convertToGeoJson } from './convert_to_geojson'; -import { VectorStyle } from '../../styles/vector_style'; -import { vectorStyles } from '../../styles/vector_style_defaults'; +import { VectorStyle } from '../../styles/vector/vector_style'; +import { vectorStyles } from '../../styles/vector/vector_style_defaults'; import { RENDER_AS } from './render_as'; import { CreateSourceEditor } from './create_source_editor'; import { UpdateSourceEditor } from './update_source_editor'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 29671b1e272fe..ea766f4cb7377 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -11,8 +11,8 @@ import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { VectorLayer } from '../../vector_layer'; import { CreateSourceEditor } from './create_source_editor'; import { UpdateSourceEditor } from './update_source_editor'; -import { VectorStyle } from '../../styles/vector_style'; -import { vectorStyles } from '../../styles/vector_style_defaults'; +import { VectorStyle } from '../../styles/vector/vector_style'; +import { vectorStyles } from '../../styles/vector/vector_style_defaults'; import { i18n } from '@kbn/i18n'; import { SOURCE_DATA_ID_ORIGIN, ES_PEW_PEW } from '../../../../common/constants'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 647d98e96202a..18bbb7e6d492f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -251,7 +251,4 @@ export class AbstractESSource extends AbstractVectorSource { return fieldFromIndexPattern.format.getConverterFor('text'); } - createField() { - throw new Error('Child must implement Source#createField'); - } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index ee678ef68f5ca..d69bd8ccf0381 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -7,7 +7,7 @@ import { VectorLayer } from '../vector_layer'; import { TooltipProperty } from '../tooltips/tooltip_property'; -import { VectorStyle } from '../styles/vector_style'; +import { VectorStyle } from '../styles/vector/vector_style'; import { AbstractSource } from './source'; import * as topojson from 'topojson-client'; import _ from 'lodash'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/_color_gradient.scss b/x-pack/legacy/plugins/maps/public/layers/styles/_color_gradient.scss similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/_color_gradient.scss rename to x-pack/legacy/plugins/maps/public/layers/styles/_color_gradient.scss diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss b/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss index 87c7bd1face64..971f92fe76152 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss +++ b/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss @@ -1,3 +1,3 @@ -@import './components/color_gradient'; -@import './components/static_dynamic_style_row'; -@import './components/vector/color/color_stops'; +@import './color_gradient'; +@import 'vector/components/static_dynamic_style_row'; +@import 'vector/components/vector/color/color_stops'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js b/x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js similarity index 96% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js rename to x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js index b416d869e592b..d5a75586eb80a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js @@ -5,7 +5,7 @@ */ import React from 'react'; -import { COLOR_RAMP_NAMES, getRGBColorRangeStrings, getLinearGradient } from '../color_utils'; +import { COLOR_RAMP_NAMES, getRGBColorRangeStrings, getLinearGradient } from './color_utils'; import classNames from 'classnames'; export const ColorGradient = ({ colorRamp, colorRampName, className }) => { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js b/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js index 78a7c9d51739a..9e96b25645ada 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js @@ -8,7 +8,7 @@ import React from 'react'; import { vislibColorMaps } from 'ui/vislib/components/color/colormaps'; import { getLegendColors, getColor } from 'ui/vis/map/color_util'; -import { ColorGradient } from './components/color_gradient'; +import { ColorGradient } from './color_gradient'; import { palettes } from '@elastic/eui/lib/services'; import tinycolor from 'tinycolor2'; import chroma from 'chroma-js'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/__snapshots__/heatmap_style_editor.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/__snapshots__/heatmap_style_editor.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/__snapshots__/heatmap_style_editor.test.js.snap rename to x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/__snapshots__/heatmap_style_editor.test.js.snap diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_constants.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_constants.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_constants.js rename to x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_constants.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js similarity index 95% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_style_editor.js rename to x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js index 0aa20f29c341b..f461bb580b281 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js @@ -8,7 +8,7 @@ import React from 'react'; import { EuiFormRow, EuiSuperSelect } from '@elastic/eui'; import { COLOR_GRADIENTS } from '../../color_utils'; -import { ColorGradient } from '../color_gradient'; +import { ColorGradient } from '../../color_gradient'; import { DEFAULT_RGB_HEATMAP_COLOR_RAMP, DEFAULT_HEATMAP_COLOR_RAMP_NAME, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_style_editor.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.test.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/heatmap_style_editor.test.js rename to x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.test.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/legend/heatmap_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js similarity index 88% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/legend/heatmap_legend.js rename to x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js index 74fce11abf0a6..dddc4f88e9bee 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/heatmap/legend/heatmap_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js @@ -7,8 +7,8 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { ColorGradient } from '../../color_gradient'; -import { StyleLegendRow } from '../../style_legend_row'; +import { ColorGradient } from '../../../color_gradient'; +import { StyleLegendRow } from '../../../vector/components/style_legend_row'; import { DEFAULT_RGB_HEATMAP_COLOR_RAMP, DEFAULT_HEATMAP_COLOR_RAMP_NAME, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js index 6bcab95be75fb..e537da8a3e2e4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js @@ -7,9 +7,9 @@ import React from 'react'; import { GRID_RESOLUTION } from '../../grid_resolution'; import { AbstractStyle } from '../abstract_style'; -import { HeatmapStyleEditor } from '../components/heatmap/heatmap_style_editor'; -import { HeatmapLegend } from '../components/heatmap/legend/heatmap_legend'; -import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from '../components/heatmap/heatmap_constants'; +import { HeatmapStyleEditor } from './components/heatmap_style_editor'; +import { HeatmapLegend } from './components/legend/heatmap_legend'; +import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from './components/heatmap_constants'; import { getColorRampStops } from '../color_utils'; import { i18n } from '@kbn/i18n'; import { EuiIcon } from '@elastic/eui'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/_static_dynamic_style_row.scss b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/_static_dynamic_style_row.scss similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/_static_dynamic_style_row.scss rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/_static_dynamic_style_row.scss diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js similarity index 95% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js index 8c3d415407011..6eb6b0ab23a3c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js @@ -5,8 +5,8 @@ */ import React from 'react'; -import { DynamicStyleProperty } from '../vector/properties/dynamic_style_property'; -import { StaticStyleProperty } from '../vector/properties/static_style_property'; +import { DynamicStyleProperty } from '../properties/dynamic_style_property'; +import { StaticStyleProperty } from '../properties/static_style_property'; import _ from 'lodash'; import { i18n } from '@kbn/i18n'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/style_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_legend_row.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/style_legend_row.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_legend_row.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/__snapshots__/vector_style_symbol_editor.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/__snapshots__/vector_style_symbol_editor.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/__snapshots__/vector_style_symbol_editor.test.js.snap rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/__snapshots__/vector_style_symbol_editor.test.js.snap diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/_color_stops.scss b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/_color_stops.scss similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/_color_stops.scss rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/_color_stops.scss diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_ramp_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_ramp_select.js similarity index 97% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_ramp_select.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_ramp_select.js index c2dd51a0182e3..5fc535b764d51 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_ramp_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_ramp_select.js @@ -8,7 +8,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { EuiSuperSelect, EuiSpacer } from '@elastic/eui'; -import { COLOR_GRADIENTS } from '../../../color_utils'; +import { COLOR_GRADIENTS } from '../../../../color_utils'; import { FormattedMessage } from '@kbn/i18n/react'; import { ColorStops } from './color_stops'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_stops.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_stops.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_stops.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_stops.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_stops_utils.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_stops_utils.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_stops_utils.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/color_stops_utils.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/dynamic_color_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/dynamic_color_selection.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/dynamic_color_selection.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/dynamic_color_selection.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/static_color_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/static_color_selection.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/static_color_selection.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/static_color_selection.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/vector_style_color_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/vector_style_color_editor.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/vector_style_color_editor.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/color/vector_style_color_editor.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/field_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/field_select.js similarity index 96% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/field_select.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/field_select.js index 1d8f4e13fdd1a..ce50978a9dc5c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/field_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/field_select.js @@ -8,7 +8,7 @@ import PropTypes from 'prop-types'; import React from 'react'; import { EuiComboBox } from '@elastic/eui'; -import { SOURCE_DATA_ID_ORIGIN } from '../../../../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN } from '../../../../../../common/constants'; import { i18n } from '@kbn/i18n'; export function FieldSelect({ fields, selectedFieldName, onChange, ...rest }) { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/get_vector_style_label.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/get_vector_style_label.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/get_vector_style_label.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/get_vector_style_label.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/__snapshots__/vector_icon.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/__snapshots__/vector_icon.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/__snapshots__/vector_icon.test.js.snap rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/__snapshots__/vector_icon.test.js.snap diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/circle_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/circle_icon.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/circle_icon.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/circle_icon.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/line_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/line_icon.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/line_icon.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/line_icon.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/polygon_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/polygon_icon.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/polygon_icon.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/polygon_icon.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/style_property_legend_row.js similarity index 96% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/style_property_legend_row.js index ee66d859449d1..ad2156bd20edc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/style_property_legend_row.js @@ -9,8 +9,8 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { styleOptionShapes, rangeShape } from '../style_option_shapes'; -import { StaticStyleProperty } from '../../../vector/properties/static_style_property'; -import { ColorGradient } from '../../color_gradient'; +import { StaticStyleProperty } from '../../../properties/static_style_property'; +import { ColorGradient } from '../../../../color_gradient'; import { CircleIcon } from './circle_icon'; import { getVectorStyleLabel } from '../get_vector_style_label'; import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule } from '@elastic/eui'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/symbol_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/symbol_icon.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/symbol_icon.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/symbol_icon.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_icon.js similarity index 95% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_icon.js index d393ed1c85c3f..bd9f8356c0ef9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_icon.js @@ -12,8 +12,8 @@ import { CircleIcon } from './circle_icon'; import { LineIcon } from './line_icon'; import { PolygonIcon } from './polygon_icon'; import { SymbolIcon } from './symbol_icon'; -import { StaticStyleProperty } from '../../../vector/properties/static_style_property'; -import { getColorRampCenterColor } from '../../../color_utils'; +import { StaticStyleProperty } from '../../../properties/static_style_property'; +import { getColorRampCenterColor } from '../../../../color_utils'; export class VectorIcon extends Component { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_icon.test.js similarity index 93% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_icon.test.js index f924c6f3149d3..4c773b35cced3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_icon.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_icon.test.js @@ -8,8 +8,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import { VectorIcon } from './vector_icon'; -import { StaticStyleProperty } from '../../../vector/properties/static_style_property'; -import { DynamicStyleProperty } from '../../../vector/properties/dynamic_style_property'; +import { StaticStyleProperty } from '../../../properties/static_style_property'; +import { DynamicStyleProperty } from '../../../properties/dynamic_style_property'; let isPointsOnly = false; let isLinesOnly = false; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_style_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_style_legend.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/legend/vector_style_legend.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/legend/vector_style_legend.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/dynamic_orientation_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/dynamic_orientation_selection.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/dynamic_orientation_selection.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/dynamic_orientation_selection.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/orientation_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/orientation_editor.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/orientation_editor.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/orientation_editor.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/static_orientation_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/static_orientation_selection.js similarity index 91% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/static_orientation_selection.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/static_orientation_selection.js index b5529c6987459..5e32ed966d360 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/orientation/static_orientation_selection.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/orientation/static_orientation_selection.js @@ -7,7 +7,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { staticOrientationShape } from '../style_option_shapes'; -import { ValidatedRange } from '../../../../../components/validated_range'; +import { ValidatedRange } from '../../../../../../components/validated_range'; export function StaticOrientationSelection({ onChange, styleOptions }) { const onOrientationChange = orientation => { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/dynamic_size_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/dynamic_size_selection.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/dynamic_size_selection.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/dynamic_size_selection.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/size_range_selector.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/size_range_selector.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/size_range_selector.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/size_range_selector.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/static_size_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/static_size_selection.js similarity index 92% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/static_size_selection.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/static_size_selection.js index 38f8fe53d1748..0168a3ef68d9d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/static_size_selection.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/static_size_selection.js @@ -7,7 +7,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { staticSizeShape } from '../style_option_shapes'; -import { ValidatedRange } from '../../../../../components/validated_range'; +import { ValidatedRange } from '../../../../../../components/validated_range'; import { i18n } from '@kbn/i18n'; export function StaticSizeSelection({ onChange, styleOptions }) { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/vector_style_size_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/vector_style_size_editor.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/size/vector_style_size_editor.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/size/vector_style_size_editor.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/style_option_shapes.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/style_option_shapes.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/style_option_shapes.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/style_option_shapes.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_editor.js similarity index 98% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_editor.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_editor.js index 83d4ff7c11d66..48404f6fbeafb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_editor.js @@ -17,8 +17,8 @@ import { getDefaultStaticProperties, vectorStyles, } from '../../vector_style_defaults'; -import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../color_utils'; -import { VECTOR_SHAPE_TYPES } from '../../../sources/vector_feature_types'; +import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../../color_utils'; +import { VECTOR_SHAPE_TYPES } from '../../../../sources/vector_feature_types'; import { SYMBOLIZE_AS_ICON } from '../../vector_constants'; import { i18n } from '@kbn/i18n'; import { SYMBOL_OPTIONS } from '../../symbol_utils'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_symbol_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_symbol_editor.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_symbol_editor.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_symbol_editor.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_symbol_editor.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_symbol_editor.test.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/components/vector/vector_style_symbol_editor.test.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector/vector_style_symbol_editor.test.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js new file mode 100644 index 0000000000000..d0e50cde05125 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -0,0 +1,15 @@ +/* + * 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 { DynamicStyleProperty } from './dynamic_style_property'; + + +export class DynamicColorProperty extends DynamicStyleProperty { + syncWithMb(layer, mbMap) { + super.syncWithMb(layer, mbMap); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js new file mode 100644 index 0000000000000..a6e64dc8f7c94 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -0,0 +1,16 @@ +/* + * 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 { DynamicStyleProperty } from './dynamic_style_property'; + + +export class DynamicSizeProperty extends DynamicStyleProperty { + + syncWithMb(layer, mbMap) { + super.syncWithMb(layer, mbMap); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js new file mode 100644 index 0000000000000..87a449cb051f9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js @@ -0,0 +1,15 @@ +/* + * 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 { StaticStyleProperty } from './static_style_property'; + + +export class StaticSizeProperty extends StaticStyleProperty { + syncWithMb(layer, mbMap) { + super.syncWithMb(layer, mbMap); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js new file mode 100644 index 0000000000000..87a449cb051f9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js @@ -0,0 +1,15 @@ +/* + * 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 { StaticStyleProperty } from './static_style_property'; + + +export class StaticSizeProperty extends StaticStyleProperty { + syncWithMb(layer, mbMap) { + super.syncWithMb(layer, mbMap); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index 8b05645afb3c6..81532b3c30823 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -9,6 +9,4 @@ export class AbstractStyleProperty { - - } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/symbol_utils.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.js similarity index 97% rename from x-pack/legacy/plugins/maps/public/layers/styles/symbol_utils.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.js index 22e1a6aea6a72..967d0e0bbd096 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/symbol_utils.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.js @@ -6,7 +6,7 @@ import maki from '@elastic/maki'; import xml2js from 'xml2js'; -import { parseXmlString } from '../../../common/parse_xml_string'; +import { parseXmlString } from '../../../../common/parse_xml_string'; export const LARGE_MAKI_ICON_SIZE = 15; const LARGE_MAKI_ICON_SIZE_AS_STRING = LARGE_MAKI_ICON_SIZE.toString(); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/symbol_utils.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.test.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/symbol_utils.test.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/symbol_utils.test.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_constants.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_constants.js similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/vector_constants.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_constants.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js similarity index 98% rename from x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index fc4822fe48b4a..59336129b990e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -7,14 +7,14 @@ import _ from 'lodash'; import React from 'react'; import { i18n } from '@kbn/i18n'; -import { getColorRampStops } from './color_utils'; +import { getColorRampStops } from '../color_utils'; import { VectorStyleEditor } from './components/vector/vector_style_editor'; import { getDefaultProperties, vectorStyles } from './vector_style_defaults'; -import { AbstractStyle } from './abstract_style'; -import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE } from '../../../common/constants'; +import { AbstractStyle } from '../abstract_style'; +import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE } from '../../../../common/constants'; import { VectorIcon } from './components/vector/legend/vector_icon'; import { VectorStyleLegend } from './components/vector/legend/vector_style_legend'; -import { VECTOR_SHAPE_TYPES } from '../sources/vector_feature_types'; +import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from './vector_constants'; import { getMakiSymbolAnchor, @@ -22,8 +22,8 @@ import { SMALL_MAKI_ICON_SIZE, HALF_LARGE_MAKI_ICON_SIZE } from './symbol_utils'; -import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; -import { StaticStyleProperty } from './vector/properties/static_style_property'; +import { DynamicStyleProperty } from './properties/dynamic_style_property'; +import { StaticStyleProperty } from './properties/static_style_property'; export class VectorStyle extends AbstractStyle { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js similarity index 96% rename from x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js index 9cd0250c4978a..2b1f7ce4e5468 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js @@ -5,10 +5,10 @@ */ import { VectorStyle } from './vector_style'; -import { DataRequest } from '../util/data_request'; -import { VECTOR_SHAPE_TYPES } from '../sources/vector_feature_types'; -import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; -import { StaticStyleProperty } from './vector/properties/static_style_property'; +import { DataRequest } from '../../util/data_request'; +import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; +import { DynamicStyleProperty } from './properties/dynamic_style_property'; +import { StaticStyleProperty } from './properties/static_style_property'; describe('getDescriptorWithMissingStylePropsRemoved', () => { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js similarity index 94% rename from x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js rename to x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js index af17775f86bda..1e215b27fa145 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector_style_defaults.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DynamicStyleProperty } from './vector/properties/dynamic_style_property'; -import { StaticStyleProperty } from './vector/properties/static_style_property'; +import { DynamicStyleProperty } from './properties/dynamic_style_property'; +import { StaticStyleProperty } from './properties/static_style_property'; import { SYMBOLIZE_AS_CIRCLE, DEFAULT_ICON_SIZE } from './vector_constants'; import { COLOR_GRADIENTS, DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS -} from './color_utils'; +} from '../color_utils'; const DEFAULT_ICON = 'airfield'; diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 166d8a1e005eb..0a096666d8508 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -7,7 +7,7 @@ import turf from 'turf'; import React from 'react'; import { AbstractLayer } from './layer'; -import { VectorStyle } from './styles/vector_style'; +import { VectorStyle } from './styles/vector/vector_style'; import { InnerJoin } from './joins/inner_join'; import { GEO_JSON_TYPE, diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index c9a0eda3aef87..4f561c9391d4d 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -11,7 +11,7 @@ import { VectorTileLayer } from '../layers/vector_tile_layer'; import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; -import { VectorStyle } from '../layers/styles/vector_style'; +import { VectorStyle } from '../layers/styles/vector/vector_style'; import { HeatmapStyle } from '../layers/styles/heatmap/heatmap_style'; import { timefilter } from 'ui/timefilter'; import { getInspectorAdapters } from '../reducers/non_serializable_instances'; From 24492e660b608d104d257b294159a420332a0ea9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 15:46:41 -0400 Subject: [PATCH 032/112] start refactoring to typed styles --- .../properties/dynamic_size_property.js | 37 +++++++++++-- .../properties/dynamic_style_property.js | 12 +++++ .../properties/static_color_property.js | 4 +- .../vector/properties/static_size_property.js | 15 +++++- .../vector/properties/style_property.js | 4 ++ .../public/layers/styles/vector/style_util.js | 14 +++++ .../layers/styles/vector/vector_style.js | 54 +++++++++++++------ 7 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/style_util.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index a6e64dc8f7c94..e897417f5b8c7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -6,11 +6,42 @@ import { DynamicStyleProperty } from './dynamic_style_property'; - +import { getComputedFieldName } from '../style_util'; export class DynamicSizeProperty extends DynamicStyleProperty { - syncWithMb(layer, mbMap) { - super.syncWithMb(layer, mbMap); + syncWithMbForPoints() { + + } + + syncWithMbForSymbols() { + + } + + syncWithMbForShapes(mbLayerId, mbMap) { + const lineWidth = this._getMbSize(); + mbMap.setPaintProperty(mbLayerId, 'line-width', lineWidth); + } + + _getMbSize() { + if (this._isSizeDynamicConfigComplete(this._options)) { + return this._getMbDataDrivenSize({ + targetName: getComputedFieldName(this._styleName, this._options.field.name), + minSize: this._options.minSize, + maxSize: this._options.maxSize, + }); + } + return null; } + + _getMbDataDrivenSize({ targetName, minSize, maxSize }) { + return [ + 'interpolate', + ['linear'], + ['coalesce', ['feature-state', targetName], 0], + 0, minSize, + 1, maxSize + ]; + } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 8200ede3e3523..feb14673b1110 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -6,7 +6,19 @@ import { AbstractStyleProperty } from './style_property'; +import _ from 'lodash'; export class DynamicStyleProperty extends AbstractStyleProperty { static type = 'DYNAMIC'; + + constructor(options, styleName) { + super(options); + this._styleName = styleName; + } + + _isSizeDynamicConfigComplete() { + return _.has(this._options, 'field.name') && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); + } + + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js index 87a449cb051f9..1f9435f52f8e9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js @@ -9,7 +9,5 @@ import { StaticStyleProperty } from './static_style_property'; export class StaticSizeProperty extends StaticStyleProperty { - syncWithMb(layer, mbMap) { - super.syncWithMb(layer, mbMap); - } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js index 87a449cb051f9..208b0f8352965 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js @@ -9,7 +9,18 @@ import { StaticStyleProperty } from './static_style_property'; export class StaticSizeProperty extends StaticStyleProperty { - syncWithMb(layer, mbMap) { - super.syncWithMb(layer, mbMap); + + constructor(options) { + if (typeof options.size !== 'number') { + super({ size: 1 }); + } else { + super(options); + } + } + + syncWithMbForShapes(mbLayerId, mbMap) { + mbMap.setPaintProperty(mbLayerId, 'line-width', this._options.size); } + + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index 81532b3c30823..7796ce7c51ef5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -9,4 +9,8 @@ export class AbstractStyleProperty { + + constructor(options) { + this._options = options; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_util.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_util.js new file mode 100644 index 0000000000000..69caaca080138 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_util.js @@ -0,0 +1,14 @@ +/* + * 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. + */ + + +export function getComputedFieldName(styleName, fieldName) { + return `${getComputedFieldNamePrefix(fieldName)}__${styleName}`; +} + +export function getComputedFieldNamePrefix(fieldName) { + return `__kbn__dynamic__${fieldName}`; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 59336129b990e..0d315f222d373 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -24,18 +24,17 @@ import { } from './symbol_utils'; import { DynamicStyleProperty } from './properties/dynamic_style_property'; import { StaticStyleProperty } from './properties/static_style_property'; +import { DynamicSizeProperty } from './properties/dynamic_size_property'; +import { StaticSizeProperty } from './properties/static_size_property'; +import { getComputedFieldName, getComputedFieldNamePrefix } from './style_util'; export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - static getComputedFieldName(styleName, fieldName) { - return `${VectorStyle.getComputedFieldNamePrefix(fieldName)}__${styleName}`; - } - - static getComputedFieldNamePrefix(fieldName) { - return `__kbn__dynamic__${fieldName}`; - } + //todo: remove these static props + static getComputedFieldName = getComputedFieldName; + static getComputedFieldNamePrefix = getComputedFieldNamePrefix; constructor(descriptor = {}, source) { super(); @@ -44,9 +43,7 @@ export class VectorStyle extends AbstractStyle { ...descriptor, ...VectorStyle.createDescriptor(descriptor.properties), }; - - - + this._lineWidthStyleProperty = this._getStyleProperty('lineWidth', this._descriptor.properties.lineWidth); } static createDescriptor(properties = {}) { @@ -456,6 +453,7 @@ export class VectorStyle extends AbstractStyle { } _getMbDataDrivenSize({ targetName, minSize, maxSize }) { + console.warn('todo: remove', targetName, minSize, maxSize); return [ 'interpolate', ['linear'], @@ -542,12 +540,14 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(lineLayerId, 'line-opacity', 0); } - if (this._descriptor.properties.lineWidth) { - const lineWidth = this._getMbSize(vectorStyles.LINE_WIDTH, this._descriptor.properties.lineWidth); - mbMap.setPaintProperty(lineLayerId, 'line-width', lineWidth); - } else { - mbMap.setPaintProperty(lineLayerId, 'line-width', 0); - } + // if (this._descriptor.properties.lineWidth) { + // const lineWidth = this._getMbSize(vectorStyles.LINE_WIDTH, this._descriptor.properties.lineWidth); + // mbMap.setPaintProperty(lineLayerId, 'line-width', lineWidth); + // } else { + // mbMap.setPaintProperty(lineLayerId, 'line-width', 0); + // } + + this._lineWidthStyleProperty.syncWithMbForShapes(lineLayerId, mbMap); } setMBPaintPropertiesForPoints({ alpha, mbMap, pointLayerId }) { @@ -640,4 +640,26 @@ export class VectorStyle extends AbstractStyle { arePointsSymbolizedAsCircles() { return this._descriptor.properties.symbol.options.symbolizeAs === SYMBOLIZE_AS_CIRCLE; } + + _getSizeProperty(descriptor, styleName) { + if (!descriptor || !descriptor.options) { + return new StaticSizeProperty({ size: 0 }); + } else if (descriptor.type === StaticStyleProperty.type) { + return new StaticSizeProperty(descriptor.options); + } else if (descriptor.type === DynamicStyleProperty.type) { + return new DynamicSizeProperty(descriptor.options, styleName); + } else { + throw new Error(`${descriptor} not implemented`); + } + } + + _getStyleProperty(propertyName, descriptor) { + + if (propertyName === 'lineWidth') { + return this._getSizeProperty(descriptor, vectorStyles.LINE_WIDTH); + } + + throw new Error(`${propertyName} not implemented`); + } + } From 645a50b6b275b56358f240c2cee55161255a23ba Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 16:00:33 -0400 Subject: [PATCH 033/112] widths for circles/symbols --- .../properties/dynamic_size_property.js | 10 +++++---- .../vector/properties/static_size_property.js | 8 +++++++ .../layers/styles/vector/vector_style.js | 22 ++++++------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index e897417f5b8c7..4cf0f92e5e2cf 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -10,12 +10,14 @@ import { getComputedFieldName } from '../style_util'; export class DynamicSizeProperty extends DynamicStyleProperty { - syncWithMbForPoints() { - + syncWithMbForHaloWidth(mbLayerId, mbMap) { + const haloWidth = this._getMbSize(); + mbMap.setPaintProperty(mbLayerId, 'icon-halo-width', haloWidth); } - syncWithMbForSymbols() { - + syncWithMbForCircles(mbLayerId, mbMap) { + const lineWidth = this._getMbSize(); + mbMap.setPaintProperty(mbLayerId, 'circle-stroke-width', lineWidth); } syncWithMbForShapes(mbLayerId, mbMap) { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js index 208b0f8352965..b7544d7ba94b5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js @@ -18,6 +18,14 @@ export class StaticSizeProperty extends StaticStyleProperty { } } + syncWithMbForHaloWidth(mbLayerId, mbMap) { + mbMap.setPaintProperty(mbLayerId, 'icon-halo-width', this._options.size); + } + + syncWithMbForCircles(mbLayerId, mbMap) { + mbMap.setPaintProperty(mbLayerId, 'circle-stroke-width', this._options.size); + } + syncWithMbForShapes(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'line-width', this._options.size); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 0d315f222d373..d0266e841d1fc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -540,13 +540,6 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(lineLayerId, 'line-opacity', 0); } - // if (this._descriptor.properties.lineWidth) { - // const lineWidth = this._getMbSize(vectorStyles.LINE_WIDTH, this._descriptor.properties.lineWidth); - // mbMap.setPaintProperty(lineLayerId, 'line-width', lineWidth); - // } else { - // mbMap.setPaintProperty(lineLayerId, 'line-width', 0); - // } - this._lineWidthStyleProperty.syncWithMbForShapes(lineLayerId, mbMap); } @@ -568,12 +561,10 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(pointLayerId, 'circle-stroke-color', null); mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', 0); } - if (this._descriptor.properties.lineWidth) { - const lineWidth = this._getMbSize(vectorStyles.LINE_WIDTH, this._descriptor.properties.lineWidth); - mbMap.setPaintProperty(pointLayerId, 'circle-stroke-width', lineWidth); - } else { - mbMap.setPaintProperty(pointLayerId, 'circle-stroke-width', 0); - } + + this._lineWidthStyleProperty.syncWithMbForCircles(pointLayerId, mbMap); + + if (this._descriptor.properties.iconSize) { const iconSize = this._getMbSize(vectorStyles.ICON_SIZE, this._descriptor.properties.iconSize); mbMap.setPaintProperty(pointLayerId, 'circle-radius', iconSize); @@ -589,11 +580,12 @@ export class VectorStyle extends AbstractStyle { mbMap.setLayoutProperty(symbolLayerId, 'icon-anchor', getMakiSymbolAnchor(symbolId)); const color = this._getMBColor(vectorStyles.FILL_COLOR, this._descriptor.properties.fillColor); const haloColor = this._getMBColor(vectorStyles.LINE_COLOR, this._descriptor.properties.lineColor); - const haloWidth = this._getMbSize(vectorStyles.LINE_WIDTH, this._descriptor.properties.lineWidth); // icon-color is only supported on SDF icons. mbMap.setPaintProperty(symbolLayerId, 'icon-color', color); mbMap.setPaintProperty(symbolLayerId, 'icon-halo-color', haloColor); - mbMap.setPaintProperty(symbolLayerId, 'icon-halo-width', haloWidth); + + this._lineWidthStyleProperty.syncWithMbForHaloWidth(symbolLayerId, mbMap); + mbMap.setPaintProperty(symbolLayerId, 'icon-opacity', alpha); // circle sizing is by radius From fe5d4601518772f475238755ffe6d0b28e135648 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 16:03:21 -0400 Subject: [PATCH 034/112] rename for clarity --- .../styles/vector/properties/dynamic_size_property.js | 6 +++--- .../layers/styles/vector/properties/static_size_property.js | 6 +++--- .../maps/public/layers/styles/vector/vector_style.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index 4cf0f92e5e2cf..277dad541b489 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -10,17 +10,17 @@ import { getComputedFieldName } from '../style_util'; export class DynamicSizeProperty extends DynamicStyleProperty { - syncWithMbForHaloWidth(mbLayerId, mbMap) { + syncHaloWidthWithMb(mbLayerId, mbMap) { const haloWidth = this._getMbSize(); mbMap.setPaintProperty(mbLayerId, 'icon-halo-width', haloWidth); } - syncWithMbForCircles(mbLayerId, mbMap) { + syncCircleStrokeWidthWithMb(mbLayerId, mbMap) { const lineWidth = this._getMbSize(); mbMap.setPaintProperty(mbLayerId, 'circle-stroke-width', lineWidth); } - syncWithMbForShapes(mbLayerId, mbMap) { + syncLineWidthWithMb(mbLayerId, mbMap) { const lineWidth = this._getMbSize(); mbMap.setPaintProperty(mbLayerId, 'line-width', lineWidth); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js index b7544d7ba94b5..fc19759e8e6ef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js @@ -18,15 +18,15 @@ export class StaticSizeProperty extends StaticStyleProperty { } } - syncWithMbForHaloWidth(mbLayerId, mbMap) { + syncHaloWidthWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'icon-halo-width', this._options.size); } - syncWithMbForCircles(mbLayerId, mbMap) { + syncCircleStrokeWidthWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'circle-stroke-width', this._options.size); } - syncWithMbForShapes(mbLayerId, mbMap) { + syncLineWidthWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'line-width', this._options.size); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index d0266e841d1fc..f2e9b02a1b84a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -540,7 +540,7 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(lineLayerId, 'line-opacity', 0); } - this._lineWidthStyleProperty.syncWithMbForShapes(lineLayerId, mbMap); + this._lineWidthStyleProperty.syncLineWidthWithMb(lineLayerId, mbMap); } setMBPaintPropertiesForPoints({ alpha, mbMap, pointLayerId }) { @@ -562,7 +562,7 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', 0); } - this._lineWidthStyleProperty.syncWithMbForCircles(pointLayerId, mbMap); + this._lineWidthStyleProperty.syncHaloWidthWithMb(pointLayerId, mbMap); if (this._descriptor.properties.iconSize) { @@ -584,7 +584,7 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(symbolLayerId, 'icon-color', color); mbMap.setPaintProperty(symbolLayerId, 'icon-halo-color', haloColor); - this._lineWidthStyleProperty.syncWithMbForHaloWidth(symbolLayerId, mbMap); + this._lineWidthStyleProperty.syncCircleStrokeWidthWithMb(symbolLayerId, mbMap); mbMap.setPaintProperty(symbolLayerId, 'icon-opacity', alpha); From 4cd0a34cc9cc23b8711eb198a4089f7d5c109467 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 16:06:15 -0400 Subject: [PATCH 035/112] fix typo --- .../plugins/maps/public/layers/styles/vector/vector_style.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index f2e9b02a1b84a..a538b0f8b4b85 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -562,7 +562,8 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', 0); } - this._lineWidthStyleProperty.syncHaloWidthWithMb(pointLayerId, mbMap); + this._lineWidthStyleProperty.syncCircleStrokeWidthWithMb(pointLayerId, mbMap); + if (this._descriptor.properties.iconSize) { @@ -584,7 +585,7 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(symbolLayerId, 'icon-color', color); mbMap.setPaintProperty(symbolLayerId, 'icon-halo-color', haloColor); - this._lineWidthStyleProperty.syncCircleStrokeWidthWithMb(symbolLayerId, mbMap); + this._lineWidthStyleProperty.syncHaloWidthWithMb(symbolLayerId, mbMap); mbMap.setPaintProperty(symbolLayerId, 'icon-opacity', alpha); From 5d166d8a057d720895525cc474fccdca8776147f Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 17:33:24 -0400 Subject: [PATCH 036/112] halo color --- .../properties/dynamic_color_property.js | 77 +++++++++- .../properties/dynamic_size_property.js | 38 +++++ .../properties/dynamic_style_property.js | 5 - .../properties/static_color_property.js | 17 ++- .../vector/properties/static_size_property.js | 12 ++ .../layers/styles/vector/vector_style.js | 141 +++++------------- 6 files changed, 178 insertions(+), 112 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index d0e50cde05125..8bd0f7b20e392 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -6,10 +6,83 @@ import { DynamicStyleProperty } from './dynamic_style_property'; +import _ from 'lodash'; +import { getComputedFieldName } from '../style_util'; +import { getColorRampStops } from '../../color_utils'; export class DynamicColorProperty extends DynamicStyleProperty { - syncWithMb(layer, mbMap) { - super.syncWithMb(layer, mbMap); + + + syncHaloBorderColorWithMb(mbLayerId, mbMap) { + const color = this._getMbColor(); + mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', color); + } + + syncCircleStrokeWithMb(pointLayerId, mbMap, alpha) { + const color = this._getMbColor(); + mbMap.setPaintProperty(pointLayerId, 'circle-stroke-color', color); + mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', alpha); + } + + syncLineColorWithMb(lineLayerId, mbMap, alpha) { + const color = this._getMbColor(); + mbMap.setPaintProperty(lineLayerId, 'line-color', color); + mbMap.setPaintProperty(lineLayerId, 'line-opacity', alpha); } + + _getMbColor() { + const isDynamicConfigComplete = _.has(this._options, 'field.name') && _.has(this._options, 'color'); + if (!isDynamicConfigComplete) { + return null; + } + + if (this._options.useCustomColorRamp && (!this._options.customColorRamp || !this._options.customColorRamp.length)) { + return null; + } + + return this._getMBDataDrivenColor({ + targetName: getComputedFieldName(this._styleName, this._options.field.name), + colorStops: this._getMBColorStops(), + isSteps: this._options.useCustomColorRamp, + }); + } + + _getMBDataDrivenColor({ targetName, colorStops, isSteps }) { + if (isSteps) { + const firstStopValue = colorStops[0]; + const lessThenFirstStopValue = firstStopValue - 1; + return [ + 'step', + ['coalesce', ['feature-state', targetName], lessThenFirstStopValue], + 'rgba(0,0,0,0)', // MB will assign the base value to any features that is below the first stop value + ...colorStops + ]; + } + + return [ + 'interpolate', + ['linear'], + ['coalesce', ['feature-state', targetName], -1], + -1, 'rgba(0,0,0,0)', + ...colorStops + ]; + } + + + _getMBColorStops() { + + if (this._options.useCustomColorRamp) { + return this._options.customColorRamp.reduce((accumulatedStops, nextStop) => { + return [...accumulatedStops, nextStop.stop, nextStop.color]; + }, []); + } + + return getColorRampStops(this._options.color); + } + } + + + + diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index 277dad541b489..aefa66da90816 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -7,6 +7,9 @@ import { DynamicStyleProperty } from './dynamic_style_property'; import { getComputedFieldName } from '../style_util'; +import { HALF_LARGE_MAKI_ICON_SIZE, LARGE_MAKI_ICON_SIZE, SMALL_MAKI_ICON_SIZE } from '../symbol_utils'; +import { vectorStyles } from '../vector_style_defaults'; +import _ from 'lodash'; export class DynamicSizeProperty extends DynamicStyleProperty { @@ -15,11 +18,40 @@ export class DynamicSizeProperty extends DynamicStyleProperty { mbMap.setPaintProperty(mbLayerId, 'icon-halo-width', haloWidth); } + + syncIconImageAndSizeWithMb(symbolLayerId, mbMap, symbolId) { + if (this._isSizeDynamicConfigComplete(this._options)) { + const iconPixels = this._options.maxSize >= HALF_LARGE_MAKI_ICON_SIZE + ? LARGE_MAKI_ICON_SIZE + : SMALL_MAKI_ICON_SIZE; + mbMap.setLayoutProperty(symbolLayerId, 'icon-image', `${symbolId}-${iconPixels}`); + + const halfIconPixels = iconPixels / 2; + const targetName = getComputedFieldName(vectorStyles.ICON_SIZE, this._options.field.name); + // Using property state instead of feature-state because layout properties do not support feature-state + mbMap.setLayoutProperty(symbolLayerId, 'icon-size', [ + 'interpolate', + ['linear'], + ['coalesce', ['get', targetName], 0], + 0, this._options.minSize / halfIconPixels, + 1, this._options.maxSize / halfIconPixels + ]); + } else { + mbMap.setLayoutProperty(symbolLayerId, 'icon-image', null); + mbMap.setLayoutProperty(symbolLayerId, 'icon-size', null); + } + } + syncCircleStrokeWidthWithMb(mbLayerId, mbMap) { const lineWidth = this._getMbSize(); mbMap.setPaintProperty(mbLayerId, 'circle-stroke-width', lineWidth); } + syncCircleRadiusWithMb(mbLayerId, mbMap) { + const circleRadius = this._getMbSize(); + mbMap.setPaintProperty(mbLayerId, 'circle-radius', circleRadius); + } + syncLineWidthWithMb(mbLayerId, mbMap) { const lineWidth = this._getMbSize(); mbMap.setPaintProperty(mbLayerId, 'line-width', lineWidth); @@ -46,4 +78,10 @@ export class DynamicSizeProperty extends DynamicStyleProperty { ]; } + + _isSizeDynamicConfigComplete() { + return _.has(this._options, 'field.name') && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); + } + + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index feb14673b1110..ffc9b1ff7964b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -6,7 +6,6 @@ import { AbstractStyleProperty } from './style_property'; -import _ from 'lodash'; export class DynamicStyleProperty extends AbstractStyleProperty { static type = 'DYNAMIC'; @@ -16,9 +15,5 @@ export class DynamicStyleProperty extends AbstractStyleProperty { this._styleName = styleName; } - _isSizeDynamicConfigComplete() { - return _.has(this._options, 'field.name') && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); - } - } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js index 1f9435f52f8e9..e209c410e60d5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js @@ -8,6 +8,21 @@ import { StaticStyleProperty } from './static_style_property'; -export class StaticSizeProperty extends StaticStyleProperty { +export class StaticColorProperty extends StaticStyleProperty { + + + syncHaloBorderColorWithMb(mbLayerId, mbMap) { + mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', this._options.color); + } + + syncLineColorWithMb(mbLayerId, mbMap, alpha) { + mbMap.setPaintProperty(mbLayerId, 'line-color', this._options.color); + mbMap.setPaintProperty(mbLayerId, 'line-opacity', alpha); + } + + syncCircleStrokeWithMb(pointLayerId, mbMap, alpha) { + mbMap.setPaintProperty(pointLayerId, 'circle-stroke-color', this._options.color); + mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', alpha); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js index fc19759e8e6ef..4587f3305615f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js @@ -6,6 +6,7 @@ import { StaticStyleProperty } from './static_style_property'; +import { HALF_LARGE_MAKI_ICON_SIZE, LARGE_MAKI_ICON_SIZE, SMALL_MAKI_ICON_SIZE } from '../symbol_utils'; export class StaticSizeProperty extends StaticStyleProperty { @@ -22,10 +23,21 @@ export class StaticSizeProperty extends StaticStyleProperty { mbMap.setPaintProperty(mbLayerId, 'icon-halo-width', this._options.size); } + syncIconImageAndSizeWithMb(symbolLayerId, mbMap, symbolId) { + const iconPixels = this._size >= HALF_LARGE_MAKI_ICON_SIZE ? LARGE_MAKI_ICON_SIZE : SMALL_MAKI_ICON_SIZE; + mbMap.setLayoutProperty(symbolLayerId, 'icon-image', `${symbolId}-${iconPixels}`); + const halfIconPixels = iconPixels / 2; + mbMap.setLayoutProperty(symbolLayerId, 'icon-size', this._options.size / halfIconPixels); + } + syncCircleStrokeWidthWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'circle-stroke-width', this._options.size); } + syncCircleRadiusWithMb(mbLayerId, mbMap) { + mbMap.setPaintProperty(mbLayerId, 'circle-radius', this._options.size); + } + syncLineWidthWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'line-width', this._options.size); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index a538b0f8b4b85..6c1154c5f9a96 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -16,17 +16,14 @@ import { VectorIcon } from './components/vector/legend/vector_icon'; import { VectorStyleLegend } from './components/vector/legend/vector_style_legend'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from './vector_constants'; -import { - getMakiSymbolAnchor, - LARGE_MAKI_ICON_SIZE, - SMALL_MAKI_ICON_SIZE, - HALF_LARGE_MAKI_ICON_SIZE -} from './symbol_utils'; +import { getMakiSymbolAnchor } from './symbol_utils'; import { DynamicStyleProperty } from './properties/dynamic_style_property'; import { StaticStyleProperty } from './properties/static_style_property'; import { DynamicSizeProperty } from './properties/dynamic_size_property'; import { StaticSizeProperty } from './properties/static_size_property'; import { getComputedFieldName, getComputedFieldNamePrefix } from './style_util'; +import { StaticColorProperty } from './properties/static_color_property'; +import { DynamicColorProperty } from './properties/dynamic_color_property'; export class VectorStyle extends AbstractStyle { @@ -43,7 +40,11 @@ export class VectorStyle extends AbstractStyle { ...descriptor, ...VectorStyle.createDescriptor(descriptor.properties), }; - this._lineWidthStyleProperty = this._getStyleProperty('lineWidth', this._descriptor.properties.lineWidth); + + this._lineColorStyleProperty = this._makeStyleProperty(vectorStyles.LINE_COLOR, this._descriptor.properties[vectorStyles.LINE_COLOR]); + this._fillColorStyleProperty = this._makeStyleProperty(vectorStyles.FILL_COLOR, this._descriptor.properties[vectorStyles.FILL_COLOR]); + this._lineWidthStyleProperty = this._makeStyleProperty(vectorStyles.LINE_WIDTH, this._descriptor.properties[vectorStyles.LINE_WIDTH]); + this._iconSizeStyleProperty = this._makeStyleProperty(vectorStyles.ICON_SIZE, this._descriptor.properties[vectorStyles.ICON_SIZE]); } static createDescriptor(properties = {}) { @@ -334,11 +335,11 @@ export class VectorStyle extends AbstractStyle { // To work around this limitation, some styling values must fall back to geojson property values. let supportsFeatureState; let isScaled; - if (styleName === 'iconSize' + if (styleName === vectorStyles.ICON_SIZE && this._descriptor.properties.symbol.options.symbolizeAs === SYMBOLIZE_AS_ICON) { supportsFeatureState = false; isScaled = true; - } else if (styleName === 'iconOrientation') { + } else if (styleName === vectorStyles.ICON_ORIENTATION) { supportsFeatureState = false; isScaled = false; } else if ((styleName === vectorStyles.FILL_COLOR || styleName === vectorStyles.LINE_COLOR) @@ -452,17 +453,6 @@ export class VectorStyle extends AbstractStyle { ]; } - _getMbDataDrivenSize({ targetName, minSize, maxSize }) { - console.warn('todo: remove', targetName, minSize, maxSize); - return [ - 'interpolate', - ['linear'], - ['coalesce', ['feature-state', targetName], 0], - 0, minSize, - 1, maxSize - ]; - } - _getMBColor(styleName, styleDescriptor) { const isStatic = styleDescriptor.type === StaticStyleProperty.type; if (isStatic) { @@ -498,28 +488,6 @@ export class VectorStyle extends AbstractStyle { return getColorRampStops(styleDescriptor.options.color); } - _isSizeDynamicConfigComplete(styleDescriptor) { - return _.has(styleDescriptor, 'options.field.name') - && _.has(styleDescriptor, 'options.minSize') - && _.has(styleDescriptor, 'options.maxSize'); - } - - _getMbSize(styleName, styleDescriptor) { - if (styleDescriptor.type === StaticStyleProperty.type) { - return styleDescriptor.options.size; - } - - if (this._isSizeDynamicConfigComplete(styleDescriptor)) { - return this._getMbDataDrivenSize({ - targetName: VectorStyle.getComputedFieldName(styleName, styleDescriptor.options.field.name), - minSize: styleDescriptor.options.minSize, - maxSize: styleDescriptor.options.maxSize, - }); - } - - return null; - } - setMBPaintProperties({ alpha, mbMap, fillLayerId, lineLayerId }) { if (this._descriptor.properties.fillColor) { const color = this._getMBColor(vectorStyles.FILL_COLOR, this._descriptor.properties.fillColor); @@ -530,16 +498,7 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(fillLayerId, 'fill-opacity', 0); } - if (this._descriptor.properties.lineColor) { - const color = this._getMBColor(vectorStyles.LINE_COLOR, this._descriptor.properties.lineColor); - mbMap.setPaintProperty(lineLayerId, 'line-color', color); - mbMap.setPaintProperty(lineLayerId, 'line-opacity', alpha); - - } else { - mbMap.setPaintProperty(lineLayerId, 'line-color', null); - mbMap.setPaintProperty(lineLayerId, 'line-opacity', 0); - } - + this._lineColorStyleProperty.syncLineColorWithMb(lineLayerId, mbMap, alpha); this._lineWidthStyleProperty.syncLineWidthWithMb(lineLayerId, mbMap); } @@ -552,26 +511,11 @@ export class VectorStyle extends AbstractStyle { mbMap.setPaintProperty(pointLayerId, 'circle-color', null); mbMap.setPaintProperty(pointLayerId, 'circle-opacity', 0); } - if (this._descriptor.properties.lineColor) { - const color = this._getMBColor(vectorStyles.LINE_COLOR, this._descriptor.properties.lineColor); - mbMap.setPaintProperty(pointLayerId, 'circle-stroke-color', color); - mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', alpha); - - } else { - mbMap.setPaintProperty(pointLayerId, 'circle-stroke-color', null); - mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', 0); - } + this._lineColorStyleProperty.syncCircleStrokeWithMb(pointLayerId, mbMap, alpha); this._lineWidthStyleProperty.syncCircleStrokeWidthWithMb(pointLayerId, mbMap); + this._iconSizeStyleProperty.syncCircleRadiusWithMb(pointLayerId, mbMap); - - - if (this._descriptor.properties.iconSize) { - const iconSize = this._getMbSize(vectorStyles.ICON_SIZE, this._descriptor.properties.iconSize); - mbMap.setPaintProperty(pointLayerId, 'circle-radius', iconSize); - } else { - mbMap.setPaintProperty(pointLayerId, 'circle-radius', 0); - } } async setMBSymbolPropertiesForPoints({ mbMap, symbolLayerId, alpha }) { @@ -580,43 +524,14 @@ export class VectorStyle extends AbstractStyle { const symbolId = this._descriptor.properties.symbol.options.symbolId; mbMap.setLayoutProperty(symbolLayerId, 'icon-anchor', getMakiSymbolAnchor(symbolId)); const color = this._getMBColor(vectorStyles.FILL_COLOR, this._descriptor.properties.fillColor); - const haloColor = this._getMBColor(vectorStyles.LINE_COLOR, this._descriptor.properties.lineColor); // icon-color is only supported on SDF icons. mbMap.setPaintProperty(symbolLayerId, 'icon-color', color); - mbMap.setPaintProperty(symbolLayerId, 'icon-halo-color', haloColor); + this._lineColorStyleProperty.syncHaloBorderColorWithMb(symbolLayerId, mbMap); this._lineWidthStyleProperty.syncHaloWidthWithMb(symbolLayerId, mbMap); - + this._iconSizeStyleProperty.syncIconImageAndSizeWithMb(symbolLayerId, mbMap, symbolId); mbMap.setPaintProperty(symbolLayerId, 'icon-opacity', alpha); - // circle sizing is by radius - // to make icons be similiar in size to circles then have to deal with icon in half width measurements - const iconSize = this._descriptor.properties.iconSize; - if (iconSize.type === StaticStyleProperty.type) { - const iconPixels = iconSize.options.size >= HALF_LARGE_MAKI_ICON_SIZE - ? LARGE_MAKI_ICON_SIZE - : SMALL_MAKI_ICON_SIZE; - mbMap.setLayoutProperty(symbolLayerId, 'icon-image', `${symbolId}-${iconPixels}`); - - const halfIconPixels = iconPixels / 2; - mbMap.setLayoutProperty(symbolLayerId, 'icon-size', iconSize.options.size / halfIconPixels); - } else if (this._isSizeDynamicConfigComplete(iconSize)) { - const iconPixels = iconSize.options.maxSize >= HALF_LARGE_MAKI_ICON_SIZE - ? LARGE_MAKI_ICON_SIZE - : SMALL_MAKI_ICON_SIZE; - mbMap.setLayoutProperty(symbolLayerId, 'icon-image', `${symbolId}-${iconPixels}`); - - const halfIconPixels = iconPixels / 2; - const targetName = VectorStyle.getComputedFieldName(vectorStyles.ICON_SIZE, iconSize.options.field.name); - // Using property state instead of feature-state because layout properties do not support feature-state - mbMap.setLayoutProperty(symbolLayerId, 'icon-size', [ - 'interpolate', - ['linear'], - ['coalesce', ['get', targetName], 0], - 0, iconSize.options.minSize / halfIconPixels, - 1, iconSize.options.maxSize / halfIconPixels - ]); - } const iconOrientation = this._descriptor.properties.iconOrientation; if (iconOrientation.type === DynamicStyleProperty.type) { @@ -634,7 +549,7 @@ export class VectorStyle extends AbstractStyle { return this._descriptor.properties.symbol.options.symbolizeAs === SYMBOLIZE_AS_CIRCLE; } - _getSizeProperty(descriptor, styleName) { + _makeSizeProperty(descriptor, styleName) { if (!descriptor || !descriptor.options) { return new StaticSizeProperty({ size: 0 }); } else if (descriptor.type === StaticStyleProperty.type) { @@ -646,10 +561,28 @@ export class VectorStyle extends AbstractStyle { } } - _getStyleProperty(propertyName, descriptor) { + _makeColorProperty(descriptor, styleName) { + if (!descriptor || !descriptor.options) { + return new StaticColorProperty({ color: null }); + } else if (descriptor.type === StaticStyleProperty.type) { + return new StaticColorProperty(descriptor.options); + } else if (descriptor.type === DynamicStyleProperty.type) { + return new DynamicColorProperty(descriptor.options, styleName); + } else { + throw new Error(`${descriptor} not implemented`); + } + } + + _makeStyleProperty(propertyName, descriptor) { - if (propertyName === 'lineWidth') { - return this._getSizeProperty(descriptor, vectorStyles.LINE_WIDTH); + if (propertyName === vectorStyles.LINE_WIDTH) { + return this._makeSizeProperty(descriptor, vectorStyles.LINE_WIDTH); + } else if (propertyName === vectorStyles.ICON_SIZE) { + return this._makeSizeProperty(descriptor, vectorStyles.ICON_SIZE); + } else if (propertyName === vectorStyles.LINE_COLOR) { + return this._makeColorProperty(descriptor, vectorStyles.LINE_COLOR); + } else if (propertyName === vectorStyles.FILL_COLOR) { + return this._makeColorProperty(descriptor, vectorStyles.FILL_COLOR); } throw new Error(`${propertyName} not implemented`); From ab7360b5c53d7086beeb9cce25bc4c7215580561 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 17:40:17 -0400 Subject: [PATCH 037/112] fill color --- .../vector/properties/dynamic_color_property.js | 12 +++++++++--- .../vector/properties/dynamic_size_property.js | 1 - .../vector/properties/static_color_property.js | 4 ++++ .../maps/public/layers/styles/vector/vector_style.js | 10 +--------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index 8bd0f7b20e392..718f978e3eda5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -25,10 +25,16 @@ export class DynamicColorProperty extends DynamicStyleProperty { mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', alpha); } - syncLineColorWithMb(lineLayerId, mbMap, alpha) { + syncFillColorWithMb(mbLayerId, mbMap, alpha) { const color = this._getMbColor(); - mbMap.setPaintProperty(lineLayerId, 'line-color', color); - mbMap.setPaintProperty(lineLayerId, 'line-opacity', alpha); + mbMap.setPaintProperty(mbLayerId, 'fill-color', color); + mbMap.setPaintProperty(mbLayerId, 'fill-opacity', alpha); + } + + syncLineColorWithMb(mbLayerId, mbMap, alpha) { + const color = this._getMbColor(); + mbMap.setPaintProperty(mbLayerId, 'line-color', color); + mbMap.setPaintProperty(mbLayerId, 'line-opacity', alpha); } _getMbColor() { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index aefa66da90816..f5ab16bcc37b5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -78,7 +78,6 @@ export class DynamicSizeProperty extends DynamicStyleProperty { ]; } - _isSizeDynamicConfigComplete() { return _.has(this._options, 'field.name') && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js index e209c410e60d5..89a2bd7c0f1af 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js @@ -10,6 +10,10 @@ import { StaticStyleProperty } from './static_style_property'; export class StaticColorProperty extends StaticStyleProperty { + syncFillColorWithMb(mbLayerId, mbMap, alpha) { + mbMap.setPaintProperty(mbLayerId, 'fill-color', this._options.color); + mbMap.setPaintProperty(mbLayerId, 'fill-opacity', alpha); + } syncHaloBorderColorWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', this._options.color); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 6c1154c5f9a96..c0c69594f2aec 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -489,15 +489,7 @@ export class VectorStyle extends AbstractStyle { } setMBPaintProperties({ alpha, mbMap, fillLayerId, lineLayerId }) { - if (this._descriptor.properties.fillColor) { - const color = this._getMBColor(vectorStyles.FILL_COLOR, this._descriptor.properties.fillColor); - mbMap.setPaintProperty(fillLayerId, 'fill-color', color); - mbMap.setPaintProperty(fillLayerId, 'fill-opacity', alpha); - } else { - mbMap.setPaintProperty(fillLayerId, 'fill-color', null); - mbMap.setPaintProperty(fillLayerId, 'fill-opacity', 0); - } - + this._fillColorStyleProperty.syncFillColorWithMb(fillLayerId, mbMap, alpha); this._lineColorStyleProperty.syncLineColorWithMb(lineLayerId, mbMap, alpha); this._lineWidthStyleProperty.syncLineWidthWithMb(lineLayerId, mbMap); } From 63dd09b6658fb25481e2c07aa36e711acc21134e Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 17:43:03 -0400 Subject: [PATCH 038/112] circle color --- .../vector/properties/dynamic_color_property.js | 6 ++++++ .../styles/vector/properties/static_color_property.js | 5 +++++ .../maps/public/layers/styles/vector/vector_style.js | 11 +---------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index 718f978e3eda5..4a4ff42694f84 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -14,6 +14,12 @@ import { getColorRampStops } from '../../color_utils'; export class DynamicColorProperty extends DynamicStyleProperty { + syncCircleColorWithMb(mbLayerId, mbMap, alpha) { + const color = this._getMbColor(); + mbMap.setPaintProperty(mbLayerId, 'circle-color', color); + mbMap.setPaintProperty(mbLayerId, 'circle-opacity', alpha); + } + syncHaloBorderColorWithMb(mbLayerId, mbMap) { const color = this._getMbColor(); mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', color); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js index 89a2bd7c0f1af..c6a86069e6331 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js @@ -10,6 +10,11 @@ import { StaticStyleProperty } from './static_style_property'; export class StaticColorProperty extends StaticStyleProperty { + syncCircleColorWithMb(mbLayerId, mbMap, alpha) { + mbMap.setPaintProperty(mbLayerId, 'circle-color', this._options.color); + mbMap.setPaintProperty(mbLayerId, 'circle-opacity', alpha); + } + syncFillColorWithMb(mbLayerId, mbMap, alpha) { mbMap.setPaintProperty(mbLayerId, 'fill-color', this._options.color); mbMap.setPaintProperty(mbLayerId, 'fill-opacity', alpha); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index c0c69594f2aec..49f140b477d19 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -495,19 +495,10 @@ export class VectorStyle extends AbstractStyle { } setMBPaintPropertiesForPoints({ alpha, mbMap, pointLayerId }) { - if (this._descriptor.properties.fillColor) { - const color = this._getMBColor(vectorStyles.FILL_COLOR, this._descriptor.properties.fillColor); - mbMap.setPaintProperty(pointLayerId, 'circle-color', color); - mbMap.setPaintProperty(pointLayerId, 'circle-opacity', alpha); - } else { - mbMap.setPaintProperty(pointLayerId, 'circle-color', null); - mbMap.setPaintProperty(pointLayerId, 'circle-opacity', 0); - } - + this._fillColorStyleProperty.syncCircleColorWithMb(pointLayerId, mbMap, alpha); this._lineColorStyleProperty.syncCircleStrokeWithMb(pointLayerId, mbMap, alpha); this._lineWidthStyleProperty.syncCircleStrokeWidthWithMb(pointLayerId, mbMap); this._iconSizeStyleProperty.syncCircleRadiusWithMb(pointLayerId, mbMap); - } async setMBSymbolPropertiesForPoints({ mbMap, symbolLayerId, alpha }) { From c048cf9f10dab8d0c14a4c9cbf225ac2cce41be4 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 17:46:38 -0400 Subject: [PATCH 039/112] icon color --- .../styles/vector/properties/dynamic_color_property.js | 5 +++++ .../styles/vector/properties/static_color_property.js | 4 ++++ .../maps/public/layers/styles/vector/vector_style.js | 9 ++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index 4a4ff42694f84..5c2122dfc4566 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -20,6 +20,11 @@ export class DynamicColorProperty extends DynamicStyleProperty { mbMap.setPaintProperty(mbLayerId, 'circle-opacity', alpha); } + syncIconColorWithMb(mbLayerId, mbMap) { + const color = this._getMbColor(); + mbMap.setPaintProperty(mbLayerId, 'icon-color', color); + } + syncHaloBorderColorWithMb(mbLayerId, mbMap) { const color = this._getMbColor(); mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', color); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js index c6a86069e6331..d4c44fca1bd08 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_color_property.js @@ -20,6 +20,10 @@ export class StaticColorProperty extends StaticStyleProperty { mbMap.setPaintProperty(mbLayerId, 'fill-opacity', alpha); } + syncIconColorWithMb(mbLayerId, mbMap) { + mbMap.setPaintProperty(mbLayerId, 'icon-color', this._options.color); + } + syncHaloBorderColorWithMb(mbLayerId, mbMap) { mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', this._options.color); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 49f140b477d19..409b58e26e590 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -502,18 +502,17 @@ export class VectorStyle extends AbstractStyle { } async setMBSymbolPropertiesForPoints({ mbMap, symbolLayerId, alpha }) { - mbMap.setLayoutProperty(symbolLayerId, 'icon-ignore-placement', true); const symbolId = this._descriptor.properties.symbol.options.symbolId; + mbMap.setLayoutProperty(symbolLayerId, 'icon-ignore-placement', true); mbMap.setLayoutProperty(symbolLayerId, 'icon-anchor', getMakiSymbolAnchor(symbolId)); - const color = this._getMBColor(vectorStyles.FILL_COLOR, this._descriptor.properties.fillColor); - // icon-color is only supported on SDF icons. - mbMap.setPaintProperty(symbolLayerId, 'icon-color', color); + mbMap.setPaintProperty(symbolLayerId, 'icon-opacity', alpha); + // icon-color is only supported on SDF icons. + this._fillColorStyleProperty.syncIconColorWithMb(symbolLayerId, mbMap); this._lineColorStyleProperty.syncHaloBorderColorWithMb(symbolLayerId, mbMap); this._lineWidthStyleProperty.syncHaloWidthWithMb(symbolLayerId, mbMap); this._iconSizeStyleProperty.syncIconImageAndSizeWithMb(symbolLayerId, mbMap, symbolId); - mbMap.setPaintProperty(symbolLayerId, 'icon-opacity', alpha); const iconOrientation = this._descriptor.properties.iconOrientation; From 427135764aa748b211d136917eff0c45258d5e38 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 17:48:21 -0400 Subject: [PATCH 040/112] remove unused --- .../layers/styles/vector/vector_style.js | 61 +------------------ 1 file changed, 2 insertions(+), 59 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 409b58e26e590..6950437ce8aa1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -7,7 +7,6 @@ import _ from 'lodash'; import React from 'react'; import { i18n } from '@kbn/i18n'; -import { getColorRampStops } from '../color_utils'; import { VectorStyleEditor } from './components/vector/vector_style_editor'; import { getDefaultProperties, vectorStyles } from './vector_style_defaults'; import { AbstractStyle } from '../abstract_style'; @@ -356,7 +355,7 @@ export class VectorStyle extends AbstractStyle { isScaled, name, range: this._getFieldRange(name), - computedName: VectorStyle.getComputedFieldName(styleName, name), + computedName: getComputedFieldName(styleName, name), }; }); } @@ -432,62 +431,6 @@ export class VectorStyle extends AbstractStyle { return hasGeoJsonProperties; } - _getMBDataDrivenColor({ targetName, colorStops, isSteps }) { - if (isSteps) { - const firstStopValue = colorStops[0]; - const lessThenFirstStopValue = firstStopValue - 1; - return [ - 'step', - ['coalesce', ['feature-state', targetName], lessThenFirstStopValue], - 'rgba(0,0,0,0)', // MB will assign the base value to any features that is below the first stop value - ...colorStops - ]; - } - - return [ - 'interpolate', - ['linear'], - ['coalesce', ['feature-state', targetName], -1], - -1, 'rgba(0,0,0,0)', - ...colorStops - ]; - } - - _getMBColor(styleName, styleDescriptor) { - const isStatic = styleDescriptor.type === StaticStyleProperty.type; - if (isStatic) { - return _.get(styleDescriptor, 'options.color', null); - } - - const isDynamicConfigComplete = _.has(styleDescriptor, 'options.field.name') - && _.has(styleDescriptor, 'options.color'); - if (!isDynamicConfigComplete) { - return null; - } - - if (styleDescriptor.options.useCustomColorRamp && - (!styleDescriptor.options.customColorRamp || - !styleDescriptor.options.customColorRamp.length)) { - return null; - } - - return this._getMBDataDrivenColor({ - targetName: VectorStyle.getComputedFieldName(styleName, styleDescriptor.options.field.name), - colorStops: this._getMBColorStops(styleDescriptor), - isSteps: styleDescriptor.options.useCustomColorRamp, - }); - } - - _getMBColorStops(styleDescriptor) { - if (styleDescriptor.options.useCustomColorRamp) { - return styleDescriptor.options.customColorRamp.reduce((accumulatedStops, nextStop) => { - return [...accumulatedStops, nextStop.stop, nextStop.color]; - }, []); - } - - return getColorRampStops(styleDescriptor.options.color); - } - setMBPaintProperties({ alpha, mbMap, fillLayerId, lineLayerId }) { this._fillColorStyleProperty.syncFillColorWithMb(fillLayerId, mbMap, alpha); this._lineColorStyleProperty.syncLineColorWithMb(lineLayerId, mbMap, alpha); @@ -519,7 +462,7 @@ export class VectorStyle extends AbstractStyle { if (iconOrientation.type === DynamicStyleProperty.type) { mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', iconOrientation.options.orientation); } else if (_.has(iconOrientation, 'options.field.name')) { - const targetName = VectorStyle.getComputedFieldName(vectorStyles.ICON_ORIENTATION, iconOrientation.options.field.name); + const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, iconOrientation.options.field.name); // Using property state instead of feature-state because layout properties do not support feature-state mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [ 'coalesce', ['get', targetName], 0 From 34c38bccdcf419f1b46c83d769baec07b413f467 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 18:05:42 -0400 Subject: [PATCH 041/112] orientations --- .../dynamic_orientation_property.js | 29 +++++++++++ .../properties/static_orientation_property.js | 26 ++++++++++ .../layers/styles/vector/vector_style.js | 52 +++++++++++++------ 3 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js new file mode 100644 index 0000000000000..c7ad179670fa8 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js @@ -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 { DynamicStyleProperty } from './dynamic_style_property'; +import { getComputedFieldName } from '../style_util'; +import { vectorStyles } from '../vector_style_defaults'; + + +export class DynamicOrientationProperty extends DynamicStyleProperty { + + + syncIconRotationWithMb(symbolLayerId, mbMap) { + const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, this._options.field.name); + // Using property state instead of feature-state because layout properties do not support feature-state + mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [ + 'coalesce', ['get', targetName], 0 + ]); + } + + +} + + + + diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js new file mode 100644 index 0000000000000..2499591c6c5ff --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js @@ -0,0 +1,26 @@ +/* + * 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 { StaticStyleProperty } from './static_style_property'; + + +export class StaticOrientationProperty extends StaticStyleProperty { + + constructor(options) { + if (typeof options.orientation !== 'number') { + super({ orientation: 0 }); + } else { + super(options); + } + } + + syncIconRotationWithMb(symbolLayerId, mbMap) { + mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', this._options.orientation); + } + + +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 6950437ce8aa1..aa3068c73ab41 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -20,18 +20,16 @@ import { DynamicStyleProperty } from './properties/dynamic_style_property'; import { StaticStyleProperty } from './properties/static_style_property'; import { DynamicSizeProperty } from './properties/dynamic_size_property'; import { StaticSizeProperty } from './properties/static_size_property'; -import { getComputedFieldName, getComputedFieldNamePrefix } from './style_util'; +import { getComputedFieldName } from './style_util'; import { StaticColorProperty } from './properties/static_color_property'; import { DynamicColorProperty } from './properties/dynamic_color_property'; +import { StaticOrientationProperty } from './properties/static_orientation_property'; +import { DynamicOrientationProperty } from './properties/dynamic_orientation_property'; export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - //todo: remove these static props - static getComputedFieldName = getComputedFieldName; - static getComputedFieldNamePrefix = getComputedFieldNamePrefix; - constructor(descriptor = {}, source) { super(); this._source = source; @@ -44,6 +42,9 @@ export class VectorStyle extends AbstractStyle { this._fillColorStyleProperty = this._makeStyleProperty(vectorStyles.FILL_COLOR, this._descriptor.properties[vectorStyles.FILL_COLOR]); this._lineWidthStyleProperty = this._makeStyleProperty(vectorStyles.LINE_WIDTH, this._descriptor.properties[vectorStyles.LINE_WIDTH]); this._iconSizeStyleProperty = this._makeStyleProperty(vectorStyles.ICON_SIZE, this._descriptor.properties[vectorStyles.ICON_SIZE]); + // eslint-disable-next-line max-len + this._iconOrientationProperty = this._makeStyleProperty(vectorStyles.ICON_ORIENTATION, this._descriptor.properties[vectorStyles.ICON_ORIENTATION]); + } static createDescriptor(properties = {}) { @@ -456,18 +457,18 @@ export class VectorStyle extends AbstractStyle { this._lineColorStyleProperty.syncHaloBorderColorWithMb(symbolLayerId, mbMap); this._lineWidthStyleProperty.syncHaloWidthWithMb(symbolLayerId, mbMap); this._iconSizeStyleProperty.syncIconImageAndSizeWithMb(symbolLayerId, mbMap, symbolId); - - - const iconOrientation = this._descriptor.properties.iconOrientation; - if (iconOrientation.type === DynamicStyleProperty.type) { - mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', iconOrientation.options.orientation); - } else if (_.has(iconOrientation, 'options.field.name')) { - const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, iconOrientation.options.field.name); - // Using property state instead of feature-state because layout properties do not support feature-state - mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [ - 'coalesce', ['get', targetName], 0 - ]); - } + this._iconOrientationProperty.syncIconRotationWithMb(symbolLayerId, mbMap); + + // const iconOrientation = this._descriptor.properties.iconOrientation; + // if (iconOrientation.type === DynamicStyleProperty.type) { + // mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', iconOrientation.options.orientation); + // } else if (_.has(iconOrientation, 'options.field.name')) { + // const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, iconOrientation.options.field.name); + // // Using property state instead of feature-state because layout properties do not support feature-state + // mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [ + // 'coalesce', ['get', targetName], 0 + // ]); + // } } arePointsSymbolizedAsCircles() { @@ -498,6 +499,21 @@ export class VectorStyle extends AbstractStyle { } } + _makeOrientationProperty(descriptor, styleName) { + + + if (!descriptor || !descriptor.options) { + return new StaticOrientationProperty({ orientation: 0 }); + } else if (descriptor.type === StaticStyleProperty.type) { + return new StaticOrientationProperty(descriptor.options); + } else if (descriptor.type === DynamicStyleProperty.type) { + return new DynamicOrientationProperty(descriptor.options, styleName); + } else { + throw new Error(`${descriptor} not implemented`); + } + + } + _makeStyleProperty(propertyName, descriptor) { if (propertyName === vectorStyles.LINE_WIDTH) { @@ -508,6 +524,8 @@ export class VectorStyle extends AbstractStyle { return this._makeColorProperty(descriptor, vectorStyles.LINE_COLOR); } else if (propertyName === vectorStyles.FILL_COLOR) { return this._makeColorProperty(descriptor, vectorStyles.FILL_COLOR); + } else if (propertyName === vectorStyles.ICON_ORIENTATION) { + return this._makeOrientationProperty(descriptor, vectorStyles.ICON_ORIENTATION); } throw new Error(`${propertyName} not implemented`); From 3d4eec6ab13e4d7e8868561142f0a89d82936fc8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 18:09:43 -0400 Subject: [PATCH 042/112] remove comments --- .../vector/properties/dynamic_orientation_property.js | 1 - .../maps/public/layers/styles/vector/vector_style.js | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js index c7ad179670fa8..0996d5c2182ba 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js @@ -12,7 +12,6 @@ import { vectorStyles } from '../vector_style_defaults'; export class DynamicOrientationProperty extends DynamicStyleProperty { - syncIconRotationWithMb(symbolLayerId, mbMap) { const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, this._options.field.name); // Using property state instead of feature-state because layout properties do not support feature-state diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index aa3068c73ab41..6c597e480c030 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -459,16 +459,6 @@ export class VectorStyle extends AbstractStyle { this._iconSizeStyleProperty.syncIconImageAndSizeWithMb(symbolLayerId, mbMap, symbolId); this._iconOrientationProperty.syncIconRotationWithMb(symbolLayerId, mbMap); - // const iconOrientation = this._descriptor.properties.iconOrientation; - // if (iconOrientation.type === DynamicStyleProperty.type) { - // mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', iconOrientation.options.orientation); - // } else if (_.has(iconOrientation, 'options.field.name')) { - // const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, iconOrientation.options.field.name); - // // Using property state instead of feature-state because layout properties do not support feature-state - // mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [ - // 'coalesce', ['get', targetName], 0 - // ]); - // } } arePointsSymbolizedAsCircles() { From 161d851d916280a70f703eb332b7388e5609e7df Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 22:31:36 -0400 Subject: [PATCH 043/112] clearup --- .../properties/dynamic_orientation_property.js | 12 +++++++----- .../maps/public/layers/styles/vector/vector_style.js | 3 --- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js index 0996d5c2182ba..442f393e42301 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js @@ -13,11 +13,13 @@ import { vectorStyles } from '../vector_style_defaults'; export class DynamicOrientationProperty extends DynamicStyleProperty { syncIconRotationWithMb(symbolLayerId, mbMap) { - const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, this._options.field.name); - // Using property state instead of feature-state because layout properties do not support feature-state - mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', [ - 'coalesce', ['get', targetName], 0 - ]); + if (this._options.field && this._options.field.name) { + const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, this._options.field.name); + // Using property state instead of feature-state because layout properties do not support feature-state + mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', ['coalesce', ['get', targetName], 0]); + } else { + mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', 0); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 6c597e480c030..da2c378a2b22e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -490,8 +490,6 @@ export class VectorStyle extends AbstractStyle { } _makeOrientationProperty(descriptor, styleName) { - - if (!descriptor || !descriptor.options) { return new StaticOrientationProperty({ orientation: 0 }); } else if (descriptor.type === StaticStyleProperty.type) { @@ -501,7 +499,6 @@ export class VectorStyle extends AbstractStyle { } else { throw new Error(`${descriptor} not implemented`); } - } _makeStyleProperty(propertyName, descriptor) { From 276b7c7394ca42165b03513ee16c6fc679ec4e92 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 23:12:11 -0400 Subject: [PATCH 044/112] start removing hardcoded styles --- .../properties/dynamic_style_property.js | 10 +-- .../properties/static_orientation_property.js | 6 +- .../vector/properties/static_size_property.js | 6 +- .../properties/static_style_property.js | 1 + .../vector/properties/style_property.js | 11 ++- .../layers/styles/vector/vector_style.js | 72 +++++++++++-------- .../maps/public/layers/vector_layer.js | 2 +- 7 files changed, 64 insertions(+), 44 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index ffc9b1ff7964b..81959cbe4d5d8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -9,11 +9,11 @@ import { AbstractStyleProperty } from './style_property'; export class DynamicStyleProperty extends AbstractStyleProperty { static type = 'DYNAMIC'; - - constructor(options, styleName) { - super(options); - this._styleName = styleName; + isDynamic() { + return this._options.field && this._options.field.name; } - + getFieldConfig() { + return this._options.field || {}; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js index 2499591c6c5ff..48a7bbd3f79df 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_orientation_property.js @@ -10,11 +10,11 @@ import { StaticStyleProperty } from './static_style_property'; export class StaticOrientationProperty extends StaticStyleProperty { - constructor(options) { + constructor(options, styleName) { if (typeof options.orientation !== 'number') { - super({ orientation: 0 }); + super({ orientation: 0 }, styleName); } else { - super(options); + super(options, styleName); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js index 4587f3305615f..37162d8cb0a3c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_size_property.js @@ -11,11 +11,11 @@ import { HALF_LARGE_MAKI_ICON_SIZE, LARGE_MAKI_ICON_SIZE, SMALL_MAKI_ICON_SIZE } export class StaticSizeProperty extends StaticStyleProperty { - constructor(options) { + constructor(options, styleName) { if (typeof options.size !== 'number') { - super({ size: 1 }); + super({ size: 1 }, styleName); } else { - super(options); + super(options, styleName); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js index 7898959956aff..448efc06899e5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js @@ -9,4 +9,5 @@ import { AbstractStyleProperty } from './style_property'; export class StaticStyleProperty extends AbstractStyleProperty { static type = 'STATIC'; + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index 7796ce7c51ef5..e719ac90809d1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -10,7 +10,16 @@ export class AbstractStyleProperty { - constructor(options) { + constructor(options, styleName) { this._options = options; + this._styleName = styleName; + } + + isDynamic() { + return false; + } + + getStyleName() { + return this._styleName; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index da2c378a2b22e..d27f98a5fe32c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -30,22 +30,6 @@ export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - constructor(descriptor = {}, source) { - super(); - this._source = source; - this._descriptor = { - ...descriptor, - ...VectorStyle.createDescriptor(descriptor.properties), - }; - - this._lineColorStyleProperty = this._makeStyleProperty(vectorStyles.LINE_COLOR, this._descriptor.properties[vectorStyles.LINE_COLOR]); - this._fillColorStyleProperty = this._makeStyleProperty(vectorStyles.FILL_COLOR, this._descriptor.properties[vectorStyles.FILL_COLOR]); - this._lineWidthStyleProperty = this._makeStyleProperty(vectorStyles.LINE_WIDTH, this._descriptor.properties[vectorStyles.LINE_WIDTH]); - this._iconSizeStyleProperty = this._makeStyleProperty(vectorStyles.ICON_SIZE, this._descriptor.properties[vectorStyles.ICON_SIZE]); - // eslint-disable-next-line max-len - this._iconOrientationProperty = this._makeStyleProperty(vectorStyles.ICON_ORIENTATION, this._descriptor.properties[vectorStyles.ICON_ORIENTATION]); - - } static createDescriptor(properties = {}) { return { @@ -66,6 +50,33 @@ export class VectorStyle extends AbstractStyle { static description = ''; + + constructor(descriptor = {}, source) { + super(); + this._source = source; + this._descriptor = { + ...descriptor, + ...VectorStyle.createDescriptor(descriptor.properties), + }; + + this._lineColorStyleProperty = this._makeStyleProperty(vectorStyles.LINE_COLOR, this._descriptor.properties[vectorStyles.LINE_COLOR]); + this._fillColorStyleProperty = this._makeStyleProperty(vectorStyles.FILL_COLOR, this._descriptor.properties[vectorStyles.FILL_COLOR]); + this._lineWidthStyleProperty = this._makeStyleProperty(vectorStyles.LINE_WIDTH, this._descriptor.properties[vectorStyles.LINE_WIDTH]); + this._iconSizeStyleProperty = this._makeStyleProperty(vectorStyles.ICON_SIZE, this._descriptor.properties[vectorStyles.ICON_SIZE]); + // eslint-disable-next-line max-len + this._iconOrientationProperty = this._makeStyleProperty(vectorStyles.ICON_ORIENTATION, this._descriptor.properties[vectorStyles.ICON_ORIENTATION]); + } + + _getAllStyleProperties() { + return [ + this._lineColorStyleProperty, + this._fillColorStyleProperty, + this._lineWidthStyleProperty, + this._iconSizeStyleProperty, + this._iconOrientationProperty + ]; + } + renderEditor({ layer, onStyleDescriptorChange }) { const styleProperties = { ...this.getProperties() }; const handlePropertyChange = (propertyName, settings) => { @@ -212,19 +223,13 @@ export class VectorStyle extends AbstractStyle { } getSourceFieldNames() { - const properties = this.getProperties(); const fieldNames = []; - Object.keys(properties).forEach(propertyName => { - if (!this._isPropertyDynamic(propertyName)) { - return; - } - - const field = _.get(properties[propertyName], 'options.field', {}); + this.getDynamicPropertiesArray2().forEach(styleProperty => { + const field = styleProperty.getFieldConfig(); if (field.origin === SOURCE_DATA_ID_ORIGIN && field.name) { fieldNames.push(field.name); } }); - return fieldNames; } @@ -248,6 +253,11 @@ export class VectorStyle extends AbstractStyle { }); } + getDynamicPropertiesArray2() { + const styleProperties = this._getAllStyleProperties(); + return styleProperties.filter(styleProperty => styleProperty.isDynamic()); + } + _isPropertyDynamic(propertyName) { const { type, options } = _.get(this._descriptor, ['properties', propertyName], {}); return type === DynamicStyleProperty.type && options.field && options.field.name; @@ -445,7 +455,7 @@ export class VectorStyle extends AbstractStyle { this._iconSizeStyleProperty.syncCircleRadiusWithMb(pointLayerId, mbMap); } - async setMBSymbolPropertiesForPoints({ mbMap, symbolLayerId, alpha }) { + setMBSymbolPropertiesForPoints({ mbMap, symbolLayerId, alpha }) { const symbolId = this._descriptor.properties.symbol.options.symbolId; mbMap.setLayoutProperty(symbolLayerId, 'icon-ignore-placement', true); @@ -467,9 +477,9 @@ export class VectorStyle extends AbstractStyle { _makeSizeProperty(descriptor, styleName) { if (!descriptor || !descriptor.options) { - return new StaticSizeProperty({ size: 0 }); + return new StaticSizeProperty({ size: 0 }, styleName); } else if (descriptor.type === StaticStyleProperty.type) { - return new StaticSizeProperty(descriptor.options); + return new StaticSizeProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { return new DynamicSizeProperty(descriptor.options, styleName); } else { @@ -479,9 +489,9 @@ export class VectorStyle extends AbstractStyle { _makeColorProperty(descriptor, styleName) { if (!descriptor || !descriptor.options) { - return new StaticColorProperty({ color: null }); + return new StaticColorProperty({ color: null }, styleName); } else if (descriptor.type === StaticStyleProperty.type) { - return new StaticColorProperty(descriptor.options); + return new StaticColorProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { return new DynamicColorProperty(descriptor.options, styleName); } else { @@ -491,9 +501,9 @@ export class VectorStyle extends AbstractStyle { _makeOrientationProperty(descriptor, styleName) { if (!descriptor || !descriptor.options) { - return new StaticOrientationProperty({ orientation: 0 }); + return new StaticOrientationProperty({ orientation: 0 }, styleName); } else if (descriptor.type === StaticStyleProperty.type) { - return new StaticOrientationProperty(descriptor.options); + return new StaticOrientationProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { return new DynamicOrientationProperty(descriptor.options, styleName); } else { diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 0a096666d8508..92298f2feea3c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -191,7 +191,7 @@ export class VectorLayer extends AbstractLayer { } hasLegendDetails() { - return this._style.getDynamicPropertiesArray().length > 0; + return this._style.getDynamicPropertiesArray2().length > 0; } getLegendDetails() { From 72a8bf3f5bc4d6a764f4428dd8f910c2bd516bd9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 23:26:15 -0400 Subject: [PATCH 045/112] use stylefields --- .../styles/vector/properties/style_property.js | 3 +++ .../maps/public/layers/styles/vector/vector_style.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index e719ac90809d1..302fbb10d00b2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -22,4 +22,7 @@ export class AbstractStyleProperty { getStyleName() { return this._styleName; } + getOptions() { + return this._options || {}; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index d27f98a5fe32c..e78388b03f09b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -308,8 +308,8 @@ export class VectorStyle extends AbstractStyle { ); @@ -337,8 +337,11 @@ export class VectorStyle extends AbstractStyle { } _getStyleFields() { - return this.getDynamicPropertiesArray() - .map(({ styleName, options }) => { + return this.getDynamicPropertiesArray2() + .map(styleProperty => { + + const styleName = styleProperty.getStyleName(); + const options = styleProperty.getOptions(); const name = options.field.name; // "feature-state" data expressions are not supported with layout properties. @@ -391,6 +394,7 @@ export class VectorStyle extends AbstractStyle { } const styleFields = this._getStyleFields(); + console.log('stylefields', styleFields); if (styleFields.length === 0) { return; } From a0bbe1b12a2aa150cbf49794e435a57e8e5f2ab8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 23:32:14 -0400 Subject: [PATCH 046/112] cleanup cruft --- .../layers/styles/vector/vector_style.js | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index e78388b03f09b..b2e376f616bde 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -26,6 +26,10 @@ import { DynamicColorProperty } from './properties/dynamic_color_property'; import { StaticOrientationProperty } from './properties/static_orientation_property'; import { DynamicOrientationProperty } from './properties/dynamic_orientation_property'; +const POINTS = [GEO_JSON_TYPE.POINT, GEO_JSON_TYPE.MULTI_POINT]; +const LINES = [GEO_JSON_TYPE.LINE_STRING, GEO_JSON_TYPE.MULTI_LINE_STRING]; +const POLYGONS = [GEO_JSON_TYPE.POLYGON, GEO_JSON_TYPE.MULTI_POLYGON]; + export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; @@ -159,10 +163,10 @@ export class VectorStyle extends AbstractStyle { return {}; } - const scaledFields = this.getDynamicPropertiesArray() - .map(({ options }) => { + const scaledFields = this.getDynamicPropertiesArray2() + .map(styleProperty => { return { - name: options.field.name, + name: styleProperty.getFieldConfig().name, min: Infinity, max: -Infinity }; @@ -181,13 +185,13 @@ export class VectorStyle extends AbstractStyle { let hasPolygons = false; for (let i = 0; i < features.length; i++) { const feature = features[i]; - if (!hasPoints && [GEO_JSON_TYPE.POINT, GEO_JSON_TYPE.MULTI_POINT].includes(feature.geometry.type)) { + if (!hasPoints && POINTS.includes(feature.geometry.type)) { hasPoints = true; } - if (!hasLines && [GEO_JSON_TYPE.LINE_STRING, GEO_JSON_TYPE.MULTI_LINE_STRING].includes(feature.geometry.type)) { + if (!hasLines && LINES.includes(feature.geometry.type)) { hasLines = true; } - if (!hasPolygons && [GEO_JSON_TYPE.POLYGON, GEO_JSON_TYPE.MULTI_POLYGON].includes(feature.geometry.type)) { + if (!hasPolygons && POLYGONS.includes(feature.geometry.type)) { hasPolygons = true; } @@ -237,22 +241,6 @@ export class VectorStyle extends AbstractStyle { return this._descriptor.properties || {}; } - getDynamicPropertiesArray() { - const styles = this.getProperties(); - return Object.keys(styles) - .map(styleName => { - const { type, options } = styles[styleName]; - return { - styleName, - type, - options - }; - }) - .filter(({ styleName }) => { - return this._isPropertyDynamic(styleName); - }); - } - getDynamicPropertiesArray2() { const styleProperties = this._getAllStyleProperties(); return styleProperties.filter(styleProperty => styleProperty.isDynamic()); @@ -394,7 +382,6 @@ export class VectorStyle extends AbstractStyle { } const styleFields = this._getStyleFields(); - console.log('stylefields', styleFields); if (styleFields.length === 0) { return; } From 9d6fefb5ca2602fc3c59e5edfc6378d00bd30bbb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 28 Oct 2019 23:33:42 -0400 Subject: [PATCH 047/112] rename --- .../maps/public/layers/styles/vector/vector_style.js | 8 ++++---- x-pack/legacy/plugins/maps/public/layers/vector_layer.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index b2e376f616bde..96486f66802ec 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -163,7 +163,7 @@ export class VectorStyle extends AbstractStyle { return {}; } - const scaledFields = this.getDynamicPropertiesArray2() + const scaledFields = this.getDynamicPropertiesArray() .map(styleProperty => { return { name: styleProperty.getFieldConfig().name, @@ -228,7 +228,7 @@ export class VectorStyle extends AbstractStyle { getSourceFieldNames() { const fieldNames = []; - this.getDynamicPropertiesArray2().forEach(styleProperty => { + this.getDynamicPropertiesArray().forEach(styleProperty => { const field = styleProperty.getFieldConfig(); if (field.origin === SOURCE_DATA_ID_ORIGIN && field.name) { fieldNames.push(field.name); @@ -241,7 +241,7 @@ export class VectorStyle extends AbstractStyle { return this._descriptor.properties || {}; } - getDynamicPropertiesArray2() { + getDynamicPropertiesArray() { const styleProperties = this._getAllStyleProperties(); return styleProperties.filter(styleProperty => styleProperty.isDynamic()); } @@ -325,7 +325,7 @@ export class VectorStyle extends AbstractStyle { } _getStyleFields() { - return this.getDynamicPropertiesArray2() + return this.getDynamicPropertiesArray() .map(styleProperty => { const styleName = styleProperty.getStyleName(); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 92298f2feea3c..0a096666d8508 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -191,7 +191,7 @@ export class VectorLayer extends AbstractLayer { } hasLegendDetails() { - return this._style.getDynamicPropertiesArray2().length > 0; + return this._style.getDynamicPropertiesArray().length > 0; } getLegendDetails() { From 04fd0722980d60969ed1713294aa6492f6780a5d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 00:08:26 -0400 Subject: [PATCH 048/112] start adding fields to styles --- .../layers/fields/kibana_region_field.js | 3 ++ .../maps/public/layers/joins/inner_join.js | 2 +- .../ems_file_source/ems_file_source.js | 4 +- .../es_search_source/es_search_source.js | 2 +- .../public/layers/sources/vector_source.js | 4 ++ .../properties/dynamic_style_property.js | 10 +++++ .../layers/styles/vector/vector_style.js | 37 ++++++++++++++++--- .../maps/public/layers/vector_layer.js | 4 ++ 8 files changed, 57 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js index 7f15b38f7a3e6..0bfc0c6c437c7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js @@ -15,4 +15,7 @@ export class KibanaRegionField extends AbstractField { return AbstractField.FIELD_TYPE.STRING; } + createField() { + throw new Error('must implement'); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 692a2983e82d3..186baf6ccd05b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -14,7 +14,7 @@ export class InnerJoin { this._descriptor = joinDescriptor; const inspectorAdapters = leftSource.getInspectorAdapters(); this._rightSource = new ESTermSource(joinDescriptor.right, inspectorAdapters); - this._leftField = this._descriptor.leftField ? leftSource.createField(joinDescriptor.leftField) : null; + this._leftField = this._descriptor.leftField ? leftSource.createField({ fieldName: joinDescriptor.leftField }) : null; } destroy() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index 6c4c1752798e5..9c1bd57873a2e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -45,10 +45,10 @@ export class EMSFileSource extends AbstractVectorSource { constructor(descriptor, inspectorAdapters) { super(EMSFileSource.createDescriptor(descriptor), inspectorAdapters); - this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => this.createField(propertyKey)); + this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => this.createField({ fieldName: propertyKey })); } - createField(fieldName) { + createField({ fieldName }) { return new EMSRegionLayerField({ fieldName, source: this diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index ad710019265e7..25f1a057f36ff 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -71,7 +71,7 @@ export class ESSearchSource extends AbstractESSource { this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField(property)); } - createField(fieldName) { + createField({ fieldName }) { return new ESDocField({ fieldName, source: this diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index d69bd8ccf0381..7deda8af6c1d0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -48,6 +48,10 @@ export class AbstractVectorSource extends AbstractSource { })); } + createField() { + return null; + } + _createDefaultLayerDescriptor(options, mapColors) { return VectorLayer.createDescriptor( { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 81959cbe4d5d8..8707ca32eef9c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -9,6 +9,16 @@ import { AbstractStyleProperty } from './style_property'; export class DynamicStyleProperty extends AbstractStyleProperty { static type = 'DYNAMIC'; + + constructor(options, styleName, field) { + super(options, styleName); + this._field = field; + } + + getField() { + return this._field; + } + isDynamic() { return this._options.field && this._options.field.name; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 96486f66802ec..f540068fe2ad2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { VectorStyleEditor } from './components/vector/vector_style_editor'; import { getDefaultProperties, vectorStyles } from './vector_style_defaults'; import { AbstractStyle } from '../abstract_style'; -import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE } from '../../../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE, FIELD_ORIGIN } from '../../../../common/constants'; import { VectorIcon } from './components/vector/legend/vector_icon'; import { VectorStyleLegend } from './components/vector/legend/vector_style_legend'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; @@ -55,9 +55,10 @@ export class VectorStyle extends AbstractStyle { static description = ''; - constructor(descriptor = {}, source) { + constructor(descriptor = {}, source, layer) { super(); this._source = source; + this._layer = layer; this._descriptor = { ...descriptor, ...VectorStyle.createDescriptor(descriptor.properties), @@ -466,13 +467,37 @@ export class VectorStyle extends AbstractStyle { return this._descriptor.properties.symbol.options.symbolizeAs === SYMBOLIZE_AS_CIRCLE; } + _makeField(field) { + + if (!field || !field.name) { + return null; + } + + if (field.origin === FIELD_ORIGIN.SOURCE) { + return this._source.createField({ + fieldName: field.name, + label: field.label + }); + } else if (field.origin === FIELD_ORIGIN.JOIN) { + + + return null; + + } else { + throw new Error(`Unknown origin-type ${field.origin}`); + } + + + } + _makeSizeProperty(descriptor, styleName) { if (!descriptor || !descriptor.options) { return new StaticSizeProperty({ size: 0 }, styleName); } else if (descriptor.type === StaticStyleProperty.type) { return new StaticSizeProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { - return new DynamicSizeProperty(descriptor.options, styleName); + const field = this._makeField(descriptor.options.field); + return new DynamicSizeProperty(descriptor.options, styleName, field); } else { throw new Error(`${descriptor} not implemented`); } @@ -484,7 +509,8 @@ export class VectorStyle extends AbstractStyle { } else if (descriptor.type === StaticStyleProperty.type) { return new StaticColorProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { - return new DynamicColorProperty(descriptor.options, styleName); + const field = this._makeField(descriptor.options.field); + return new DynamicColorProperty(descriptor.options, styleName, field); } else { throw new Error(`${descriptor} not implemented`); } @@ -496,7 +522,8 @@ export class VectorStyle extends AbstractStyle { } else if (descriptor.type === StaticStyleProperty.type) { return new StaticOrientationProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { - return new DynamicOrientationProperty(descriptor.options, styleName); + const field = this._makeField(descriptor.options.field); + return new DynamicOrientationProperty(descriptor.options, styleName, field); } else { throw new Error(`${descriptor} not implemented`); } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 0a096666d8508..d33fd04cfdb59 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -95,6 +95,10 @@ export class VectorLayer extends AbstractLayer { this._joins.push(join); }); } + + //todo: remove style-instance creation from selectors. Need to inject layer instance + this._style = new VectorStyle(this._descriptor.style, this._source, this); + } destroy() { From 0590e7e0f59dd78fa01868bd7a050af0e244db08 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 00:13:39 -0400 Subject: [PATCH 049/112] start field-refactor --- .../styles/vector/properties/dynamic_style_property.js | 6 +++++- .../maps/public/layers/styles/vector/vector_style.js | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 8707ca32eef9c..14703ae22b6c8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -20,10 +20,14 @@ export class DynamicStyleProperty extends AbstractStyleProperty { } isDynamic() { - return this._options.field && this._options.field.name; + return !!this._field || (this._options.field && this._options.field.name); } getFieldConfig() { return this._options.field || {}; } + + getFieldOrigin() { + return this._options.field.origin; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index f540068fe2ad2..e460174e0cfcd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -230,9 +230,8 @@ export class VectorStyle extends AbstractStyle { getSourceFieldNames() { const fieldNames = []; this.getDynamicPropertiesArray().forEach(styleProperty => { - const field = styleProperty.getFieldConfig(); - if (field.origin === SOURCE_DATA_ID_ORIGIN && field.name) { - fieldNames.push(field.name); + if (styleProperty.getFieldOrigin() === SOURCE_DATA_ID_ORIGIN) { + fieldNames.push(styleProperty.getField().getName()); } }); return fieldNames; From 88c289f3a54bb8a91266e3491a07a0d47f746105 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 11:32:22 -0400 Subject: [PATCH 050/112] test --- .../maps/public/layers/joins/inner_join.js | 4 ++-- .../public/layers/sources/es_agg_source.js | 6 ++++++ .../layers/styles/vector/vector_style.js | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 186baf6ccd05b..781c02c3cffc2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -6,7 +6,7 @@ import { ESTermSource } from '../sources/es_term_source'; -import { VectorStyle } from '../styles/vector/vector_style'; +import { getComputedFieldNamePrefix } from '../styles/vector/style_util'; export class InnerJoin { @@ -54,7 +54,7 @@ export class InnerJoin { delete feature.properties[metricPropertyKey]; // delete all dynamic properties for metric field - const stylePropertyPrefix = VectorStyle.getComputedFieldNamePrefix(metricPropertyKey); + const stylePropertyPrefix = getComputedFieldNamePrefix(metricPropertyKey); Object.keys(feature.properties).forEach(featurePropertyKey => { if (featurePropertyKey.length >= stylePropertyPrefix.length && featurePropertyKey.substring(0, stylePropertyPrefix.length) === stylePropertyPrefix) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index b3c1ef242b477..efeebfd0d0e3e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -31,6 +31,12 @@ export class AbstractESAggSource extends AbstractESSource { }) : []; } + getMetricFieldForName(fieldName) { + return this._metricFields.find(metricField => { + return metricField.getName() === fieldName; + }); + } + getMetricFields() { const metrics = this._metricFields.filter(esAggField => { return (esAggField.getAggType() === 'count') ? true : !!esAggField.getESDocField(); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index e460174e0cfcd..064b9dab7ccd8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -25,6 +25,8 @@ import { StaticColorProperty } from './properties/static_color_property'; import { DynamicColorProperty } from './properties/dynamic_color_property'; import { StaticOrientationProperty } from './properties/static_orientation_property'; import { DynamicOrientationProperty } from './properties/dynamic_orientation_property'; +import {ESDocField} from "../../fields/es_doc_field"; +import {ESAggMetricField} from "../../fields/es_agg_field"; const POINTS = [GEO_JSON_TYPE.POINT, GEO_JSON_TYPE.MULTI_POINT]; const LINES = [GEO_JSON_TYPE.LINE_STRING, GEO_JSON_TYPE.MULTI_LINE_STRING]; @@ -468,6 +470,11 @@ export class VectorStyle extends AbstractStyle { _makeField(field) { + if (!this._layer) { + console.warn('should be instantiated with layer'); + return null; + } + if (!field || !field.name) { return null; } @@ -479,8 +486,17 @@ export class VectorStyle extends AbstractStyle { }); } else if (field.origin === FIELD_ORIGIN.JOIN) { + let matchingField = null; + this._layer.getValidJoins().forEach(join => { + console.log('kj', join); + matchingField = join.getRightJoinSource().find(source => { + return source.getMetricFieldForName(field.name); + }); + return !!matchingField; + }); - return null; + console.log('found matching field', matchingField); + return matchingField; } else { throw new Error(`Unknown origin-type ${field.origin}`); From a70ccffd18e245523d34461ef8f7229e4e7f7e10 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 17:59:26 -0400 Subject: [PATCH 051/112] remove log --- .../plugins/maps/public/layers/styles/vector/vector_style.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 064b9dab7ccd8..af9f01669064a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -25,8 +25,6 @@ import { StaticColorProperty } from './properties/static_color_property'; import { DynamicColorProperty } from './properties/dynamic_color_property'; import { StaticOrientationProperty } from './properties/static_orientation_property'; import { DynamicOrientationProperty } from './properties/dynamic_orientation_property'; -import {ESDocField} from "../../fields/es_doc_field"; -import {ESAggMetricField} from "../../fields/es_agg_field"; const POINTS = [GEO_JSON_TYPE.POINT, GEO_JSON_TYPE.MULTI_POINT]; const LINES = [GEO_JSON_TYPE.LINE_STRING, GEO_JSON_TYPE.MULTI_LINE_STRING]; @@ -488,14 +486,12 @@ export class VectorStyle extends AbstractStyle { let matchingField = null; this._layer.getValidJoins().forEach(join => { - console.log('kj', join); matchingField = join.getRightJoinSource().find(source => { return source.getMetricFieldForName(field.name); }); return !!matchingField; }); - console.log('found matching field', matchingField); return matchingField; } else { From 47f325939c65191c8e046bb3b8e0419fa16d19bc Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:00:35 -0400 Subject: [PATCH 052/112] read style --- .../legacy/plugins/maps/common/constants.js | 2 + .../maps/public/layers/fields/es_agg_field.js | 10 ++--- .../layers/fields/kibana_region_field.js | 3 -- .../public/layers/sources/es_agg_source.js | 39 ++++++++++++++----- .../public/layers/sources/es_term_source.js | 13 +++++-- .../public/layers/sources/vector_source.js | 2 +- .../layers/styles/vector/vector_style.js | 27 ++++++------- .../maps/public/layers/vector_layer.js | 3 -- .../maps/public/selectors/map_selectors.js | 29 +++----------- 9 files changed, 64 insertions(+), 64 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index 1fd1f4b43bbda..1126dabc38232 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -102,3 +102,5 @@ export const DRAW_TYPE = { BOUNDS: 'BOUNDS', POLYGON: 'POLYGON' }; + +export const COUNT_AGG_TYPE = 'count'; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 29d77334cff8d..1e501d44d948d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -6,7 +6,7 @@ import { AbstractField } from './field'; - +import { COUNT_AGG_TYPE } from '../../../common/constants'; export class ESAggMetricField extends AbstractField { @@ -31,8 +31,8 @@ export class ESAggMetricField extends AbstractField { return this._aggType; } - getESDocField() { - return this._esDocField; + isValid() { + return (this.getAggType() === COUNT_AGG_TYPE) ? true : !!this._esDocField; } getPropertyLabel() { @@ -44,7 +44,7 @@ export class ESAggMetricField extends AbstractField { } getRequestDescription() { - return this.getAggType() !== 'count' ? `${this.getAggType()} ${this.getESDocFieldName()}` : 'count'; + return this.getAggType() !== COUNT_AGG_TYPE ? `${this.getAggType()} ${this.getESDocFieldName()}` : COUNT_AGG_TYPE; } makeMetricAggConfig() { @@ -55,7 +55,7 @@ export class ESAggMetricField extends AbstractField { schema: 'metric', params: {} }; - if (this.getAggType() !== 'count') { + if (this.getAggType() !== COUNT_AGG_TYPE) { metricAggConfig.params = { field: this.getESDocFieldName() }; } return metricAggConfig; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js index 0bfc0c6c437c7..7f15b38f7a3e6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js @@ -15,7 +15,4 @@ export class KibanaRegionField extends AbstractField { return AbstractField.FIELD_TYPE.STRING; } - createField() { - throw new Error('must implement'); - } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index efeebfd0d0e3e..77f2e023b86ad 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -9,10 +9,13 @@ import { AbstractESSource } from './es_source'; import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; import { ESAggMetricField } from '../fields/es_agg_field'; import { ESDocField } from '../fields/es_doc_field'; +import { COUNT_AGG_TYPE } from '../../../common/constants'; const COUNT_PROP_LABEL = 'count'; const COUNT_PROP_NAME = 'doc_count'; +const AGG_DELIMITER = '_of_'; + export class AbstractESAggSource extends AbstractESSource { static COUNT_PROP_LABEL = COUNT_PROP_LABEL; @@ -21,7 +24,7 @@ export class AbstractESAggSource extends AbstractESSource { constructor(descriptor, inspectorAdapters) { super(descriptor, inspectorAdapters); this._metricFields = this._descriptor.metrics ? this._descriptor.metrics.map(metric => { - const esDocField = metric.field ? new ESDocField({ fieldName: metric.field }) : null; + const esDocField = metric.field ? new ESDocField({ fieldName: metric.field, source: this }) : null; return new ESAggMetricField({ label: metric.label, esDocField: esDocField, @@ -31,6 +34,26 @@ export class AbstractESAggSource extends AbstractESSource { }) : []; } + createField({ fieldName, label }) { + if (fieldName === COUNT_PROP_NAME) { + return new ESAggMetricField({ + aggType: COUNT_AGG_TYPE, + label: label, + source: this + }); + } else { + //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 + }); + } + } + getMetricFieldForName(fieldName) { return this._metricFields.find(metricField => { return metricField.getName() === fieldName; @@ -38,24 +61,22 @@ export class AbstractESAggSource extends AbstractESSource { } getMetricFields() { - const metrics = this._metricFields.filter(esAggField => { - return (esAggField.getAggType() === 'count') ? true : !!esAggField.getESDocField(); - }); + const metrics = this._metricFields.filter(esAggField => esAggField.isValid()); if (metrics.length === 0) { metrics.push(new ESAggMetricField({ - aggType: 'count', + aggType: COUNT_AGG_TYPE, source: this })); } return metrics; } - formatMetricKey(type, fieldName) { - return type !== 'count' ? `${type}_of_${fieldName}` : COUNT_PROP_NAME; + formatMetricKey(aggType, fieldName) { + return aggType !== COUNT_AGG_TYPE ? `${aggType}${AGG_DELIMITER}${fieldName}` : COUNT_PROP_NAME; } - formatMetricLabel(type, fieldName) { - return type !== 'count' ? `${type} of ${fieldName}` : COUNT_PROP_LABEL; + formatMetricLabel(aggType, fieldName) { + return aggType !== COUNT_AGG_TYPE ? `${aggType} of ${fieldName}` : COUNT_PROP_LABEL; } createMetricAggConfigs() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 68f0e15347d13..48320701a4675 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -15,6 +15,9 @@ import { AbstractESAggSource } from './es_agg_source'; const TERMS_AGG_NAME = 'join'; +const FIELD_NAME_PREFIX = '__kbnjoin__'; +const GROUP_BY_DELIMITER = '_groupby_'; + const aggSchemas = new Schemas([ { group: 'metrics', @@ -68,6 +71,10 @@ export class ESTermSource extends AbstractESAggSource { return `
editor details
`; } + createField() { + throw new Error('Not implemented. Should retrieve corresponding field from the inner_join.metrics config.'); + } + hasCompleteConfig() { return (_.has(this._descriptor, 'indexPatternId') && _.has(this._descriptor, 'term')); } @@ -84,9 +91,9 @@ export class ESTermSource extends AbstractESAggSource { return this._descriptor.whereQuery; } - formatMetricKey(type, fieldName) { - const metricKey = type !== 'count' ? `${type}_of_${fieldName}` : type; - return `__kbnjoin__${metricKey}_groupby_${this._descriptor.indexPatternTitle}.${this._termField.getName()}`; + formatMetricKey(aggType, fieldName) { + const metricKey = aggType !== 'count' ? `${aggType}_of_${fieldName}` : aggType; + return `${FIELD_NAME_PREFIX}${metricKey}${GROUP_BY_DELIMITER}${this._descriptor.indexPatternTitle}.${this._termField.getName()}`; } formatMetricLabel(type, fieldName) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index 7deda8af6c1d0..e8f0829cfd8b8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -49,7 +49,7 @@ export class AbstractVectorSource extends AbstractSource { } createField() { - return null; + throw new Error(`Should implemement ${this.constructor.type} ${this}`); } _createDefaultLayerDescriptor(options, mapColors) { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index af9f01669064a..ad3e1c205ccf1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -466,36 +466,31 @@ export class VectorStyle extends AbstractStyle { return this._descriptor.properties.symbol.options.symbolizeAs === SYMBOLIZE_AS_CIRCLE; } - _makeField(field) { + _makeField(fieldDescriptor) { - if (!this._layer) { - console.warn('should be instantiated with layer'); + if (!fieldDescriptor || !fieldDescriptor.name) { return null; } - if (!field || !field.name) { - return null; - } - - if (field.origin === FIELD_ORIGIN.SOURCE) { + if (fieldDescriptor.origin === FIELD_ORIGIN.SOURCE) { return this._source.createField({ - fieldName: field.name, - label: field.label + fieldName: fieldDescriptor.name, + label: fieldDescriptor.label }); - } else if (field.origin === FIELD_ORIGIN.JOIN) { + } else if (fieldDescriptor.origin === FIELD_ORIGIN.JOIN) { let matchingField = null; - this._layer.getValidJoins().forEach(join => { - matchingField = join.getRightJoinSource().find(source => { - return source.getMetricFieldForName(field.name); - }); + const joins = this._layer.getValidJoins(); + joins.find(join => { + const aggSource = join.getRightJoinSource(); + matchingField = aggSource.getMetricFieldForName(fieldDescriptor.name); return !!matchingField; }); return matchingField; } else { - throw new Error(`Unknown origin-type ${field.origin}`); + throw new Error(`Unknown origin-type ${fieldDescriptor.origin}`); } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index d33fd04cfdb59..d19aae326aa9e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -95,10 +95,7 @@ export class VectorLayer extends AbstractLayer { this._joins.push(join); }); } - - //todo: remove style-instance creation from selectors. Need to inject layer instance this._style = new VectorStyle(this._descriptor.style, this._source, this); - } destroy() { diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index 4f561c9391d4d..c5e953fd4cd2f 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -11,7 +11,6 @@ import { VectorTileLayer } from '../layers/vector_tile_layer'; import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; -import { VectorStyle } from '../layers/styles/vector/vector_style'; import { HeatmapStyle } from '../layers/styles/heatmap/heatmap_style'; import { timefilter } from 'ui/timefilter'; import { getInspectorAdapters } from '../reducers/non_serializable_instances'; @@ -19,15 +18,16 @@ import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/util' function createLayerInstance(layerDescriptor, inspectorAdapters) { const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters); - const style = createStyleInstance(layerDescriptor.style, source); + switch (layerDescriptor.type) { case TileLayer.type: - return new TileLayer({ layerDescriptor, source, style }); + return new TileLayer({ layerDescriptor, source }); case VectorLayer.type: - return new VectorLayer({ layerDescriptor, source, style }); + return new VectorLayer({ layerDescriptor, source }); case VectorTileLayer.type: - return new VectorTileLayer({ layerDescriptor, source, style }); + return new VectorTileLayer({ layerDescriptor, source }); case HeatmapLayer.type: + const style = layerDescriptor.style ? new HeatmapStyle(layerDescriptor.style) : null; return new HeatmapLayer({ layerDescriptor, source, style }); default: throw new Error(`Unrecognized layerType ${layerDescriptor.type}`); @@ -44,25 +44,6 @@ function createSourceInstance(sourceDescriptor, inspectorAdapters) { return new Source(sourceDescriptor, inspectorAdapters); } - -function createStyleInstance(styleDescriptor, source) { - - if (!styleDescriptor || !styleDescriptor.type) { - return null; - } - - switch (styleDescriptor.type) { - case 'TILE'://backfill for old tilestyles. - return null; - case VectorStyle.type: - return new VectorStyle(styleDescriptor, source); - case HeatmapStyle.type: - return new HeatmapStyle(styleDescriptor); - default: - throw new Error(`Unrecognized styleType ${styleDescriptor.type}`); - } -} - export const getTooltipState = ({ map }) => { return map.tooltipState; }; From ba77ce3ce74b4f7429b3198b60feda503f443422 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:09:17 -0400 Subject: [PATCH 053/112] heatmaplayer --- x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index c766fc5df1faf..157d45fbbd275 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -27,6 +27,8 @@ export class HeatmapLayer extends VectorLayer { if (!style) { const defaultStyle = HeatmapStyle.createDescriptor(); this._style = new HeatmapStyle(defaultStyle); + } else { + this._style = style; } } From 31b9e887affa541c223f0575bcb7198b839dac10 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:18:42 -0400 Subject: [PATCH 054/112] minor changes --- .../styles/vector/properties/dynamic_color_property.js | 4 ++++ .../styles/vector/properties/dynamic_style_property.js | 2 +- .../maps/public/layers/styles/vector/vector_style.js | 10 +++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index 5c2122dfc4566..c3f50b4d8c2df 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -48,6 +48,10 @@ export class DynamicColorProperty extends DynamicStyleProperty { mbMap.setPaintProperty(mbLayerId, 'line-opacity', alpha); } + isCustomColorRamp() { + return !!this._options.customColorRamp; + } + _getMbColor() { const isDynamicConfigComplete = _.has(this._options, 'field.name') && _.has(this._options, 'color'); if (!isDynamicConfigComplete) { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 14703ae22b6c8..b94dd27521e64 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -20,7 +20,7 @@ export class DynamicStyleProperty extends AbstractStyleProperty { } isDynamic() { - return !!this._field || (this._options.field && this._options.field.name); + return !!this._field; } getFieldConfig() { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index ad3e1c205ccf1..cff70c207344d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -279,10 +279,6 @@ export class VectorStyle extends AbstractStyle { return this._checkIfOnlyFeatureType(VECTOR_SHAPE_TYPES.LINE); } - _getIsPolygonsOnly = async () => { - return this._checkIfOnlyFeatureType(VECTOR_SHAPE_TYPES.POLYGON); - } - _getFieldRange = (fieldName) => { return _.get(this._descriptor, ['__styleMeta', fieldName]); } @@ -329,8 +325,8 @@ export class VectorStyle extends AbstractStyle { .map(styleProperty => { const styleName = styleProperty.getStyleName(); - const options = styleProperty.getOptions(); - const name = options.field.name; + const field = styleProperty.getField(); + const name = field.getName(); // "feature-state" data expressions are not supported with layout properties. // To work around this limitation, some styling values must fall back to geojson property values. @@ -344,7 +340,7 @@ export class VectorStyle extends AbstractStyle { supportsFeatureState = false; isScaled = false; } else if ((styleName === vectorStyles.FILL_COLOR || styleName === vectorStyles.LINE_COLOR) - && options.useCustomColorRamp) { + && styleProperty.isCustomColorRamp()) { supportsFeatureState = true; isScaled = false; } else { From 27a883d21a75e24ef9de12e045971d0f391f02b9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:36:55 -0400 Subject: [PATCH 055/112] more changes --- .../plugins/maps/public/layers/fields/field.js | 4 ++++ .../vector/properties/dynamic_color_property.js | 8 ++++++++ .../properties/dynamic_orientation_property.js | 7 +++++++ .../vector/properties/dynamic_size_property.js | 10 +++++++++- .../vector/properties/dynamic_style_property.js | 12 ++++++++---- .../maps/public/layers/styles/vector/vector_style.js | 2 +- 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index dfe9f9ac52ad5..8ee70e533989d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -22,6 +22,10 @@ export class AbstractField { return this._fieldName; } + isValid() { + return !!this._fieldName; + } + async getType() { return AbstractField.FIELD_TYPE.STRING; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index c3f50b4d8c2df..eda9242fe53dd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -52,6 +52,14 @@ export class DynamicColorProperty extends DynamicStyleProperty { return !!this._options.customColorRamp; } + supportsFeatureState() { + return true; + } + + isScaled() { + return !this.isCustomColorRamp(); + } + _getMbColor() { const isDynamicConfigComplete = _.has(this._options, 'field.name') && _.has(this._options, 'color'); if (!isDynamicConfigComplete) { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js index 442f393e42301..fb4ffd8cce4b4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_orientation_property.js @@ -22,6 +22,13 @@ export class DynamicOrientationProperty extends DynamicStyleProperty { } } + supportsFeatureState() { + return false; + } + + isScaled() { + return false; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index f5ab16bcc37b5..ef0eba1d968a8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -79,7 +79,15 @@ export class DynamicSizeProperty extends DynamicStyleProperty { } _isSizeDynamicConfigComplete() { - return _.has(this._options, 'field.name') && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); + return this._field.isValid() && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); + } + + supportsFeatureState() { + return false; + } + + isScaled() { + return false; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index b94dd27521e64..2110d9a1e1bb4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -23,11 +23,15 @@ export class DynamicStyleProperty extends AbstractStyleProperty { return !!this._field; } - getFieldConfig() { - return this._options.field || {}; - } - getFieldOrigin() { return this._options.field.origin; } + + supportsFeatureState() { + return true; + } + + isScaled() { + return true; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index cff70c207344d..f3e030e63a6f9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -167,7 +167,7 @@ export class VectorStyle extends AbstractStyle { const scaledFields = this.getDynamicPropertiesArray() .map(styleProperty => { return { - name: styleProperty.getFieldConfig().name, + name: styleProperty.getField().getName(), min: Infinity, max: -Infinity }; From 78040441145802704b319230b1162d2ca4cefcd6 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:47:42 -0400 Subject: [PATCH 056/112] more typing --- .../properties/dynamic_size_property.js | 10 -------- .../layers/styles/vector/vector_style.js | 24 ++++++------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index ef0eba1d968a8..cfd46ed20823a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -81,14 +81,4 @@ export class DynamicSizeProperty extends DynamicStyleProperty { _isSizeDynamicConfigComplete() { return this._field.isValid() && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); } - - supportsFeatureState() { - return false; - } - - isScaled() { - return false; - } - - } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index f3e030e63a6f9..4f0150acebe31 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -324,36 +324,26 @@ export class VectorStyle extends AbstractStyle { return this.getDynamicPropertiesArray() .map(styleProperty => { - const styleName = styleProperty.getStyleName(); - const field = styleProperty.getField(); - const name = field.getName(); - // "feature-state" data expressions are not supported with layout properties. // To work around this limitation, some styling values must fall back to geojson property values. let supportsFeatureState; let isScaled; - if (styleName === vectorStyles.ICON_SIZE + if (styleProperty.getStyleName() === vectorStyles.ICON_SIZE && this._descriptor.properties.symbol.options.symbolizeAs === SYMBOLIZE_AS_ICON) { supportsFeatureState = false; isScaled = true; - } else if (styleName === vectorStyles.ICON_ORIENTATION) { - supportsFeatureState = false; - isScaled = false; - } else if ((styleName === vectorStyles.FILL_COLOR || styleName === vectorStyles.LINE_COLOR) - && styleProperty.isCustomColorRamp()) { - supportsFeatureState = true; - isScaled = false; } else { - supportsFeatureState = true; - isScaled = true; + supportsFeatureState = styleProperty.supportsFeatureState(); + isScaled = styleProperty.isScaled(); } + const field = styleProperty.getField(); return { supportsFeatureState, isScaled, - name, - range: this._getFieldRange(name), - computedName: getComputedFieldName(styleName, name), + name: field.getName(), + range: this._getFieldRange(field.getName()), + computedName: getComputedFieldName(styleProperty.getStyleName(), field.getName()), }; }); } From 4c04d6d9adb10375b73a76789d26636c30704ccb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:56:56 -0400 Subject: [PATCH 057/112] more typing --- .../layers/styles/vector/vector_style.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 4f0150acebe31..d1aad5b1928df 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -115,16 +115,16 @@ export class VectorStyle extends AbstractStyle { getDescriptorWithMissingStylePropsRemoved(nextOrdinalFields) { const originalProperties = this.getProperties(); const updatedProperties = {}; - Object.keys(originalProperties).forEach(propertyName => { - if (!this._isPropertyDynamic(propertyName)) { - return; - } - const fieldName = _.get(originalProperties[propertyName], 'options.field.name'); - if (!fieldName) { + + this.getDynamicPropertiesArray().forEach(dynamicProperty =>{ + + const field = dynamicProperty.getField(); + if (field || !field.isValid()) { return; } + const fieldName = field.getName(); const matchingOrdinalField = nextOrdinalFields.find(oridinalField => { return fieldName === oridinalField.name; }); @@ -133,13 +133,14 @@ export class VectorStyle extends AbstractStyle { return; } - updatedProperties[propertyName] = { + updatedProperties[dynamicProperty.getStyleName()] = { type: DynamicStyleProperty.type, options: { - ...originalProperties[propertyName].options + ...originalProperties[dynamicProperty.getStyleName()].options } }; - delete updatedProperties[propertyName].options.field; + delete updatedProperties[dynamicProperty.getStyleName()].options.field; + }); if (Object.keys(updatedProperties).length === 0) { @@ -156,6 +157,7 @@ export class VectorStyle extends AbstractStyle { ...updatedProperties, }) }; + } async pluckStyleMetaFromSourceDataRequest(sourceDataRequest) { @@ -247,8 +249,8 @@ export class VectorStyle extends AbstractStyle { } _isPropertyDynamic(propertyName) { - const { type, options } = _.get(this._descriptor, ['properties', propertyName], {}); - return type === DynamicStyleProperty.type && options.field && options.field.name; + const styleProperty = this._getAllStyleProperties().find(styleProperty => styleProperty.getName() === propertyName); + return styleProperty.isDynamic(); } _checkIfOnlyFeatureType = async (featureType) => { @@ -464,7 +466,6 @@ export class VectorStyle extends AbstractStyle { label: fieldDescriptor.label }); } else if (fieldDescriptor.origin === FIELD_ORIGIN.JOIN) { - let matchingField = null; const joins = this._layer.getValidJoins(); joins.find(join => { @@ -472,9 +473,7 @@ export class VectorStyle extends AbstractStyle { matchingField = aggSource.getMetricFieldForName(fieldDescriptor.name); return !!matchingField; }); - return matchingField; - } else { throw new Error(`Unknown origin-type ${fieldDescriptor.origin}`); } From 607c801528345259bef77a7fe187a968be271b14 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 22:58:28 -0400 Subject: [PATCH 058/112] rename for clarity --- .../public/layers/styles/vector/vector_style.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index d1aad5b1928df..d4b55dd32b0fa 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -83,7 +83,7 @@ export class VectorStyle extends AbstractStyle { } renderEditor({ layer, onStyleDescriptorChange }) { - const styleProperties = { ...this.getProperties() }; + const styleProperties = { ...this.getRawProperties() }; const handlePropertyChange = (propertyName, settings) => { styleProperties[propertyName] = settings;//override single property, but preserve the rest const vectorStyleDescriptor = VectorStyle.createDescriptor(styleProperties); @@ -113,7 +113,7 @@ export class VectorStyle extends AbstractStyle { * can then use to update store state via dispatch. */ getDescriptorWithMissingStylePropsRemoved(nextOrdinalFields) { - const originalProperties = this.getProperties(); + const originalProperties = this.getRawProperties(); const updatedProperties = {}; @@ -239,7 +239,7 @@ export class VectorStyle extends AbstractStyle { return fieldNames; } - getProperties() { + getRawProperties() { return this._descriptor.properties || {}; } @@ -248,11 +248,6 @@ export class VectorStyle extends AbstractStyle { return styleProperties.filter(styleProperty => styleProperty.isDynamic()); } - _isPropertyDynamic(propertyName) { - const styleProperty = this._getAllStyleProperties().find(styleProperty => styleProperty.getName() === propertyName); - return styleProperty.isDynamic(); - } - _checkIfOnlyFeatureType = async (featureType) => { const supportedFeatures = await this._source.getSupportedShapeTypes(); @@ -286,7 +281,7 @@ export class VectorStyle extends AbstractStyle { } getIcon = () => { - const styles = this.getProperties(); + const styles = this.getRawProperties(); const symbolId = this.arePointsSymbolizedAsCircles() ? undefined : this._descriptor.properties.symbol.options.symbolId; @@ -302,7 +297,7 @@ export class VectorStyle extends AbstractStyle { } getLegendDetails(getFieldLabel, getFieldFormatter) { - const styles = this.getProperties(); + const styles = this.getRawProperties(); const styleProperties = Object.keys(styles).map(styleName => { const { type, options } = styles[styleName]; return { From 9e84385f476d00b854ead502090d7aca2d37dddc Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 23:03:10 -0400 Subject: [PATCH 059/112] renames --- .../plugins/maps/public/layers/styles/vector/vector_style.js | 2 +- x-pack/legacy/plugins/maps/public/layers/vector_layer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index d4b55dd32b0fa..a70d7bbb7b324 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -296,7 +296,7 @@ export class VectorStyle extends AbstractStyle { ); } - getLegendDetails(getFieldLabel, getFieldFormatter) { + renderLegendDetails(getFieldLabel, getFieldFormatter) { const styles = this.getRawProperties(); const styleProperties = Object.keys(styles).map(styleName => { const { type, options } = styles[styleName]; diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index d19aae326aa9e..94de3f030bfa5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -214,7 +214,7 @@ export class VectorLayer extends AbstractLayer { return await source.getFieldFormatter(field.name); }; - return this._style.getLegendDetails(getFieldLabel, getFieldFormatter); + return this._style.renderLegendDetails(getFieldLabel, getFieldFormatter); } _getBoundsBasedOnData() { From 6e0e168fb12b8d15e5838d98d621b9477a4075e8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 29 Oct 2019 23:20:19 -0400 Subject: [PATCH 060/112] fix wonky mistake --- .../plugins/maps/server/sample_data/web_logs_saved_objects.js | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js b/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js index c6d78a5020f6f..2ac1de70b17d3 100644 --- a/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js +++ b/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js @@ -100,6 +100,7 @@ const layerList = [ 'type': 'ES_SEARCH', 'geoField': 'geo.coordinates', 'limit': 2048, + 'filterByMapBounds': true, 'tooltipProperties': [ 'clientip', 'timestamp', From 066865d4cca9fae007a1b57856f89a5572f15a7f Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 30 Oct 2019 11:45:19 -0400 Subject: [PATCH 061/112] add todos --- .../plugins/maps/public/layers/fields/ems_region_field.js | 1 + x-pack/legacy/plugins/maps/public/layers/fields/field.js | 2 ++ .../plugins/maps/public/layers/fields/kibana_region_field.js | 1 + .../legacy/plugins/maps/public/layers/sources/es_agg_source.js | 1 + .../plugins/maps/public/layers/styles/vector/vector_style.js | 1 - 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js index 4b1dfce242a12..a078fc6cd3f35 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js @@ -8,6 +8,7 @@ import { AbstractField } from './field'; import { TooltipProperty } from '../tooltips/tooltip_property'; +//todo: rename to ESMFileField export class EMSRegionLayerField extends AbstractField { static type = 'EMS_REGION_LAYER'; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 8ee70e533989d..49a24c398213f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -7,6 +7,8 @@ export class AbstractField { + //todo consider removing + //double check if we're actually using this consistently static FIELD_TYPE = { STRING: 'string', NUMBER: 'number', diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js index 7f15b38f7a3e6..f341d05db9a3b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js @@ -7,6 +7,7 @@ import { AbstractField } from './field'; +//todo: need to be implemented export class KibanaRegionField extends AbstractField { static type = 'KIBANA_REGION'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 77f2e023b86ad..8286934d16057 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -16,6 +16,7 @@ const COUNT_PROP_NAME = 'doc_count'; const AGG_DELIMITER = '_of_'; +//todo: extract in separate PR export class AbstractESAggSource extends AbstractESSource { static COUNT_PROP_LABEL = COUNT_PROP_LABEL; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index a70d7bbb7b324..55a52213aacbc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -34,7 +34,6 @@ export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - static createDescriptor(properties = {}) { return { type: VectorStyle.type, From 5df73ea637f933acb0dfbb4fd6232384019f5db8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 4 Nov 2019 10:43:12 -0500 Subject: [PATCH 062/112] merge in master (start) --- .../public/components/tooltip_selector.js | 5 +- .../maps/public/layers/fields/es_doc_field.js | 1 + .../maps/public/layers/fields/field.js | 2 + .../es_search_source/es_search_source.js | 2 +- .../es_search_source/update_source_editor.js | 6 + .../maps/public/layers/styles/_index.scss | 6 +- .../maps/public/layers/styles/color_utils.js | 2 +- .../{ => components}/_color_gradient.scss | 0 .../components/_static_dynamic_style_row.scss | 3 + .../styles/components/color_gradient.js | 27 ++ .../components/static_dynamic_style_row.js | 127 ++++++++ .../styles/components/style_legend_row.js | 66 ++++ .../components/heatmap_style_editor.js | 2 +- .../components/legend/heatmap_legend.js | 4 +- .../vector_style_symbol_editor.test.js.snap | 98 ++++++ .../vector/components/color/_color_stops.scss | 39 +++ .../components/color/color_ramp_select.js | 106 ++++++ .../vector/components/color/color_stops.js | 155 +++++++++ .../components/color/color_stops_utils.js | 66 ++++ .../color/dynamic_color_selection.js | 48 +++ .../color/static_color_selection.js | 30 ++ .../color/vector_style_color_editor.js | 29 ++ .../styles/vector/components/field_select.js | 86 +++++ .../components/get_vector_style_label.js | 32 ++ .../__snapshots__/vector_icon.test.js.snap | 45 +++ .../vector/components/legend/circle_icon.js | 44 +++ .../vector/components/legend/line_icon.js | 13 + .../vector/components/legend/polygon_icon.js | 18 ++ .../legend/style_property_legend_row.js | 170 ++++++++++ .../vector/components/legend/symbol_icon.js | 79 +++++ .../vector/components/legend/vector_icon.js | 128 ++++++++ .../components/legend/vector_icon.test.js | 117 +++++++ .../components/legend/vector_style_legend.js | 40 +++ .../dynamic_orientation_selection.js | 32 ++ .../orientation/orientation_editor.js | 30 ++ .../static_orientation_selection.js | 34 ++ .../components/size/dynamic_size_selection.js | 48 +++ .../components/size/size_range_selector.js | 44 +++ .../components/size/static_size_selection.js | 38 +++ .../size/vector_style_size_editor.js | 28 ++ .../vector/components/style_option_shapes.js | 51 +++ .../vector/components/vector_style_editor.js | 304 ++++++++++++++++++ .../components/vector_style_symbol_editor.js | 136 ++++++++ .../vector_style_symbol_editor.test.js | 52 +++ .../layers/styles/vector/vector_style.js | 29 +- .../layers/styles/vector/vector_style.test.js | 13 +- .../styles/vector/vector_style_defaults.js | 23 +- 47 files changed, 2407 insertions(+), 51 deletions(-) rename x-pack/legacy/plugins/maps/public/layers/styles/{ => components}/_color_gradient.scss (100%) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/components/_static_dynamic_style_row.scss create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/components/style_legend_row.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/__snapshots__/vector_style_symbol_editor.test.js.snap create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/_color_stops.scss create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_ramp_select.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops_utils.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_selection.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/static_color_selection.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/vector_style_color_editor.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/get_vector_style_label.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/circle_icon.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/line_icon.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/polygon_icon.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.test.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/dynamic_orientation_selection.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/orientation_editor.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/static_orientation_selection.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/dynamic_size_selection.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/size_range_selector.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/static_size_selection.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/vector_style_size_editor.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.test.js diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 1d524c20ead8d..0130f39cd118a 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -62,7 +62,10 @@ export class TooltipSelector extends Component { return; } + console.log('tpf', this.props.fields); + const getProps = async field => { + console.log('getprops', field); return new Promise(async (resolve, reject) => { try { const label = await field.getLabel(); @@ -72,7 +75,7 @@ export class TooltipSelector extends Component { type: type, name: field.getName() }); - }catch(e) { + } catch(e) { reject(e); } }); diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 187e046a2eb6c..fc9b3e7ca86eb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -23,6 +23,7 @@ export class ESDocField extends AbstractField { } async getType() { + console.trace(); const field = await this._getField(); return field.type; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 49a24c398213f..e3db8c564770b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -16,6 +16,8 @@ export class AbstractField { }; constructor({ fieldName, source }) { + console.trace(); + console.log('make field', source, fieldName); this._fieldName = fieldName; this._source = source; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 40cbdd24e21b7..93bf4de3cbe6d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -68,7 +68,7 @@ export class ESSearchSource extends AbstractESSource { topHitsSize: _.get(descriptor, 'topHitsSize', 1), }, inspectorAdapters); - this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField(property)); + this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField({ fieldName: property })); } createField({ fieldName }) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index 05bdfe701e356..fa1c828dd9ffa 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -77,12 +77,17 @@ export class UpdateSourceEditor extends Component { //todo move this all to the source const rawTooltipFields = getSourceFields(indexPattern.fields); const tooltipFields = rawTooltipFields.map(field => { + console.log('f', field, field.name); + if (!field.name) { + console.log('this field has no name!', field); + } return new ESDocField({ fieldName: field.name, source: this.props.source }); }); + console.log('set state', tooltipFields); this.setState({ tooltipFields: tooltipFields, termFields: getTermsFields(indexPattern.fields), //todo change term fields to use fields @@ -175,6 +180,7 @@ export class UpdateSourceEditor extends Component { } render() { + console.log('ttf - apsed in', this.props.tooltipFields); return ( diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss b/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss index 971f92fe76152..bd517f81517c2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss +++ b/x-pack/legacy/plugins/maps/public/layers/styles/_index.scss @@ -1,3 +1,3 @@ -@import './color_gradient'; -@import 'vector/components/static_dynamic_style_row'; -@import 'vector/components/vector/color/color_stops'; +@import './components/color_gradient'; +@import './components/static_dynamic_style_row'; +@import './vector/components/color/color_stops'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js b/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js index 9e96b25645ada..78a7c9d51739a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js @@ -8,7 +8,7 @@ import React from 'react'; import { vislibColorMaps } from 'ui/vislib/components/color/colormaps'; import { getLegendColors, getColor } from 'ui/vis/map/color_util'; -import { ColorGradient } from './color_gradient'; +import { ColorGradient } from './components/color_gradient'; import { palettes } from '@elastic/eui/lib/services'; import tinycolor from 'tinycolor2'; import chroma from 'chroma-js'; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/_color_gradient.scss b/x-pack/legacy/plugins/maps/public/layers/styles/components/_color_gradient.scss similarity index 100% rename from x-pack/legacy/plugins/maps/public/layers/styles/_color_gradient.scss rename to x-pack/legacy/plugins/maps/public/layers/styles/components/_color_gradient.scss diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/_static_dynamic_style_row.scss b/x-pack/legacy/plugins/maps/public/layers/styles/components/_static_dynamic_style_row.scss new file mode 100644 index 0000000000000..8ec006d32a8b9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/_static_dynamic_style_row.scss @@ -0,0 +1,3 @@ +.mapStaticDynamicSylingOption__dynamicSizeHack { + width: calc(100% - #{$euiSizeXXL + $euiSizeS}); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js new file mode 100644 index 0000000000000..b416d869e592b --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/color_gradient.js @@ -0,0 +1,27 @@ +/* + * 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 React from 'react'; +import { COLOR_RAMP_NAMES, getRGBColorRangeStrings, getLinearGradient } from '../color_utils'; +import classNames from 'classnames'; + +export const ColorGradient = ({ colorRamp, colorRampName, className }) => { + if (!colorRamp && (!colorRampName || !COLOR_RAMP_NAMES.includes(colorRampName))) { + return null; + } + + const classes = classNames('mapColorGradient', className); + const rgbColorStrings = colorRampName + ? getRGBColorRangeStrings(colorRampName) + : colorRamp; + const background = getLinearGradient(rgbColorStrings); + return ( +
+ ); +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js new file mode 100644 index 0000000000000..5537bb90fa245 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/static_dynamic_style_row.js @@ -0,0 +1,127 @@ +/* + * 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 React from 'react'; +import { VectorStyle } from '../vector/vector_style'; +import _ from 'lodash'; +import { i18n } from '@kbn/i18n'; + +import { EuiFlexGroup, EuiFlexItem, EuiToolTip, EuiFormRow, EuiButtonToggle } from '@elastic/eui'; + +export class StaticDynamicStyleRow extends React.Component { + // Store previous options locally so when type is toggled, + // previous style options can be used. + prevStaticStyleOptions = this.props.defaultStaticStyleOptions; + prevDynamicStyleOptions = this.props.defaultDynamicStyleOptions; + + _canBeDynamic() { + return this.props.ordinalFields.length > 0; + } + + _isDynamic() { + if (!this.props.styleDescriptor) { + return false; + } + return this.props.styleDescriptor.type === VectorStyle.STYLE_TYPE.DYNAMIC; + } + + _getStyleOptions() { + return _.get(this.props, 'styleDescriptor.options'); + } + + _onStaticStyleChange = options => { + const styleDescriptor = { + type: VectorStyle.STYLE_TYPE.STATIC, + options, + }; + this.props.handlePropertyChange(this.props.property, styleDescriptor); + }; + + _onDynamicStyleChange = options => { + const styleDescriptor = { + type: VectorStyle.STYLE_TYPE.DYNAMIC, + options, + }; + this.props.handlePropertyChange(this.props.property, styleDescriptor); + }; + + _onTypeToggle = () => { + if (this._isDynamic()) { + // preserve current dynmaic style + this.prevDynamicStyleOptions = this._getStyleOptions(); + // toggle to static style + this._onStaticStyleChange(this.prevStaticStyleOptions); + return; + } + + // preserve current static style + this.prevStaticStyleOptions = this._getStyleOptions(); + // toggle to dynamic style + this._onDynamicStyleChange(this.prevDynamicStyleOptions); + }; + + _renderStyleSelector() { + if (this._isDynamic()) { + const DynamicSelector = this.props.DynamicSelector; + return ( + + ); + } + + const StaticSelector = this.props.StaticSelector; + return ( + + ); + } + + render() { + const isDynamic = this._isDynamic(); + const dynamicTooltipContent = isDynamic + ? i18n.translate('xpack.maps.styles.staticDynamic.staticDescription', { + defaultMessage: 'Use static styling properties to symbolize features.', + }) + : i18n.translate('xpack.maps.styles.staticDynamic.dynamicDescription', { + defaultMessage: 'Use property values to symbolize features.', + }); + + return ( + + + + {this._renderStyleSelector()} + + + {this._canBeDynamic() && ( + + + + + + + + )} + + ); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/components/style_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/components/style_legend_row.js new file mode 100644 index 0000000000000..3691f18cbeba6 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/components/style_legend_row.js @@ -0,0 +1,66 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; + +import { + EuiFlexGroup, + EuiFlexItem, + EuiText, + EuiSpacer, + EuiToolTip, +} from '@elastic/eui'; + +export function StyleLegendRow({ header, minLabel, maxLabel, propertyLabel, fieldLabel }) { + return ( +
+ + {header} + + + + {minLabel} + + + + + + {fieldLabel} + + + + + + {maxLabel} + + + +
+ ); +} + +StyleLegendRow.propTypes = { + header: PropTypes.node.isRequired, + minLabel: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.number, + ]).isRequired, + maxLabel: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.number, + ]).isRequired, + propertyLabel: PropTypes.string.isRequired, + fieldLabel: PropTypes.string.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js index f461bb580b281..a0f86dcf5130b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/heatmap_style_editor.js @@ -8,7 +8,7 @@ import React from 'react'; import { EuiFormRow, EuiSuperSelect } from '@elastic/eui'; import { COLOR_GRADIENTS } from '../../color_utils'; -import { ColorGradient } from '../../color_gradient'; +import { ColorGradient } from '../../components/color_gradient'; import { DEFAULT_RGB_HEATMAP_COLOR_RAMP, DEFAULT_HEATMAP_COLOR_RAMP_NAME, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js index dddc4f88e9bee..06709ba0ebf21 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js @@ -7,8 +7,8 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { ColorGradient } from '../../../color_gradient'; -import { StyleLegendRow } from '../../../vector/components/style_legend_row'; +import { ColorGradient } from '../../../components/color_gradient'; +import { StyleLegendRow } from '../../../components/style_legend_row'; import { DEFAULT_RGB_HEATMAP_COLOR_RAMP, DEFAULT_HEATMAP_COLOR_RAMP_NAME, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/__snapshots__/vector_style_symbol_editor.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/__snapshots__/vector_style_symbol_editor.test.js.snap new file mode 100644 index 0000000000000..43ba2108242d5 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/__snapshots__/vector_style_symbol_editor.test.js.snap @@ -0,0 +1,98 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Should render icon select when symbolized as Icon 1`] = ` + + + + + + + +`; + +exports[`Should render symbol select when symbolized as Circle 1`] = ` + + + + + +`; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/_color_stops.scss b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/_color_stops.scss new file mode 100644 index 0000000000000..001ca0685d0e9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/_color_stops.scss @@ -0,0 +1,39 @@ +.mapColorStop { + position: relative; + padding-right: $euiSizeXL + $euiSizeS; + + & + & { + margin-top: $euiSizeS; + } + + &:hover, + &:focus { + .mapColorStop__icons { + visibility: visible; + opacity: 1; + display: block; + animation: mapColorStopBecomeVisible $euiAnimSpeedFast $euiAnimSlightResistance; + } + } +} + +.mapColorStop__icons { + flex-shrink: 0; + display: none; + position: absolute; + right: 0; + top: 50%; + margin-right: -$euiSizeS; + margin-top: -$euiSizeM; +} + +@keyframes mapColorStopBecomeVisible { + + 0% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_ramp_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_ramp_select.js new file mode 100644 index 0000000000000..c2dd51a0182e3 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_ramp_select.js @@ -0,0 +1,106 @@ +/* + * 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 React, { Component, Fragment } from 'react'; +import PropTypes from 'prop-types'; + +import { EuiSuperSelect, EuiSpacer } from '@elastic/eui'; +import { COLOR_GRADIENTS } from '../../../color_utils'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { ColorStops } from './color_stops'; + +const CUSTOM_COLOR_RAMP = 'CUSTOM_COLOR_RAMP'; + +export class ColorRampSelect extends Component { + state = {}; + + static getDerivedStateFromProps(nextProps, prevState) { + if (nextProps.customColorRamp !== prevState.prevPropsCustomColorRamp) { + return { + prevPropsCustomColorRamp: nextProps.customColorRamp, // reset tracker to latest value + customColorRamp: nextProps.customColorRamp, // reset customColorRamp to latest value + }; + } + + return null; + } + + _onColorRampSelect = selectedValue => { + const useCustomColorRamp = selectedValue === CUSTOM_COLOR_RAMP; + this.props.onChange({ + color: useCustomColorRamp ? null : selectedValue, + useCustomColorRamp, + }); + }; + + _onCustomColorRampChange = ({ colorStops, isInvalid }) => { + // Manage invalid custom color ramp in local state + if (isInvalid) { + this.setState({ customColorRamp: colorStops }); + return; + } + + this.props.onChange({ + customColorRamp: colorStops, + }); + }; + + render() { + const { + color, + onChange, // eslint-disable-line no-unused-vars + useCustomColorRamp, + customColorRamp, // eslint-disable-line no-unused-vars + ...rest + } = this.props; + + let colorStopsInput; + if (useCustomColorRamp) { + colorStopsInput = ( + + + + + ); + } + + const colorRampOptions = [ + { + value: CUSTOM_COLOR_RAMP, + inputDisplay: ( + + ), + }, + ...COLOR_GRADIENTS, + ]; + + return ( + + + {colorStopsInput} + + ); + } +} + +ColorRampSelect.propTypes = { + color: PropTypes.string, + onChange: PropTypes.func.isRequired, + useCustomColorRamp: PropTypes.bool, + customColorRamp: PropTypes.array, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops.js new file mode 100644 index 0000000000000..df8464d141b5a --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops.js @@ -0,0 +1,155 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; + +import { + EuiColorPicker, + EuiFormRow, + EuiFieldNumber, + EuiFlexGroup, + EuiFlexItem, + EuiButtonIcon, +} from '@elastic/eui'; +import { addRow, removeRow, isColorInvalid, isStopInvalid, isInvalid } from './color_stops_utils'; + +const DEFAULT_COLOR = '#FF0000'; + +export const ColorStops = ({ colorStops = [{ stop: 0, color: DEFAULT_COLOR }], onChange }) => { + function getStopInput(stop, index) { + const onStopChange = e => { + const newColorStops = _.cloneDeep(colorStops); + const sanitizedValue = parseFloat(e.target.value); + newColorStops[index].stop = isNaN(sanitizedValue) ? '' : sanitizedValue; + onChange({ + colorStops: newColorStops, + isInvalid: isInvalid(newColorStops), + }); + }; + + let error; + if (isStopInvalid(stop)) { + error = 'Stop must be a number'; + } else if (index !== 0 && colorStops[index - 1].stop >= stop) { + error = 'Stop must be greater than previous stop value'; + } + + return { + stopError: error, + stopInput: ( + + ), + }; + } + + function getColorInput(color, index) { + const onColorChange = color => { + const newColorStops = _.cloneDeep(colorStops); + newColorStops[index].color = color; + onChange({ + colorStops: newColorStops, + isInvalid: isInvalid(newColorStops), + }); + }; + + return { + colorError: isColorInvalid(color) ? 'Color must provide a valid hex value' : undefined, + colorInput: , + }; + } + + const rows = colorStops.map((colorStop, index) => { + const { stopError, stopInput } = getStopInput(colorStop.stop, index); + const { colorError, colorInput } = getColorInput(colorStop.color, index); + const errors = []; + if (stopError) { + errors.push(stopError); + } + if (colorError) { + errors.push(colorError); + } + + const onRemove = () => { + const newColorStops = removeRow(colorStops, index); + onChange({ + colorStops: newColorStops, + isInvalid: isInvalid(newColorStops), + }); + }; + + const onAdd = () => { + const newColorStops = addRow(colorStops, index); + + onChange({ + colorStops: newColorStops, + isInvalid: isInvalid(newColorStops), + }); + }; + + let deleteButton; + if (colorStops.length > 1) { + deleteButton = ( + + ); + } + + return ( + +
+ + {stopInput} + {colorInput} + +
+ {deleteButton} + +
+
+
+ ); + }); + + return
{rows}
; +}; + +ColorStops.propTypes = { + /** + * Array of { stop, color }. + * Stops are numbers in strictly ascending order. + * The range is from the given stop number (inclusive) to the next stop number (exclusive). + * Colors are color hex strings (3 or 6 character). + */ + colorStops: PropTypes.arrayOf( + PropTypes.shape({ + stopKey: PropTypes.number, + color: PropTypes.string, + }) + ), + /** + * Callback for when the color stops changes. Called with { colorStops, isInvalid } + */ + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops_utils.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops_utils.js new file mode 100644 index 0000000000000..51aba22729056 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_stops_utils.js @@ -0,0 +1,66 @@ +/* + * 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 { isValidHex } from '@elastic/eui'; + +export function removeRow(colorStops, index) { + if (colorStops.length === 1) { + return colorStops; + } + + return [...colorStops.slice(0, index), ...colorStops.slice(index + 1)]; +} + +export function addRow(colorStops, index) { + const currentStop = colorStops[index].stop; + let delta = 1; + if (index === colorStops.length - 1) { + // Adding row to end of list. + if (index !== 0) { + const prevStop = colorStops[index - 1].stop; + delta = currentStop - prevStop; + } + } else { + // Adding row in middle of list. + const nextStop = colorStops[index + 1].stop; + delta = (nextStop - currentStop) / 2; + } + + const newRow = { + stop: currentStop + delta, + color: '#FF0000', + }; + return [ + ...colorStops.slice(0, index + 1), + newRow, + ...colorStops.slice(index + 1), + ]; +} + +export function isColorInvalid(color) { + return !isValidHex(color) || color === ''; +} + +export function isStopInvalid(stop) { + return stop === '' || isNaN(stop); +} + +export function isInvalid(colorStops) { + return colorStops.some((colorStop, index) => { + // expect stops to be in ascending order + let isDescending = false; + if (index !== 0) { + const prevStop = colorStops[index - 1].stop; + isDescending = prevStop >= colorStop.stop; + } + + return ( + isColorInvalid(colorStop.color) || + isStopInvalid(colorStop.stop) || + isDescending + ); + }); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_selection.js new file mode 100644 index 0000000000000..2db92ba7f9337 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_selection.js @@ -0,0 +1,48 @@ +/* + * 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 React, { Fragment } from 'react'; +import PropTypes from 'prop-types'; +import { dynamicColorShape } from '../style_option_shapes'; +import { FieldSelect, fieldShape } from '../field_select'; +import { ColorRampSelect } from './color_ramp_select'; +import { EuiSpacer } from '@elastic/eui'; + +export function DynamicColorSelection({ ordinalFields, onChange, styleOptions }) { + const onFieldChange = ({ field }) => { + onChange({ ...styleOptions, field }); + }; + + const onColorChange = colorOptions => { + onChange({ ...styleOptions, ...colorOptions }); + }; + + return ( + + + + + + ); +} + +DynamicColorSelection.propTypes = { + ordinalFields: PropTypes.arrayOf(fieldShape).isRequired, + styleOptions: dynamicColorShape.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/static_color_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/static_color_selection.js new file mode 100644 index 0000000000000..e42b582dc3929 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/static_color_selection.js @@ -0,0 +1,30 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; +import { EuiColorPicker } from '@elastic/eui'; +import { staticColorShape } from '../style_option_shapes'; + +export function StaticColorSelection({ onChange, styleOptions, swatches }) { + const onColorChange = color => { + onChange({ color }); + }; + + return ( + + ); +} + +StaticColorSelection.propTypes = { + styleOptions: staticColorShape.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/vector_style_color_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/vector_style_color_editor.js new file mode 100644 index 0000000000000..a39db57dc4883 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/vector_style_color_editor.js @@ -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 React from 'react'; + +import { StaticDynamicStyleRow } from '../../../components/static_dynamic_style_row'; +import { DynamicColorSelection } from './dynamic_color_selection'; +import { StaticColorSelection } from './static_color_selection'; +import { getVectorStyleLabel } from '../get_vector_style_label'; + +export function VectorStyleColorEditor(props) { + return ( + + ); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js new file mode 100644 index 0000000000000..1d8f4e13fdd1a --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js @@ -0,0 +1,86 @@ +/* + * 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 PropTypes from 'prop-types'; +import React from 'react'; + +import { EuiComboBox } from '@elastic/eui'; +import { SOURCE_DATA_ID_ORIGIN } from '../../../../../common/constants'; +import { i18n } from '@kbn/i18n'; + +export function FieldSelect({ fields, selectedFieldName, onChange, ...rest }) { + const onFieldChange = selectedFields => { + onChange({ + field: selectedFields.length > 0 ? selectedFields[0].value : null, + }); + }; + + const groupFieldsByOrigin = () => { + const fieldsByOriginMap = new Map(); + fields.forEach(field => { + if (fieldsByOriginMap.has(field.origin)) { + const fieldsList = fieldsByOriginMap.get(field.origin); + fieldsList.push(field); + fieldsByOriginMap.set(field.origin, fieldsList); + } else { + fieldsByOriginMap.set(field.origin, [field]); + } + }); + + const optionGroups = []; + fieldsByOriginMap.forEach((fieldsList, fieldOrigin) => { + optionGroups.push({ + label: fieldOrigin, + options: fieldsList + .map(field => { + return { value: field, label: field.label }; + }) + .sort((a, b) => { + return a.label.toLowerCase().localeCompare(b.label.toLowerCase()); + }), + }); + }); + + optionGroups.sort((a, b) => { + return a.label.toLowerCase().localeCompare(b.label.toLowerCase()); + }); + + return optionGroups; + }; + + let selectedOption; + if (selectedFieldName) { + selectedOption = fields.find(field => { + return field.name === selectedFieldName; + }); + } + + return ( + + ); +} + +export const fieldShape = PropTypes.shape({ + name: PropTypes.string.isRequired, + origin: PropTypes.oneOf(['join', SOURCE_DATA_ID_ORIGIN]).isRequired, +}); + +FieldSelect.propTypes = { + selectedFieldName: PropTypes.string, + fields: PropTypes.arrayOf(fieldShape).isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/get_vector_style_label.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/get_vector_style_label.js new file mode 100644 index 0000000000000..b6cc215ec6ded --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/get_vector_style_label.js @@ -0,0 +1,32 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +import { vectorStyles } from '../vector_style_defaults'; + +export function getVectorStyleLabel(styleName) { + switch (styleName) { + case vectorStyles.FILL_COLOR: + return i18n.translate('xpack.maps.styles.vector.fillColorLabel', { + defaultMessage: 'Fill color' + }); + case vectorStyles.LINE_COLOR: + return i18n.translate('xpack.maps.styles.vector.borderColorLabel', { + defaultMessage: 'Border color' + }); + case vectorStyles.LINE_WIDTH: + return i18n.translate('xpack.maps.styles.vector.borderWidthLabel', { + defaultMessage: 'Border width' + }); + case vectorStyles.ICON_SIZE: + return i18n.translate('xpack.maps.styles.vector.symbolSizeLabel', { + defaultMessage: 'Symbol size' + }); + default: + return styleName; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap new file mode 100644 index 0000000000000..57368b52a2bce --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/__snapshots__/vector_icon.test.js.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renders CircleIcon with correct styles when isPointOnly 1`] = ` + +`; + +exports[`Renders LineIcon with correct styles when isLineOnly 1`] = ` + +`; + +exports[`Renders PolygonIcon with correct styles when not line only or not point only 1`] = ` + +`; + +exports[`Renders SymbolIcon with correct styles when isPointOnly and symbolId provided 1`] = ` + +`; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/circle_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/circle_icon.js new file mode 100644 index 0000000000000..5efba64360f23 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/circle_icon.js @@ -0,0 +1,44 @@ +/* + * 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 React from 'react'; + +export const CircleIcon = ({ style }) => ( + + + + + + + + +); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/line_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/line_icon.js new file mode 100644 index 0000000000000..0f5b6e4b470bf --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/line_icon.js @@ -0,0 +1,13 @@ +/* + * 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 React from 'react'; + +export const LineIcon = ({ style }) => ( + + + +); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/polygon_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/polygon_icon.js new file mode 100644 index 0000000000000..4907a853e2cda --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/polygon_icon.js @@ -0,0 +1,18 @@ +/* + * 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 React from 'react'; + +export const PolygonIcon = ({ style }) => ( + + + +); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js new file mode 100644 index 0000000000000..4d091389a360e --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -0,0 +1,170 @@ +/* + * 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 React, { Component, Fragment } from 'react'; +import PropTypes from 'prop-types'; + +import { styleOptionShapes, rangeShape } from '../style_option_shapes'; +import { VectorStyle } from '../../vector_style'; +import { ColorGradient } from '../../../components/color_gradient'; +import { CircleIcon } from './circle_icon'; +import { getVectorStyleLabel } from '../get_vector_style_label'; +import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule } from '@elastic/eui'; +import { StyleLegendRow } from '../../../components/style_legend_row'; + +function getLineWidthIcons() { + const defaultStyle = { + stroke: 'grey', + fill: 'none', + width: '12px', + }; + return [ + , + , + , + ]; +} + +function getSymbolSizeIcons() { + const defaultStyle = { + stroke: 'grey', + strokeWidth: 'none', + fill: 'grey', + }; + return [ + , + , + , + ]; +} + +function renderHeaderWithIcons(icons) { + return ( + + { + icons.map((icon, index) => { + const isLast = index === icons.length - 1; + let spacer; + if (!isLast) { + spacer = ( + + + + ); + } + return ( + + + {icon} + + {spacer} + + ); + }) + } + + ); +} + +const EMPTY_VALUE = ''; + +export class StylePropertyLegendRow extends Component { + + state = { + label: '', + hasLoadedFieldFormatter: false, + } + + componentDidMount() { + this._isMounted = true; + this._prevLabel = undefined; + this._fieldValueFormatter = undefined; + this._loadLabel(); + this._loadFieldFormatter(); + } + + componentDidUpdate() { + // label could change so it needs to be loaded on update + this._loadLabel(); + } + + componentWillUnmount() { + this._isMounted = false; + } + + async _loadFieldFormatter() { + this._fieldValueFormatter = await this.props.getFieldFormatter(this.props.options.field); + if (this._isMounted) { + this.setState({ hasLoadedFieldFormatter: true }); + } + } + + _loadLabel = async () => { + if (this._isStatic()) { + return; + } + + // have to load label and then check for changes since field name stays constant while label may change + const label = await this.props.getFieldLabel(this.props.options.field.name); + if (this._prevLabel === label) { + return; + } + + this._prevLabel = label; + if (this._isMounted) { + this.setState({ label }); + } + } + + _isStatic() { + return this.props.type === VectorStyle.STYLE_TYPE.STATIC || + !this.props.options.field || !this.props.options.field.name; + } + + _formatValue = value => { + if (!this.state.hasLoadedFieldFormatter || !this._fieldValueFormatter || value === EMPTY_VALUE) { + return value; + } + + return this._fieldValueFormatter(value); + } + + render() { + const { name, options, range } = this.props; + if (this._isStatic()) { + return null; + } + + let header; + if (options.color) { + header = ; + } else if (name === 'lineWidth') { + header = renderHeaderWithIcons(getLineWidthIcons()); + } else if (name === 'iconSize') { + header = renderHeaderWithIcons(getSymbolSizeIcons()); + } + + return ( + + ); + } +} + +StylePropertyLegendRow.propTypes = { + name: PropTypes.string.isRequired, + type: PropTypes.string, + options: PropTypes.oneOfType(styleOptionShapes).isRequired, + range: rangeShape, + getFieldLabel: PropTypes.func.isRequired, + getFieldFormatter: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js new file mode 100644 index 0000000000000..d241226e577a8 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/symbol_icon.js @@ -0,0 +1,79 @@ +/* + * 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 React, { Component } from 'react'; +import PropTypes from 'prop-types'; + +import { getMakiSymbolSvg, styleSvg, buildSrcUrl } from '../../symbol_utils'; + +export class SymbolIcon extends Component { + + state = { + imgDataUrl: undefined, + prevSymbolId: undefined, + prevFill: undefined, + prevStroke: undefined, + prevStrokeWidth: undefined, + } + + componentDidMount() { + this._isMounted = true; + this._loadSymbol(this.props.symbolId, this.props.fill, this.props.stroke, this.props.strokeWidth); + } + + componentDidUpdate() { + this._loadSymbol(this.props.symbolId, this.props.fill, this.props.stroke, this.props.strokeWidth); + } + + componentWillUnmount() { + this._isMounted = false; + } + + async _loadSymbol(nextSymbolId, nextFill, nextStroke, nextStrokeWidth) { + if (nextSymbolId === this.state.prevSymbolId + && nextFill === this.state.prevFill + && nextStroke === this.state.prevStroke + && nextStrokeWidth === this.state.prevStrokeWidth) { + return; + } + + let imgDataUrl; + try { + const svg = getMakiSymbolSvg(nextSymbolId); + const styledSvg = await styleSvg(svg, nextFill, nextStroke, nextStrokeWidth); + imgDataUrl = buildSrcUrl(styledSvg); + } catch (error) { + // ignore failures - component will just not display an icon + } + + if (this._isMounted) { + this.setState({ + imgDataUrl, + prevSymbolId: nextSymbolId, + prevFill: nextFill, + prevStroke: nextStroke, + prevStrokeWidth: nextStrokeWidth + }); + } + } + + render() { + if (!this.state.imgDataUrl) { + return null; + } + + return ( + {this.props.symbolId} + ); + } +} + +SymbolIcon.propTypes = { + symbolId: PropTypes.string.isRequired, + fill: PropTypes.string.isRequired, + stroke: PropTypes.string.isRequired, + strokeWidth: PropTypes.string.isRequired +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js new file mode 100644 index 0000000000000..5b86b88572552 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.js @@ -0,0 +1,128 @@ +/* + * 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 React, { Component } from 'react'; +import PropTypes from 'prop-types'; + +import { dynamicColorShape, staticColorShape } from '../style_option_shapes'; +import { CircleIcon } from './circle_icon'; +import { LineIcon } from './line_icon'; +import { PolygonIcon } from './polygon_icon'; +import { SymbolIcon } from './symbol_icon'; +import { VectorStyle } from '../../vector_style'; +import { getColorRampCenterColor } from '../../../color_utils'; + +export class VectorIcon extends Component { + + state = { + isInitialized: false + } + + componentDidMount() { + this._isMounted = true; + this._init(); + } + + componentWillUnmount() { + this._isMounted = false; + } + + async _init() { + const isPointsOnly = await this.props.loadIsPointsOnly(); + const isLinesOnly = await this.props.loadIsLinesOnly(); + if (this._isMounted) { + this.setState({ + isInitialized: true, + isPointsOnly, + isLinesOnly, + }); + } + } + + render() { + if (!this.state.isInitialized) { + return null; + } + + if (this.state.isLinesOnly) { + const style = { + stroke: extractColorFromStyleProperty(this.props.lineColor, 'grey'), + strokeWidth: '4px', + }; + return ( + + ); + } + + const style = { + stroke: extractColorFromStyleProperty(this.props.lineColor, 'none'), + strokeWidth: '1px', + fill: extractColorFromStyleProperty(this.props.fillColor, 'grey'), + }; + + if (!this.state.isPointsOnly) { + return (); + } + + if (!this.props.symbolId) { + return (); + } + + return ( + + ); + } +} + +function extractColorFromStyleProperty(colorStyleProperty, defaultColor) { + if (!colorStyleProperty) { + return defaultColor; + } + + if (colorStyleProperty.type === VectorStyle.STYLE_TYPE.STATIC) { + return colorStyleProperty.options.color; + } + + // Do not use dynamic color unless configuration is complete + if (!colorStyleProperty.options.field || !colorStyleProperty.options.field.name) { + return defaultColor; + } + + // return middle of gradient for dynamic style property + + if (colorStyleProperty.options.useCustomColorRamp) { + if (!colorStyleProperty.options.customColorRamp || + !colorStyleProperty.options.customColorRamp.length) { + return defaultColor; + } + // favor the lowest color in even arrays + const middleIndex = Math.floor((colorStyleProperty.options.customColorRamp.length - 1) / 2); + return colorStyleProperty.options.customColorRamp[middleIndex].color; + } + + return getColorRampCenterColor(colorStyleProperty.options.color); +} + +const colorStylePropertyShape = PropTypes.shape({ + type: PropTypes.string.isRequired, + options: PropTypes.oneOfType([ + dynamicColorShape, + staticColorShape + ]).isRequired, +}); + +VectorIcon.propTypes = { + fillColor: colorStylePropertyShape, + lineColor: colorStylePropertyShape, + symbolId: PropTypes.string, + loadIsPointsOnly: PropTypes.func.isRequired, + loadIsLinesOnly: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.test.js new file mode 100644 index 0000000000000..1a16035fe6d33 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_icon.test.js @@ -0,0 +1,117 @@ +/* + * 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 React from 'react'; +import { shallow } from 'enzyme'; + +import { VectorIcon } from './vector_icon'; +import { VectorStyle } from '../../vector_style'; + +let isPointsOnly = false; +let isLinesOnly = false; +const defaultProps = { + loadIsPointsOnly: () => { return isPointsOnly; }, + loadIsLinesOnly: () => { return isLinesOnly; }, + fillColor: { + type: VectorStyle.STYLE_TYPE.STATIC, + options: { + color: '#ff0000', + } + }, + lineColor: { + type: VectorStyle.STYLE_TYPE.DYNAMIC, + options: { + color: 'Blues', + field: { + name: 'prop1' + } + } + } +}; + +function configureIsLinesOnly() { + isLinesOnly = true; + isPointsOnly = false; +} + +function configureIsPointsOnly() { + isLinesOnly = false; + isPointsOnly = true; +} + +function configureNotLineOrPointOnly() { + isLinesOnly = false; + isPointsOnly = false; +} + +test('Renders PolygonIcon with correct styles when not line only or not point only', async () => { + configureNotLineOrPointOnly(); + const component = shallow( + + ); + + // Ensure all promises resolve + await new Promise(resolve => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + + expect(component) + .toMatchSnapshot(); +}); + +test('Renders LineIcon with correct styles when isLineOnly', async () => { + configureIsLinesOnly(); + const component = shallow( + + ); + + // Ensure all promises resolve + await new Promise(resolve => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + + expect(component) + .toMatchSnapshot(); +}); + +test('Renders CircleIcon with correct styles when isPointOnly', async () => { + configureIsPointsOnly(); + const component = shallow( + + ); + + // Ensure all promises resolve + await new Promise(resolve => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + + expect(component) + .toMatchSnapshot(); +}); + +test('Renders SymbolIcon with correct styles when isPointOnly and symbolId provided', async () => { + configureIsPointsOnly(); + const component = shallow( + + ); + + // Ensure all promises resolve + await new Promise(resolve => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + + expect(component) + .toMatchSnapshot(); +}); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js new file mode 100644 index 0000000000000..60baaff158377 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js @@ -0,0 +1,40 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; + +import { styleOptionShapes, rangeShape } from '../style_option_shapes'; +import { StylePropertyLegendRow } from './style_property_legend_row'; + +export function VectorStyleLegend({ getFieldLabel, getFieldFormatter, styleProperties }) { + return styleProperties.map(styleProperty => { + return ( + + ); + }); +} + +const stylePropertyShape = PropTypes.shape({ + name: PropTypes.string.isRequired, + type: PropTypes.string, + options: PropTypes.oneOfType(styleOptionShapes).isRequired, + range: rangeShape, +}); + +VectorStyleLegend.propTypes = { + styleProperties: PropTypes.arrayOf(stylePropertyShape).isRequired, + getFieldLabel: PropTypes.func.isRequired, + getFieldFormatter: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/dynamic_orientation_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/dynamic_orientation_selection.js new file mode 100644 index 0000000000000..6df3283737c73 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/dynamic_orientation_selection.js @@ -0,0 +1,32 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; +import { dynamicOrientationShape } from '../style_option_shapes'; +import { FieldSelect, fieldShape } from '../field_select'; + +export function DynamicOrientationSelection({ ordinalFields, styleOptions, onChange }) { + const onFieldChange = ({ field }) => { + onChange({ ...styleOptions, field }); + }; + + return ( + + ); +} + +DynamicOrientationSelection.propTypes = { + ordinalFields: PropTypes.arrayOf(fieldShape).isRequired, + styleOptions: dynamicOrientationShape.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/orientation_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/orientation_editor.js new file mode 100644 index 0000000000000..65efddae90933 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/orientation_editor.js @@ -0,0 +1,30 @@ +/* + * 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 React from 'react'; + +import { StaticDynamicStyleRow } from '../../../components/static_dynamic_style_row'; +import { DynamicOrientationSelection } from './dynamic_orientation_selection'; +import { StaticOrientationSelection } from './static_orientation_selection'; +import { i18n } from '@kbn/i18n'; + +export function OrientationEditor(props) { + return ( + + ); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/static_orientation_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/static_orientation_selection.js new file mode 100644 index 0000000000000..b5529c6987459 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/orientation/static_orientation_selection.js @@ -0,0 +1,34 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; +import { staticOrientationShape } from '../style_option_shapes'; +import { ValidatedRange } from '../../../../../components/validated_range'; + +export function StaticOrientationSelection({ onChange, styleOptions }) { + const onOrientationChange = orientation => { + onChange({ orientation }); + }; + + return ( + + ); +} + +StaticOrientationSelection.propTypes = { + styleOptions: staticOrientationShape.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/dynamic_size_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/dynamic_size_selection.js new file mode 100644 index 0000000000000..6f8161d26cd6c --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/dynamic_size_selection.js @@ -0,0 +1,48 @@ +/* + * 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 React, { Fragment } from 'react'; +import PropTypes from 'prop-types'; +import { dynamicSizeShape } from '../style_option_shapes'; +import { FieldSelect, fieldShape } from '../field_select'; +import { SizeRangeSelector } from './size_range_selector'; +import { EuiSpacer } from '@elastic/eui'; + +export function DynamicSizeSelection({ ordinalFields, styleOptions, onChange }) { + const onFieldChange = ({ field }) => { + onChange({ ...styleOptions, field }); + }; + + const onSizeRangeChange = ({ minSize, maxSize }) => { + onChange({ ...styleOptions, minSize, maxSize }); + }; + + return ( + + + + + + ); +} + +DynamicSizeSelection.propTypes = { + ordinalFields: PropTypes.arrayOf(fieldShape).isRequired, + styleOptions: dynamicSizeShape.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/size_range_selector.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/size_range_selector.js new file mode 100644 index 0000000000000..4279fbbe0fbb3 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/size_range_selector.js @@ -0,0 +1,44 @@ +/* + * 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 React from 'react'; +import PropTypes from 'prop-types'; +import { ValidatedDualRange } from 'ui/validated_range'; +import { DEFAULT_MIN_SIZE, DEFAULT_MAX_SIZE } from '../../vector_style_defaults'; +import { i18n } from '@kbn/i18n'; + +export function SizeRangeSelector({ minSize, maxSize, onChange, ...rest }) { + const onSizeChange = ([min, max]) => { + onChange({ + minSize: Math.max(DEFAULT_MIN_SIZE, parseInt(min, 10)), + maxSize: Math.min(DEFAULT_MAX_SIZE, parseInt(max, 10)), + }); + }; + + return ( + + ); +} + +SizeRangeSelector.propTypes = { + minSize: PropTypes.number.isRequired, + maxSize: PropTypes.number.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/static_size_selection.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/static_size_selection.js new file mode 100644 index 0000000000000..38f8fe53d1748 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/static_size_selection.js @@ -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 React from 'react'; +import PropTypes from 'prop-types'; +import { staticSizeShape } from '../style_option_shapes'; +import { ValidatedRange } from '../../../../../components/validated_range'; +import { i18n } from '@kbn/i18n'; + +export function StaticSizeSelection({ onChange, styleOptions }) { + const onSizeChange = size => { + onChange({ size }); + }; + + return ( + + ); +} + +StaticSizeSelection.propTypes = { + styleOptions: staticSizeShape.isRequired, + onChange: PropTypes.func.isRequired, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/vector_style_size_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/vector_style_size_editor.js new file mode 100644 index 0000000000000..ffaaace680a43 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/size/vector_style_size_editor.js @@ -0,0 +1,28 @@ +/* + * 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 React from 'react'; + +import { StaticDynamicStyleRow } from '../../../components/static_dynamic_style_row'; +import { DynamicSizeSelection } from './dynamic_size_selection'; +import { StaticSizeSelection } from './static_size_selection'; +import { getVectorStyleLabel } from '../get_vector_style_label'; + +export function VectorStyleSizeEditor(props) { + return ( + + ); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js new file mode 100644 index 0000000000000..d595dccaea425 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js @@ -0,0 +1,51 @@ +/* + * 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 PropTypes from 'prop-types'; +import { fieldShape } from './field_select'; + +export const staticColorShape = PropTypes.shape({ + color: PropTypes.string.isRequired, +}); + +export const dynamicColorShape = PropTypes.shape({ + color: PropTypes.string, + field: fieldShape, + customColorRamp: PropTypes.array, + useCustomColorRamp: PropTypes.bool, +}); + +export const staticOrientationShape = PropTypes.shape({ + orientation: PropTypes.number.isRequired, +}); + +export const dynamicOrientationShape = PropTypes.shape({ + field: fieldShape, +}); + +export const staticSizeShape = PropTypes.shape({ + size: PropTypes.number.isRequired, +}); + +export const dynamicSizeShape = PropTypes.shape({ + minSize: PropTypes.number.isRequired, + maxSize: PropTypes.number.isRequired, + field: fieldShape, +}); + +export const styleOptionShapes = [ + staticColorShape, + dynamicColorShape, + staticOrientationShape, + dynamicOrientationShape, + staticSizeShape, + dynamicSizeShape +]; + +export const rangeShape = PropTypes.shape({ + min: PropTypes.number.isRequired, + max: PropTypes.number.isRequired, +}); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js new file mode 100644 index 0000000000000..f624f4e661a14 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -0,0 +1,304 @@ +/* + * 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 React, { Component, Fragment } from 'react'; + +import chrome from 'ui/chrome'; +import { VectorStyleColorEditor } from './color/vector_style_color_editor'; +import { VectorStyleSizeEditor } from './size/vector_style_size_editor'; +import { VectorStyleSymbolEditor } from './vector_style_symbol_editor'; +import { OrientationEditor } from './orientation/orientation_editor'; +import { + getDefaultDynamicProperties, + getDefaultStaticProperties, + vectorStyles, +} from '../vector_style_defaults'; +import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../color_utils'; +import { VECTOR_SHAPE_TYPES } from '../../../sources/vector_feature_types'; +import { SYMBOLIZE_AS_ICON } from '../vector_constants'; +import { i18n } from '@kbn/i18n'; +import { SYMBOL_OPTIONS } from '../symbol_utils'; + +import { EuiSpacer, EuiButtonGroup } from '@elastic/eui'; + +export class VectorStyleEditor extends Component { + state = { + dateFields: [], + numberFields: [], + defaultDynamicProperties: getDefaultDynamicProperties(), + defaultStaticProperties: getDefaultStaticProperties(), + supportedFeatures: undefined, + selectedFeatureType: undefined, + }; + + componentWillUnmount() { + this._isMounted = false; + } + + componentDidMount() { + this._isMounted = true; + this._loadOrdinalFields(); + this._loadSupportedFeatures(); + } + + componentDidUpdate() { + this._loadOrdinalFields(); + this._loadSupportedFeatures(); + } + + async _loadOrdinalFields() { + + const dateFields = await this.props.layer.getDateFields(); + if (!this._isMounted) { + return; + } + if (!_.isEqual(dateFields, this.state.dateFields)) { + this.setState({ dateFields }); + } + + const numberFields = await this.props.layer.getNumberFields(); + if (!this._isMounted) { + return; + } + if (!_.isEqual(numberFields, this.state.numberFields)) { + this.setState({ numberFields }); + } + + } + + async _loadSupportedFeatures() { + const supportedFeatures = await this.props.layer.getSource().getSupportedShapeTypes(); + const isPointsOnly = await this.props.loadIsPointsOnly(); + const isLinesOnly = await this.props.loadIsLinesOnly(); + + if (!this._isMounted) { + return; + } + + if ( + _.isEqual(supportedFeatures, this.state.supportedFeatures) && + isPointsOnly === this.state.isPointsOnly && + isLinesOnly === this.state.isLinesOnly + ) { + return; + } + + let selectedFeature = VECTOR_SHAPE_TYPES.POLYGON; + if (isPointsOnly) { + selectedFeature = VECTOR_SHAPE_TYPES.POINT; + } else if (isLinesOnly) { + selectedFeature = VECTOR_SHAPE_TYPES.LINE; + } + + if ( + !_.isEqual(supportedFeatures, this.state.supportedFeatures) || + selectedFeature !== this.state.selectedFeature + ) { + this.setState({ + supportedFeatures, + selectedFeature, + isPointsOnly, + isLinesOnly, + }); + } + } + + _getOrdinalFields() { + return [...this.state.dateFields, ...this.state.numberFields]; + } + + _renderFillColor() { + return ( + + ); + } + + _renderLineColor() { + return ( + + ); + } + + _renderLineWidth() { + return ( + + ); + } + + _renderSymbolSize() { + return ( + + ); + } + + _renderPointProperties() { + let iconOrientation; + if (this.props.styleProperties.symbol.options.symbolizeAs === SYMBOLIZE_AS_ICON) { + iconOrientation = ( + + + + + ); + } + + return ( + + + + + {this._renderFillColor()} + + + {this._renderLineColor()} + + + {this._renderLineWidth()} + + + {iconOrientation} + + {this._renderSymbolSize()} + + ); + } + + _renderLineProperties() { + return ( + + {this._renderLineColor()} + + + {this._renderLineWidth()} + + ); + } + + _renderPolygonProperties() { + return ( + + {this._renderFillColor()} + + + {this._renderLineColor()} + + + {this._renderLineWidth()} + + ); + } + + _handleSelectedFeatureChange = selectedFeature => { + this.setState({ selectedFeature }); + }; + + render() { + const { supportedFeatures, selectedFeature } = this.state; + + if (!supportedFeatures) { + return null; + } + + if (supportedFeatures.length === 1) { + switch (supportedFeatures[0]) { + case VECTOR_SHAPE_TYPES.POINT: + return this._renderPointProperties(); + case VECTOR_SHAPE_TYPES.LINE: + return this._renderLineProperties(); + case VECTOR_SHAPE_TYPES.POLYGON: + return this._renderPolygonProperties(); + } + } + + const featureButtons = [ + { + id: VECTOR_SHAPE_TYPES.POINT, + label: i18n.translate('xpack.maps.vectorStyleEditor.pointLabel', { + defaultMessage: 'Points', + }), + }, + { + id: VECTOR_SHAPE_TYPES.LINE, + label: i18n.translate('xpack.maps.vectorStyleEditor.lineLabel', { + defaultMessage: 'Lines', + }), + }, + { + id: VECTOR_SHAPE_TYPES.POLYGON, + label: i18n.translate('xpack.maps.vectorStyleEditor.polygonLabel', { + defaultMessage: 'Polygons', + }), + }, + ]; + + let styleProperties = this._renderPolygonProperties(); + if (selectedFeature === VECTOR_SHAPE_TYPES.LINE) { + styleProperties = this._renderLineProperties(); + } else if (selectedFeature === VECTOR_SHAPE_TYPES.POINT) { + styleProperties = this._renderPointProperties(); + } + + return ( + + + + + + {styleProperties} + + ); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.js new file mode 100644 index 0000000000000..29be736b432f9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.js @@ -0,0 +1,136 @@ +/* + * 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 React, { Fragment } from 'react'; + +import { + EuiFlexGroup, + EuiFlexItem, + EuiFormRow, + EuiButtonGroup, + EuiSpacer, + EuiComboBox, +} from '@elastic/eui'; + +import { i18n } from '@kbn/i18n'; +import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from '../vector_constants'; +import { SymbolIcon } from './legend/symbol_icon'; + +const SYMBOLIZE_AS_OPTIONS = [ + { + id: SYMBOLIZE_AS_CIRCLE, + label: i18n.translate('xpack.maps.vector.symbolAs.circleLabel', { + defaultMessage: 'circle marker', + }), + }, + { + id: SYMBOLIZE_AS_ICON, + label: i18n.translate('xpack.maps.vector.symbolAs.IconLabel', { + defaultMessage: 'icon', + }), + }, +]; + +export function VectorStyleSymbolEditor({ + styleOptions, + handlePropertyChange, + symbolOptions, + isDarkMode, +}) { + const renderSymbolizeAsSelect = () => { + const selectedOption = SYMBOLIZE_AS_OPTIONS.find(({ id }) => { + return id === styleOptions.symbolizeAs; + }); + + const onSymbolizeAsChange = optionId => { + const styleDescriptor = { + options: { + ...styleOptions, + symbolizeAs: optionId, + }, + }; + handlePropertyChange('symbol', styleDescriptor); + }; + + return ( + + ); + }; + + const renderSymbolSelect = () => { + const selectedOption = symbolOptions.find(({ value }) => { + return value === styleOptions.symbolId; + }); + + const onSymbolChange = selectedOptions => { + if (!selectedOptions || selectedOptions.length === 0) { + return; + } + + const styleDescriptor = { + options: { + ...styleOptions, + symbolId: selectedOptions[0].value, + }, + }; + handlePropertyChange('symbol', styleDescriptor); + }; + + const renderOption = ({ value, label }) => { + return ( + + + + + {label} + + ); + }; + + return ( + + ); + }; + + return ( + + + {renderSymbolizeAsSelect()} + + + {styleOptions.symbolizeAs !== SYMBOLIZE_AS_CIRCLE && ( + + + {renderSymbolSelect()} + + )} + + ); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.test.js new file mode 100644 index 0000000000000..44b864dea2e99 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_symbol_editor.test.js @@ -0,0 +1,52 @@ +/* + * 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 React from 'react'; +import { shallow } from 'enzyme'; + +import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from '../vector_constants'; +import { VectorStyleSymbolEditor } from './vector_style_symbol_editor'; + +const symbolOptions = [ + { value: 'symbol1', label: 'symbol1' }, + { value: 'symbol2', label: 'symbol2' } +]; + +const defaultProps = { + styleOptions: { + symbolizeAs: SYMBOLIZE_AS_CIRCLE, + symbolId: symbolOptions[0].value, + }, + handlePropertyChange: () => {}, + symbolOptions, + isDarkMode: false +}; + +test('Should render symbol select when symbolized as Circle', () => { + const component = shallow( + + ); + + expect(component) + .toMatchSnapshot(); +}); + +test('Should render icon select when symbolized as Icon', () => { + const component = shallow( + + ); + + expect(component) + .toMatchSnapshot(); +}); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 55a52213aacbc..875e92a350f77 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -33,7 +33,7 @@ const POLYGONS = [GEO_JSON_TYPE.POLYGON, GEO_JSON_TYPE.MULTI_POLYGON]; export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - + static STYLE_TYPE = { 'STATIC': StaticStyleProperty.type, 'DYNAMIC': DynamicStyleProperty.type }; static createDescriptor(properties = {}) { return { type: VectorStyle.type, @@ -63,12 +63,13 @@ export class VectorStyle extends AbstractStyle { ...VectorStyle.createDescriptor(descriptor.properties), }; - this._lineColorStyleProperty = this._makeStyleProperty(vectorStyles.LINE_COLOR, this._descriptor.properties[vectorStyles.LINE_COLOR]); - this._fillColorStyleProperty = this._makeStyleProperty(vectorStyles.FILL_COLOR, this._descriptor.properties[vectorStyles.FILL_COLOR]); - this._lineWidthStyleProperty = this._makeStyleProperty(vectorStyles.LINE_WIDTH, this._descriptor.properties[vectorStyles.LINE_WIDTH]); - this._iconSizeStyleProperty = this._makeStyleProperty(vectorStyles.ICON_SIZE, this._descriptor.properties[vectorStyles.ICON_SIZE]); + this._lineColorStyleProperty = this._makeColorProperty(this._descriptor.properties[vectorStyles.LINE_COLOR], vectorStyles.LINE_COLOR); + this._fillColorStyleProperty = this._makeColorProperty(this._descriptor.properties[vectorStyles.FILL_COLOR], vectorStyles.FILL_COLOR); + this._lineWidthStyleProperty = this._makeSizeProperty(this._descriptor.properties[vectorStyles.LINE_WIDTH], vectorStyles.LINE_WIDTH); + this._iconSizeStyleProperty = this._makeSizeProperty(this._descriptor.properties[vectorStyles.ICON_SIZE], vectorStyles.ICON_SIZE); // eslint-disable-next-line max-len - this._iconOrientationProperty = this._makeStyleProperty(vectorStyles.ICON_ORIENTATION, this._descriptor.properties[vectorStyles.ICON_ORIENTATION]); + this._iconOrientationProperty = this._makeOrientationProperty(this._descriptor.properties[vectorStyles.ICON_ORIENTATION], vectorStyles.ICON_ORIENTATION); + } _getAllStyleProperties() { @@ -514,21 +515,5 @@ export class VectorStyle extends AbstractStyle { } } - _makeStyleProperty(propertyName, descriptor) { - - if (propertyName === vectorStyles.LINE_WIDTH) { - return this._makeSizeProperty(descriptor, vectorStyles.LINE_WIDTH); - } else if (propertyName === vectorStyles.ICON_SIZE) { - return this._makeSizeProperty(descriptor, vectorStyles.ICON_SIZE); - } else if (propertyName === vectorStyles.LINE_COLOR) { - return this._makeColorProperty(descriptor, vectorStyles.LINE_COLOR); - } else if (propertyName === vectorStyles.FILL_COLOR) { - return this._makeColorProperty(descriptor, vectorStyles.FILL_COLOR); - } else if (propertyName === vectorStyles.ICON_ORIENTATION) { - return this._makeOrientationProperty(descriptor, vectorStyles.ICON_ORIENTATION); - } - - throw new Error(`${propertyName} not implemented`); - } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js index 2b1f7ce4e5468..c0d76fadc01a5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js @@ -7,23 +7,20 @@ import { VectorStyle } from './vector_style'; import { DataRequest } from '../../util/data_request'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; -import { DynamicStyleProperty } from './properties/dynamic_style_property'; -import { StaticStyleProperty } from './properties/static_style_property'; - describe('getDescriptorWithMissingStylePropsRemoved', () => { const fieldName = 'doIStillExist'; const properties = { fillColor: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: {} }, lineColor: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: {} }, iconSize: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { color: 'a color', field: { name: fieldName } @@ -183,7 +180,7 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { const vectorStyle = new VectorStyle({ properties: { fillColor: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { name: 'myDynamicFieldWithNoValues' @@ -205,7 +202,7 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { const vectorStyle = new VectorStyle({ properties: { fillColor: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { name: 'myDynamicField' diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js index 1e215b27fa145..ea4228430d13d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js @@ -4,8 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DynamicStyleProperty } from './properties/dynamic_style_property'; -import { StaticStyleProperty } from './properties/static_style_property'; +import { VectorStyle } from './vector_style'; import { SYMBOLIZE_AS_CIRCLE, DEFAULT_ICON_SIZE } from './vector_constants'; import { COLOR_GRADIENTS, @@ -50,31 +49,31 @@ export function getDefaultStaticProperties(mapColors = []) { return { [vectorStyles.FILL_COLOR]: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: { color: nextFillColor, } }, [vectorStyles.LINE_COLOR]: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: { color: nextLineColor } }, [vectorStyles.LINE_WIDTH]: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: { size: 1 } }, [vectorStyles.ICON_SIZE]: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: { size: DEFAULT_ICON_SIZE } }, [vectorStyles.ICON_ORIENTATION]: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: { orientation: 0 } @@ -85,21 +84,21 @@ export function getDefaultStaticProperties(mapColors = []) { export function getDefaultDynamicProperties() { return { [vectorStyles.FILL_COLOR]: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { color: COLOR_GRADIENTS[0].value, field: undefined, } }, [vectorStyles.LINE_COLOR]: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { color: COLOR_GRADIENTS[0].value, field: undefined, } }, [vectorStyles.LINE_WIDTH]: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { minSize: DEFAULT_MIN_SIZE, maxSize: DEFAULT_MAX_SIZE, @@ -107,7 +106,7 @@ export function getDefaultDynamicProperties() { } }, [vectorStyles.ICON_SIZE]: { - type: DynamicStyleProperty.type, + type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { minSize: DEFAULT_MIN_SIZE, maxSize: DEFAULT_MAX_SIZE, @@ -115,7 +114,7 @@ export function getDefaultDynamicProperties() { } }, [vectorStyles.ICON_ORIENTATION]: { - type: StaticStyleProperty.type, + type: VectorStyle.STYLE_TYPE.STATIC, options: { field: undefined, } From 0ca8b07d16c542db2d95509cacf6f2828f631a10 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 4 Nov 2019 12:45:38 -0500 Subject: [PATCH 063/112] add style-type module --- x-pack/legacy/plugins/maps/common/constants.js | 3 ++- .../layers/styles/vector/properties/dynamic_style_property.js | 3 ++- .../layers/styles/vector/properties/static_style_property.js | 4 ++-- .../plugins/maps/public/layers/styles/vector/vector_style.js | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index fd307504fa265..e56aa7513260f 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - export const EMS_CATALOGUE_PATH = 'ems/catalogue'; export const EMS_FILES_CATALOGUE_PATH = 'ems/files'; @@ -113,3 +112,5 @@ export const METRIC_TYPE = { }; export const COUNT_AGG_TYPE = 'count'; + +export const STYLE_TYPE = { 'STATIC': 'STATIC', 'DYNAMIC': 'DYNAMIC' }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 2110d9a1e1bb4..9ee4c3a1eb9bb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -6,9 +6,10 @@ import { AbstractStyleProperty } from './style_property'; +import { STYLE_TYPE } from '../../../../../common/constants'; export class DynamicStyleProperty extends AbstractStyleProperty { - static type = 'DYNAMIC'; + static type = STYLE_TYPE.DYNAMIC; constructor(options, styleName, field) { super(options, styleName); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js index 448efc06899e5..6c53e00f8bd20 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/static_style_property.js @@ -6,8 +6,8 @@ import { AbstractStyleProperty } from './style_property'; +import { STYLE_TYPE } from '../../../../../common/constants'; export class StaticStyleProperty extends AbstractStyleProperty { - static type = 'STATIC'; - + static type = STYLE_TYPE.STATIC; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 875e92a350f77..6d347d47f5819 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { VectorStyleEditor } from './components/vector/vector_style_editor'; import { getDefaultProperties, vectorStyles } from './vector_style_defaults'; import { AbstractStyle } from '../abstract_style'; -import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE, FIELD_ORIGIN } from '../../../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE, FIELD_ORIGIN, STYLE_TYPE } from '../../../../common/constants'; import { VectorIcon } from './components/vector/legend/vector_icon'; import { VectorStyleLegend } from './components/vector/legend/vector_style_legend'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; @@ -33,7 +33,7 @@ const POLYGONS = [GEO_JSON_TYPE.POLYGON, GEO_JSON_TYPE.MULTI_POLYGON]; export class VectorStyle extends AbstractStyle { static type = 'VECTOR'; - static STYLE_TYPE = { 'STATIC': StaticStyleProperty.type, 'DYNAMIC': DynamicStyleProperty.type }; + static STYLE_TYPE = STYLE_TYPE; static createDescriptor(properties = {}) { return { type: VectorStyle.type, From b585dafb53272c9b9d2b43ffb3b5e6e6ac0a8f34 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 4 Nov 2019 12:48:31 -0500 Subject: [PATCH 064/112] remove logs --- .../plugins/maps/public/components/tooltip_selector.js | 3 --- x-pack/legacy/plugins/maps/public/layers/fields/field.js | 2 -- .../layers/sources/es_search_source/update_source_editor.js | 6 ------ 3 files changed, 11 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 0130f39cd118a..de77cc7eba389 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -62,10 +62,7 @@ export class TooltipSelector extends Component { return; } - console.log('tpf', this.props.fields); - const getProps = async field => { - console.log('getprops', field); return new Promise(async (resolve, reject) => { try { const label = await field.getLabel(); diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index e3db8c564770b..49a24c398213f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -16,8 +16,6 @@ export class AbstractField { }; constructor({ fieldName, source }) { - console.trace(); - console.log('make field', source, fieldName); this._fieldName = fieldName; this._source = source; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index fa1c828dd9ffa..05bdfe701e356 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -77,17 +77,12 @@ export class UpdateSourceEditor extends Component { //todo move this all to the source const rawTooltipFields = getSourceFields(indexPattern.fields); const tooltipFields = rawTooltipFields.map(field => { - console.log('f', field, field.name); - if (!field.name) { - console.log('this field has no name!', field); - } return new ESDocField({ fieldName: field.name, source: this.props.source }); }); - console.log('set state', tooltipFields); this.setState({ tooltipFields: tooltipFields, termFields: getTermsFields(indexPattern.fields), //todo change term fields to use fields @@ -180,7 +175,6 @@ export class UpdateSourceEditor extends Component { } render() { - console.log('ttf - apsed in', this.props.tooltipFields); return ( From 828ea0f8c691401fbecab4dd8bc82559329bc40b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 4 Nov 2019 15:18:31 -0500 Subject: [PATCH 065/112] fix counts --- x-pack/legacy/plugins/maps/common/constants.js | 4 ++++ .../maps/public/layers/sources/es_agg_source.js | 5 ++--- .../sources/es_geo_grid_source/es_geo_grid_source.js | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index 9767833cfd7ff..fd207e9f7e00e 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -112,5 +112,9 @@ export const METRIC_TYPE = { }; export const COUNT_AGG_TYPE = METRIC_TYPE.COUNT; +export const COUNT_PROP_LABEL = METRIC_TYPE.COUNT; +export const COUNT_PROP_NAME = 'doc_count'; export const STYLE_TYPE = { 'STATIC': 'STATIC', 'DYNAMIC': 'DYNAMIC' }; + + diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index e240257bb4c8e..ef9b50a3da0e9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -8,10 +8,9 @@ import { AbstractESSource } from './es_source'; import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; import { ESAggMetricField } from '../fields/es_agg_field'; import { ESDocField } from '../fields/es_doc_field'; -import { METRIC_TYPE, COUNT_AGG_TYPE } from '../../../common/constants'; +import { METRIC_TYPE, COUNT_AGG_TYPE, COUNT_PROP_LABEL, COUNT_PROP_NAME } from '../../../common/constants'; + -const COUNT_PROP_LABEL = 'count'; -const COUNT_PROP_NAME = 'doc_count'; const AGG_DELIMITER = '_of_'; export class AbstractESAggSource extends AbstractESSource { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 01ce1d3e0ee25..682b1310880d3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -20,7 +20,7 @@ import { RENDER_AS } from './render_as'; import { CreateSourceEditor } from './create_source_editor'; import { UpdateSourceEditor } from './update_source_editor'; import { GRID_RESOLUTION } from '../../grid_resolution'; -import { SOURCE_DATA_ID_ORIGIN, ES_GEO_GRID } from '../../../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN, ES_GEO_GRID, COUNT_PROP_LABEL, COUNT_PROP_NAME } from '../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { AbstractESAggSource } from '../es_agg_source'; @@ -230,8 +230,8 @@ export class ESGeoGridSource extends AbstractESAggSource { type: DynamicStyleProperty.type, options: { field: { - label: AbstractESAggSource.COUNT_PROP_LABEL, - name: AbstractESAggSource.COUNT_PROP_NANE, + label: COUNT_PROP_LABEL, + name: COUNT_PROP_NAME, origin: SOURCE_DATA_ID_ORIGIN }, color: 'Blues' @@ -241,8 +241,8 @@ export class ESGeoGridSource extends AbstractESAggSource { type: DynamicStyleProperty.type, options: { field: { - label: AbstractESAggSource.COUNT_PROP_LABEL, - name: AbstractESAggSource.COUNT_PROP_NANE, + label: COUNT_PROP_LABEL, + name: COUNT_PROP_NAME, origin: SOURCE_DATA_ID_ORIGIN }, minSize: 4, From c8e619847876c4015d241c6eee07198e6e5da562 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 6 Nov 2019 05:38:14 -0500 Subject: [PATCH 066/112] fix refactor --- .../layers/styles/vector/vector_style.js | 6 +- .../layers/styles/vector/vector_style.test.js | 93 ++++++++++++------- 2 files changed, 66 insertions(+), 33 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 87317aa32ef9a..a28353eca81c3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -113,14 +113,16 @@ export class VectorStyle extends AbstractStyle { * can then use to update store state via dispatch. */ getDescriptorWithMissingStylePropsRemoved(nextOrdinalFields) { - const originalProperties = this.getProperties(); + + + const originalProperties = this.getRawProperties(); const updatedProperties = {}; this.getDynamicPropertiesArray().forEach(dynamicProperty =>{ const field = dynamicProperty.getField(); - if (field || !field.isValid()) { + if (!field || !field.isValid()) { return; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js index c0d76fadc01a5..782b6ee5612f3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js @@ -7,6 +7,38 @@ import { VectorStyle } from './vector_style'; import { DataRequest } from '../../util/data_request'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; +import { FIELD_ORIGIN } from '../../../../common/constants'; + +class MockField { + constructor({ fieldName }) { + this._fieldName = fieldName; + } + + getName() { + return this._fieldName; + } + + isValid() { + return !!this._fieldName; + } +} + +class MockSource { + + constructor({ supportedShapeTypes } = {}) { + this._supportedShapeTypes = supportedShapeTypes || Object.values(VECTOR_SHAPE_TYPES); + } + getSupportedShapeTypes() { + return this._supportedShapeTypes; + } + createField({ fieldName }) { + return new MockField({ fieldName }); + } +} + + + + describe('getDescriptorWithMissingStylePropsRemoved', () => { const fieldName = 'doIStillExist'; @@ -17,19 +49,24 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => { }, lineColor: { type: VectorStyle.STYLE_TYPE.DYNAMIC, - options: {} + options: { + 'field': { + 'name': fieldName, + 'origin': FIELD_ORIGIN.SOURCE + } + } }, iconSize: { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { color: 'a color', - field: { name: fieldName } + field: { name: fieldName, origin: FIELD_ORIGIN.SOURCE } } } }; it('Should return no changes when next oridinal fields contain existing style property fields', () => { - const vectorStyle = new VectorStyle({ properties }); + const vectorStyle = new VectorStyle({ properties }, new MockSource()); const nextOridinalFields = [ { name: fieldName } @@ -39,7 +76,7 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => { }); it('Should clear missing fields when next oridinal fields do not contain existing style property fields', () => { - const vectorStyle = new VectorStyle({ properties }); + const vectorStyle = new VectorStyle({ properties }, new MockSource()); const nextOridinalFields = []; const { hasChanges, nextStyleDescriptor } = vectorStyle.getDescriptorWithMissingStylePropsRemoved(nextOridinalFields); @@ -83,12 +120,6 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => { describe('pluckStyleMetaFromSourceDataRequest', () => { - const sourceMock = { - getSupportedShapeTypes: () => { - return Object.values(VECTOR_SHAPE_TYPES); - } - }; - describe('has features', () => { it('Should identify when feature collection only contains points', async () => { const sourceDataRequest = new DataRequest({ @@ -110,7 +141,7 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { ], } }); - const vectorStyle = new VectorStyle({}, sourceMock); + const vectorStyle = new VectorStyle({}, new MockSource()); const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); expect(featuresMeta.hasFeatureType).toEqual({ @@ -140,7 +171,7 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { ], } }); - const vectorStyle = new VectorStyle({}, sourceMock); + const vectorStyle = new VectorStyle({}, new MockSource()); const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); expect(featuresMeta.hasFeatureType).toEqual({ @@ -183,12 +214,13 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { + origin: FIELD_ORIGIN.SOURCE, name: 'myDynamicFieldWithNoValues' } } } } - }, sourceMock); + }, new MockSource()); const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); expect(featuresMeta.hasFeatureType).toEqual({ @@ -205,12 +237,13 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { type: VectorStyle.STYLE_TYPE.DYNAMIC, options: { field: { + origin: FIELD_ORIGIN.SOURCE, name: 'myDynamicField' } } } } - }, sourceMock); + }, new MockSource()); const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); expect(featuresMeta.myDynamicField).toEqual({ @@ -226,32 +259,24 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { describe('checkIfOnlyFeatureType', () => { describe('source supports single feature type', () => { - const sourceMock = { - getSupportedShapeTypes: () => { - return [VECTOR_SHAPE_TYPES.POINT]; - } - }; - it('isPointsOnly should be true when source feature type only supports points', async () => { - const vectorStyle = new VectorStyle({}, sourceMock); + const vectorStyle = new VectorStyle({}, new MockSource({ + supportedShapeTypes: [VECTOR_SHAPE_TYPES.POINT] + })); const isPointsOnly = await vectorStyle._getIsPointsOnly(); expect(isPointsOnly).toBe(true); }); it('isLineOnly should be false when source feature type only supports points', async () => { - const vectorStyle = new VectorStyle({}, sourceMock); + const vectorStyle = new VectorStyle({}, new MockSource({ + supportedShapeTypes: [VECTOR_SHAPE_TYPES.POINT] + })); const isLineOnly = await vectorStyle._getIsLinesOnly(); expect(isLineOnly).toBe(false); }); }); describe('source supports multiple feature types', () => { - const sourceMock = { - getSupportedShapeTypes: () => { - return Object.values(VECTOR_SHAPE_TYPES); - } - }; - it('isPointsOnly should be true when data contains just points', async () => { const vectorStyle = new VectorStyle({ __styleMeta: { @@ -261,7 +286,9 @@ describe('checkIfOnlyFeatureType', () => { POLYGON: false } } - }, sourceMock); + }, new MockSource({ + supportedShapeTypes: Object.values(VECTOR_SHAPE_TYPES) + })); const isPointsOnly = await vectorStyle._getIsPointsOnly(); expect(isPointsOnly).toBe(true); }); @@ -275,7 +302,9 @@ describe('checkIfOnlyFeatureType', () => { POLYGON: false } } - }, sourceMock); + }, new MockSource({ + supportedShapeTypes: Object.values(VECTOR_SHAPE_TYPES) + })); const isPointsOnly = await vectorStyle._getIsPointsOnly(); expect(isPointsOnly).toBe(false); }); @@ -289,7 +318,9 @@ describe('checkIfOnlyFeatureType', () => { POLYGON: true } } - }, sourceMock); + }, new MockSource({ + supportedShapeTypes: Object.values(VECTOR_SHAPE_TYPES) + })); const isPointsOnly = await vectorStyle._getIsPointsOnly(); expect(isPointsOnly).toBe(false); }); From c2648cc4d9ad9ec79350a3bba11e8fae2b932181 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sat, 9 Nov 2019 11:30:57 -0500 Subject: [PATCH 067/112] fix test --- .../legacy/plugins/maps/public/layers/joins/inner_join.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js index 12790cae42ba2..02410c64c1c42 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js @@ -29,7 +29,7 @@ const rightSource = { const mockSource = { getInspectorAdapters() { }, - createField(name) { + createField({ fieldName: name }) { return { getName() { return name; From 0fc88667de43e28b1d9906301610b4eb0f7433ce Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sat, 9 Nov 2019 11:51:58 -0500 Subject: [PATCH 068/112] fix tests --- .../layers/sources/es_term_source.test.js | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index ea11c7e367e5b..a4fe21f2e0fbb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -36,21 +36,22 @@ const metricExamples = [ describe('getMetricFields', () => { - it('should add default "count" metric when no metrics are provided', () => { + it('should add default "count" metric when no metrics are provided', async () => { const source = new ESTermSource({ indexPatternTitle: indexPatternTitle, term: termFieldName, }); const metrics = source.getMetricFields(); expect(metrics.length).toBe(1); - expect(metrics[0]).toEqual({ - type: 'count', - propertyKey: '__kbnjoin__count_groupby_myIndex.myTermField', - propertyLabel: 'count of myIndex:myTermField', - }); + + expect(metrics[0].getAggType()).toEqual('count'); + expect(metrics[0].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); + expect(metrics[0].getPropertyLabel()).toEqual('count of myIndex:myTermField'); + expect(await metrics[0].getLabel()).toEqual('count of myIndex:myTermField'); + }); - it('should remove incomplete metric configurations', () => { + it('should remove incomplete metric configurations', async () => { const source = new ESTermSource({ indexPatternTitle: indexPatternTitle, term: termFieldName, @@ -58,17 +59,18 @@ describe('getMetricFields', () => { }); const metrics = source.getMetricFields(); expect(metrics.length).toBe(2); - expect(metrics[0]).toEqual({ - type: 'sum', - field: sumFieldName, - propertyKey: '__kbnjoin__sum_of_myFieldGettingSummed_groupby_myIndex.myTermField', - propertyLabel: 'my custom label', - }); - expect(metrics[1]).toEqual({ - type: 'count', - propertyKey: '__kbnjoin__count_groupby_myIndex.myTermField', - propertyLabel: 'count of myIndex:myTermField', - }); + + expect(metrics[0].getAggType()).toEqual('sum'); + expect(metrics[0].getESDocFieldName()).toEqual(sumFieldName); + expect(metrics[0].getName()).toEqual('__kbnjoin__sum_of_myFieldGettingSummed_groupby_myIndex.myTermField'); + expect(metrics[0].getPropertyLabel()).toEqual('my custom label'); + expect(await metrics[0].getLabel()).toEqual('my custom label'); + + expect(metrics[1].getAggType()).toEqual('count'); + expect(metrics[1].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); + expect(metrics[1].getPropertyLabel()).toEqual('count of myIndex:myTermField'); + expect(await metrics[1].getLabel()).toEqual('count of myIndex:myTermField'); + }); }); From 95d895865d1bf60ab620800799dfa9d63a6d1c4d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sat, 9 Nov 2019 14:18:02 -0500 Subject: [PATCH 069/112] start removing usage of field-formatter --- .../public/layers/sources/es_agg_source.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index ef9b50a3da0e9..4e6f1ad75ae23 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -98,9 +98,13 @@ export class AbstractESAggSource extends AbstractESSource { async getNumberFields() { - return this.getMetricFields().map(esAggMetricField => { - return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getName() }; + const numberFieldPromises = this.getMetricFields().map(async (esAggMetricField) => { + return { + label: await esAggMetricField.getLabel(), + name: esAggMetricField.getName() + }; }); + return Promise.all(numberFieldPromises); } async filterAndFormatPropertiesToHtmlForMetricFields(properties) { @@ -113,8 +117,8 @@ export class AbstractESAggSource extends AbstractESSource { } const metricFields = this.getMetricFields(); - const tooltipProperties = []; - metricFields.forEach((metricField) => { + const tooltipPropertiesPromises = []; + metricFields.forEach(async (metricField) => { let value; for (const key in properties) { if (properties.hasOwnProperty(key) && metricField.getName() === key) { @@ -125,15 +129,14 @@ export class AbstractESAggSource extends AbstractESSource { const tooltipProperty = new ESAggMetricTooltipProperty( metricField.getName(), - metricField.getPropertyLabel(), + await metricField.getLabel(), value, indexPattern, metricField ); - tooltipProperties.push(tooltipProperty); + tooltipPropertiesPromises.push(tooltipProperty); }); - return tooltipProperties; - + return Promise.all(tooltipPropertiesPromises); } } From 034bc8bc61e434fbe2351f6d6b3117dde2d7da9d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 10 Nov 2019 15:21:49 -0600 Subject: [PATCH 070/112] start more refactors --- .../legacy/plugins/maps/common/constants.js | 2 +- .../maps/public/actions/map_actions.js | 7 ++- .../public/layers/fields/field_with_origin.js | 57 +++++++++++++++++++ .../maps/public/layers/joins/inner_join.js | 4 +- .../plugins/maps/public/layers/layer.js | 4 ++ .../public/layers/sources/es_agg_source.js | 8 +-- .../es_search_source/es_search_source.js | 8 +-- .../maps/public/layers/vector_layer.js | 56 +++++++++++------- 8 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index fd207e9f7e00e..4ebc75ad15ead 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -54,7 +54,7 @@ export const FIELD_ORIGIN = { JOIN: 'join' }; -export const SOURCE_DATA_ID_ORIGIN = 'source'; +export const SOURCE_DATA_ID_ORIGIN = FIELD_ORIGIN.SOURCE; export const GEOJSON_FILE = 'GEOJSON_FILE'; diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 33771a355ddd5..078d732e02fb8 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -745,9 +745,10 @@ export function clearMissingStyleProperties(layerId) { return; } - const dateFields = await targetLayer.getDateFields(); - const numberFields = await targetLayer.getNumberFields(); - const ordinalFields = [...dateFields, ...numberFields]; + // const dateFields = await targetLayer.getDateFields(); + // const numberFields = await targetLayer.getNumberFields(); + // const ordinalFields = [...dateFields, ...numberFields]; + const ordinalFields = await targetLayer.getOrdinalFields(); const { hasChanges, nextStyleDescriptor } = style.getDescriptorWithMissingStylePropsRemoved(ordinalFields); if (hasChanges) { dispatch(updateLayerStyle(layerId, nextStyleDescriptor)); diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js new file mode 100644 index 0000000000000..c96f684cd7fef --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js @@ -0,0 +1,57 @@ +/* + * 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 { AbstractField } from './field'; + +export class FieldWithOrigin extends AbstractField { + + //todo: This annotated field was introduced due to legacy constraints in the code. + //Field-descriptors in styles use a combination of field-name and FIELD_ORIGIN-enumeration to uniquely identify a field + //across layer-source and joins. + constructor({ field, origin }) { + super({}); + this._field = field; + this._origin = origin; + } + + getName() { + return this._field.getName(); + } + + isValid() { + return this._field.isValid(); + } + + async getType() { + return await this._field.getType(); + } + + async getLabel() { + return await this._field.getLabel(); + } + + getPropertyLabel() { + if (!this._field.getPropertyLabel) { + throw new Error('getPropertyLabel not implemented'); + } + return this._field.getPropertyLabel(); + } + + getOrigin() { + return this._origin; + } + +} + + + + + + + + + diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js index 781c02c3cffc2..029e0851799d6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js @@ -30,9 +30,7 @@ export class InnerJoin { } getJoinFields() { - return this._rightSource.getMetricFields().map(esAggMetricField => { - return { label: esAggMetricField.getPropertyLabel(), name: esAggMetricField.getName() }; - }); + return this._rightSource.getMetricFields(); } // Source request id must be static and unique because the re-fetch logic uses the id to locate the previous request. diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index 6515ab608c2ea..a26ad6a40581f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -402,6 +402,10 @@ export class AbstractLayer { return []; } + async getOrdinalFields() { + return []; + } + syncVisibilityWithMb(mbMap, mbLayerId) { mbMap.setLayoutProperty(mbLayerId, 'visibility', this.isVisible() ? 'visible' : 'none'); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 4e6f1ad75ae23..c4b2919c92de8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -98,13 +98,7 @@ export class AbstractESAggSource extends AbstractESSource { async getNumberFields() { - const numberFieldPromises = this.getMetricFields().map(async (esAggMetricField) => { - return { - label: await esAggMetricField.getLabel(), - name: esAggMetricField.getName() - }; - }); - return Promise.all(numberFieldPromises); + return this.getMetricFields(); } async filterAndFormatPropertiesToHtmlForMetricFields(properties) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 93bf4de3cbe6d..366819a193f80 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -99,7 +99,7 @@ export class ESSearchSource extends AbstractESSource { try { const indexPattern = await this.getIndexPattern(); return indexPattern.fields.getByType('number').map(field => { - return { name: field.name, label: field.name }; + return this.createField({ fieldName: field.name }); }); } catch (error) { return []; @@ -110,7 +110,7 @@ export class ESSearchSource extends AbstractESSource { try { const indexPattern = await this.getIndexPattern(); return indexPattern.fields.getByType('date').map(field => { - return { name: field.name, label: field.name }; + return this.createField({ fieldName: field.name }); }); } catch (error) { return []; @@ -175,7 +175,7 @@ export class ESSearchSource extends AbstractESSource { } async _excludeDateFields(fieldNames) { - const dateFieldNames = _.map(await this.getDateFields(), 'name'); + const dateFieldNames = (await this.getDateFields()).map(field => field.getName()); return fieldNames.filter(field => { return !dateFieldNames.includes(field); }); @@ -183,7 +183,7 @@ export class ESSearchSource extends AbstractESSource { // Returns docvalue_fields array for the union of indexPattern's dateFields and request's field names. async _getDateDocvalueFields(searchFields) { - const dateFieldNames = _.map(await this.getDateFields(), 'name'); + const dateFieldNames = (await this.getDateFields()).map(field => field.getName()); return searchFields .filter(fieldName => { return dateFieldNames.includes(fieldName); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index caa01a052b1c4..98992bd64233b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -24,6 +24,7 @@ import { isRefreshOnlyQuery } from './util/is_refresh_only_query'; import { EuiIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { DataRequestAbortError } from './util/data_request'; +import { FieldWithOrigin } from './fields/field_with_origin'; const VISIBILITY_FILTER_CLAUSE = ['all', [ @@ -184,8 +185,9 @@ export class VectorLayer extends AbstractLayer { } getLegendDetails() { + const getFieldLabel = async fieldName => { - const ordinalFields = await this._getOrdinalFields(); + const ordinalFields = await this.getOrdinalFields(); const field = ordinalFields.find(({ name }) => { return name === fieldName; }); @@ -243,41 +245,57 @@ export class VectorLayer extends AbstractLayer { return this._source.getDisplayName(); } - async getDateFields() { + + async getDateFieldsOO() { const timeFields = await this._source.getDateFields(); - return timeFields.map(({ label, name }) => { + return timeFields.map(async (field) => { + return new FieldWithOrigin({ field: field, origin: FIELD_ORIGIN.SOURCE }); + }); + } + + async getDateFields() { + const timeFields = await this.getDateFieldsOO(); + const fieldPromises = timeFields.map(async (field) => { return { - label, - name, - origin: SOURCE_DATA_ID_ORIGIN + label: await field.getLabel(), + name: field.getName(), + origin: field.getOrigin() }; }); + return Promise.all(fieldPromises); } async getNumberFields() { const numberFields = await this._source.getNumberFields(); - const numberFieldOptions = numberFields.map(({ label, name }) => { - return { - label, - name, - origin: FIELD_ORIGIN.SOURCE - }; + const numberFieldOptions = numberFields.map(field => { + return new FieldWithOrigin({ + field: field, + }); }); const joinFields = []; this.getValidJoins().forEach(join => { const fields = join.getJoinFields().map(joinField => { - return { - ...joinField, - origin: FIELD_ORIGIN.JOIN, - }; + return new FieldWithOrigin({ + field: joinField, + origin: FIELD_ORIGIN.JOIN + }); }); joinFields.push(...fields); }); - return [...numberFieldOptions, ...joinFields]; + + const promises = ([...numberFieldOptions, ...joinFields]).map(async (field) => { + return { + label: await field.getLabel(), + name: field.getName(), + origin: field.getOrigin() + }; + }); + + return Promise.all(promises); } - async _getOrdinalFields() { + async getOrdinalFields() { return [ ... await this.getDateFields(), ... await this.getNumberFields() @@ -807,7 +825,7 @@ export class VectorLayer extends AbstractLayer { const join = this.getValidJoins().find(join => { const matchingField = join.getJoinFields().find(joinField => { - return joinField.name === field.name; + return joinField.getName() === field.name; }); return !!matchingField; }); From 7173e1a4875181b424c666eeb35f11b8727cda42 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 10 Nov 2019 16:37:42 -0600 Subject: [PATCH 071/112] more removal --- .../legacy/plugins/maps/common/constants.js | 3 +- .../maps/public/actions/map_actions.js | 3 - .../maps/public/layers/fields/field.js | 5 ++ .../vector/components/vector_style_editor.js | 26 +++++++-- .../layers/styles/vector/vector_style.js | 4 +- .../maps/public/layers/vector_layer.js | 58 +++++++------------ 6 files changed, 51 insertions(+), 48 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index 4ebc75ad15ead..4fc0d02a33a56 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -51,7 +51,8 @@ export const ES_PEW_PEW = 'ES_PEW_PEW'; export const FIELD_ORIGIN = { SOURCE: 'source', - JOIN: 'join' + JOIN: 'join', + UNDEFINED: 'undefined' }; export const SOURCE_DATA_ID_ORIGIN = FIELD_ORIGIN.SOURCE; diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 078d732e02fb8..6f56f192e9dca 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -745,9 +745,6 @@ export function clearMissingStyleProperties(layerId) { return; } - // const dateFields = await targetLayer.getDateFields(); - // const numberFields = await targetLayer.getNumberFields(); - // const ordinalFields = [...dateFields, ...numberFields]; const ordinalFields = await targetLayer.getOrdinalFields(); const { hasChanges, nextStyleDescriptor } = style.getDescriptorWithMissingStylePropsRemoved(ordinalFields); if (hasChanges) { diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 49a24c398213f..6ccbda474cfd9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -5,6 +5,8 @@ */ +import { FIELD_ORIGIN } from '../../../common/constants'; + export class AbstractField { //todo consider removing @@ -40,6 +42,9 @@ export class AbstractField { throw new Error('must implement Field#createTooltipProperty'); } + getOrigin() { + return FIELD_ORIGIN.UNDEFINED; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index f624f4e661a14..2bab2bf8966fb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -56,16 +56,34 @@ export class VectorStyleEditor extends Component { if (!this._isMounted) { return; } - if (!_.isEqual(dateFields, this.state.dateFields)) { - this.setState({ dateFields }); + const dateFieldPromises = dateFields.map(async (field) => { + return { + label: await field.getLabel(), + name: field.getName(), + origin: field.getOrigin() + }; + }); + const dateFieldsArray = await Promise.all(dateFieldPromises); + + if (!_.isEqual(dateFieldsArray, this.state.dateFields)) { + this.setState({ dateFields: dateFieldsArray }); } const numberFields = await this.props.layer.getNumberFields(); if (!this._isMounted) { return; } - if (!_.isEqual(numberFields, this.state.numberFields)) { - this.setState({ numberFields }); + const numberFieldPromises = numberFields.map(async (field) => { + return { + label: await field.getLabel(), + name: field.getName(), + origin: field.getOrigin() + }; + }); + + const numberFieldsArray = await Promise.all(numberFieldPromises); + if (!_.isEqual(numberFieldsArray, this.state.numberFields)) { + this.setState({ numberFields: numberFieldsArray }); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index a28353eca81c3..3a3cdb897b346 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -127,8 +127,8 @@ export class VectorStyle extends AbstractStyle { } const fieldName = field.getName(); - const matchingOrdinalField = nextOrdinalFields.find(oridinalField => { - return fieldName === oridinalField.name; + const matchingOrdinalField = nextOrdinalFields.find(ordinalField => { + return fieldName === ordinalField.getName(); }); if (matchingOrdinalField) { diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 98992bd64233b..d0b96a8cd64bd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -188,11 +188,10 @@ export class VectorLayer extends AbstractLayer { const getFieldLabel = async fieldName => { const ordinalFields = await this.getOrdinalFields(); - const field = ordinalFields.find(({ name }) => { - return name === fieldName; + const field = ordinalFields.find(field => { + return field.getName() === fieldName; }); - - return field ? field.label : fieldName; + return field ? await field.getLabel() : fieldName; }; const getFieldFormatter = async field => { @@ -245,31 +244,19 @@ export class VectorLayer extends AbstractLayer { return this._source.getDisplayName(); } - - async getDateFieldsOO() { + async getDateFields() { const timeFields = await this._source.getDateFields(); - return timeFields.map(async (field) => { + return timeFields.map((field) => { return new FieldWithOrigin({ field: field, origin: FIELD_ORIGIN.SOURCE }); }); } - async getDateFields() { - const timeFields = await this.getDateFieldsOO(); - const fieldPromises = timeFields.map(async (field) => { - return { - label: await field.getLabel(), - name: field.getName(), - origin: field.getOrigin() - }; - }); - return Promise.all(fieldPromises); - } - async getNumberFields() { const numberFields = await this._source.getNumberFields(); const numberFieldOptions = numberFields.map(field => { return new FieldWithOrigin({ field: field, + origin: FIELD_ORIGIN.SOURCE }); }); const joinFields = []; @@ -283,16 +270,7 @@ export class VectorLayer extends AbstractLayer { joinFields.push(...fields); }); - - const promises = ([...numberFieldOptions, ...joinFields]).map(async (field) => { - return { - label: await field.getLabel(), - name: field.getName(), - origin: field.getOrigin() - }; - }); - - return Promise.all(promises); + return [...numberFieldOptions, ...joinFields]; } async getOrdinalFields() { @@ -821,20 +799,24 @@ export class VectorLayer extends AbstractLayer { if (field.origin === FIELD_ORIGIN.SOURCE) { return this._source; - } - - const join = this.getValidJoins().find(join => { - const matchingField = join.getJoinFields().find(joinField => { - return joinField.getName() === field.name; + } else if (field.origin === FIELD_ORIGIN.JOIN) { + const join = this.getValidJoins().find(join => { + const matchingField = join.getJoinFields().find(joinField => { + return joinField.getName() === field.name; + }); + return !!matchingField; }); - return !!matchingField; - }); - if (!join) { + if (!join) { + return null; + } + + return join.getRightJoinSource(); + } else { return null; } - return join.getRightJoinSource(); + } } From 4aa596a5976911e774118d09fa4281f802f09b50 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 10 Nov 2019 16:46:54 -0600 Subject: [PATCH 072/112] remove hardcoding from heatmap --- .../maps/public/layers/heatmap_layer.js | 3 +- .../components/legend/heatmap_legend.js | 72 +++++++++++++------ .../layers/styles/heatmap/heatmap_style.js | 4 +- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 157d45fbbd275..0ddfb2b7e3bc7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -104,7 +104,6 @@ export class HeatmapLayer extends VectorLayer { getLegendDetails() { const metricFields = this._source.getMetricFields(); - const label = metricFields[0].getPropertyLabel(); - return this._style.getLegendDetails(label); + return this._style.getLegendDetails(metricFields[0]); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js index 06709ba0ebf21..2f8850ae70d80 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js @@ -15,26 +15,54 @@ import { HEATMAP_COLOR_RAMP_LABEL } from '../heatmap_constants'; -export function HeatmapLegend({ colorRampName, label }) { - const header = colorRampName === DEFAULT_HEATMAP_COLOR_RAMP_NAME - ? - : ; - - return ( - - ); +export class HeatmapLegend extends React.Component { + + constructor() { + super(); + this.state = { label: '' }; + } + + componentDidUpdate() { + this._loadLabel(); + } + + componentDidMount() { + this._isMounted = true; + this._loadLabel(); + } + componentWillUnmount() { + this._isMounted = false; + } + + async _loadLabel() { + const label = await this.props.field.getLabel(); + if (this.state.label !== label) { + this.setState({ label }); + } + } + + render() { + const colorRampName = this.props.colorRampName; + const header = colorRampName === DEFAULT_HEATMAP_COLOR_RAMP_NAME + ? + : ; + + return ( + + ); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js index e537da8a3e2e4..eae494b5b9a44 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js @@ -50,11 +50,11 @@ export class HeatmapStyle extends AbstractStyle { ); } - getLegendDetails(label) { + getLegendDetails(field) { return ( ); } From 4952b6a1eb435b41a0910fb81f9c750e54a909f9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 10 Nov 2019 16:49:08 -0600 Subject: [PATCH 073/112] remove getPropertyLabel --- .../plugins/maps/public/layers/fields/es_agg_field.js | 6 +----- .../plugins/maps/public/layers/fields/field_with_origin.js | 7 ------- .../maps/public/layers/sources/es_term_source.test.js | 3 --- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 1e501d44d948d..8851e765e540f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -24,7 +24,7 @@ export class ESAggMetricField extends AbstractField { } async getLabel() { - return this.getPropertyLabel(); + return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this.getESDocFieldName()); } getAggType() { @@ -35,10 +35,6 @@ export class ESAggMetricField extends AbstractField { return (this.getAggType() === COUNT_AGG_TYPE) ? true : !!this._esDocField; } - getPropertyLabel() { - return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this.getESDocFieldName()); - } - getESDocFieldName() { return this._esDocField ? this._esDocField.getName() : ''; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js index c96f684cd7fef..6aefa3b974a62 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js @@ -34,13 +34,6 @@ export class FieldWithOrigin extends AbstractField { return await this._field.getLabel(); } - getPropertyLabel() { - if (!this._field.getPropertyLabel) { - throw new Error('getPropertyLabel not implemented'); - } - return this._field.getPropertyLabel(); - } - getOrigin() { return this._origin; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index a4fe21f2e0fbb..7f6415fcfae85 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -46,7 +46,6 @@ describe('getMetricFields', () => { expect(metrics[0].getAggType()).toEqual('count'); expect(metrics[0].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); - expect(metrics[0].getPropertyLabel()).toEqual('count of myIndex:myTermField'); expect(await metrics[0].getLabel()).toEqual('count of myIndex:myTermField'); }); @@ -63,12 +62,10 @@ describe('getMetricFields', () => { expect(metrics[0].getAggType()).toEqual('sum'); expect(metrics[0].getESDocFieldName()).toEqual(sumFieldName); expect(metrics[0].getName()).toEqual('__kbnjoin__sum_of_myFieldGettingSummed_groupby_myIndex.myTermField'); - expect(metrics[0].getPropertyLabel()).toEqual('my custom label'); expect(await metrics[0].getLabel()).toEqual('my custom label'); expect(metrics[1].getAggType()).toEqual('count'); expect(metrics[1].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); - expect(metrics[1].getPropertyLabel()).toEqual('count of myIndex:myTermField'); expect(await metrics[1].getLabel()).toEqual('count of myIndex:myTermField'); }); From bad52f7aaaf136ccfa17d9f7aac28150d24f6f5d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 10:59:41 -0500 Subject: [PATCH 074/112] delete unused --- .../components/_static_dynamic_style_row.scss | 3 - .../components/static_dynamic_style_row.js | 128 ------------------ .../vector/components/style_legend_row.js | 66 --------- 3 files changed, 197 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/_static_dynamic_style_row.scss delete mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js delete mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_legend_row.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/_static_dynamic_style_row.scss b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/_static_dynamic_style_row.scss deleted file mode 100644 index 8ec006d32a8b9..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/_static_dynamic_style_row.scss +++ /dev/null @@ -1,3 +0,0 @@ -.mapStaticDynamicSylingOption__dynamicSizeHack { - width: calc(100% - #{$euiSizeXXL + $euiSizeS}); -} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js deleted file mode 100644 index 6eb6b0ab23a3c..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/static_dynamic_style_row.js +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 React from 'react'; -import { DynamicStyleProperty } from '../properties/dynamic_style_property'; -import { StaticStyleProperty } from '../properties/static_style_property'; -import _ from 'lodash'; -import { i18n } from '@kbn/i18n'; - -import { EuiFlexGroup, EuiFlexItem, EuiToolTip, EuiFormRow, EuiButtonToggle } from '@elastic/eui'; - -export class StaticDynamicStyleRow extends React.Component { - // Store previous options locally so when type is toggled, - // previous style options can be used. - prevStaticStyleOptions = this.props.defaultStaticStyleOptions; - prevDynamicStyleOptions = this.props.defaultDynamicStyleOptions; - - _canBeDynamic() { - return this.props.ordinalFields.length > 0; - } - - _isDynamic() { - if (!this.props.styleDescriptor) { - return false; - } - return this.props.styleDescriptor.type === DynamicStyleProperty.type; - } - - _getStyleOptions() { - return _.get(this.props, 'styleDescriptor.options'); - } - - _onStaticStyleChange = options => { - const styleDescriptor = { - type: StaticStyleProperty.type, - options, - }; - this.props.handlePropertyChange(this.props.property, styleDescriptor); - }; - - _onDynamicStyleChange = options => { - const styleDescriptor = { - type: DynamicStyleProperty.type, - options, - }; - this.props.handlePropertyChange(this.props.property, styleDescriptor); - }; - - _onTypeToggle = () => { - if (this._isDynamic()) { - // preserve current dynmaic style - this.prevDynamicStyleOptions = this._getStyleOptions(); - // toggle to static style - this._onStaticStyleChange(this.prevStaticStyleOptions); - return; - } - - // preserve current static style - this.prevStaticStyleOptions = this._getStyleOptions(); - // toggle to dynamic style - this._onDynamicStyleChange(this.prevDynamicStyleOptions); - }; - - _renderStyleSelector() { - if (this._isDynamic()) { - const DynamicSelector = this.props.DynamicSelector; - return ( - - ); - } - - const StaticSelector = this.props.StaticSelector; - return ( - - ); - } - - render() { - const isDynamic = this._isDynamic(); - const dynamicTooltipContent = isDynamic - ? i18n.translate('xpack.maps.styles.staticDynamic.staticDescription', { - defaultMessage: 'Use static styling properties to symbolize features.', - }) - : i18n.translate('xpack.maps.styles.staticDynamic.dynamicDescription', { - defaultMessage: 'Use property values to symbolize features.', - }); - - return ( - - - - {this._renderStyleSelector()} - - - {this._canBeDynamic() && ( - - - - - - - - )} - - ); - } -} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_legend_row.js deleted file mode 100644 index 3691f18cbeba6..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_legend_row.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 React from 'react'; -import PropTypes from 'prop-types'; - -import { - EuiFlexGroup, - EuiFlexItem, - EuiText, - EuiSpacer, - EuiToolTip, -} from '@elastic/eui'; - -export function StyleLegendRow({ header, minLabel, maxLabel, propertyLabel, fieldLabel }) { - return ( -
- - {header} - - - - {minLabel} - - - - - - {fieldLabel} - - - - - - {maxLabel} - - - -
- ); -} - -StyleLegendRow.propTypes = { - header: PropTypes.node.isRequired, - minLabel: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.number, - ]).isRequired, - maxLabel: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.number, - ]).isRequired, - propertyLabel: PropTypes.string.isRequired, - fieldLabel: PropTypes.string.isRequired, -}; From 6d997f662bc508ba99874f7d8ecd1a2126ba7b50 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 11:43:53 -0500 Subject: [PATCH 075/112] fix tooltips --- .../public/layers/sources/es_agg_source.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index c4b2919c92de8..00b19496e2208 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -112,7 +112,7 @@ export class AbstractESAggSource extends AbstractESSource { const metricFields = this.getMetricFields(); const tooltipPropertiesPromises = []; - metricFields.forEach(async (metricField) => { + metricFields.forEach((metricField) => { let value; for (const key in properties) { if (properties.hasOwnProperty(key) && metricField.getName() === key) { @@ -121,16 +121,21 @@ export class AbstractESAggSource extends AbstractESSource { } } - const tooltipProperty = new ESAggMetricTooltipProperty( - metricField.getName(), - await metricField.getLabel(), - value, - indexPattern, - metricField - ); - tooltipPropertiesPromises.push(tooltipProperty); + const tooltipPromise = new Promise(async (resolve) => { + const tooltipProperty = new ESAggMetricTooltipProperty( + metricField.getName(), + await metricField.getLabel(), + value, + indexPattern, + metricField + ); + resolve(tooltipProperty); + }); + + + tooltipPropertiesPromises.push(tooltipPromise); }); - return Promise.all(tooltipPropertiesPromises); + return await Promise.all(tooltipPropertiesPromises); } } From fd39acc8ddad342b33f45833bb4b9fc87b3b877d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 14:11:18 -0500 Subject: [PATCH 076/112] fix test --- .../maps/public/layers/styles/vector/vector_style.test.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js index 782b6ee5612f3..a3020524a4e2a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js @@ -37,9 +37,6 @@ class MockSource { } - - - describe('getDescriptorWithMissingStylePropsRemoved', () => { const fieldName = 'doIStillExist'; const properties = { @@ -68,9 +65,7 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => { it('Should return no changes when next oridinal fields contain existing style property fields', () => { const vectorStyle = new VectorStyle({ properties }, new MockSource()); - const nextOridinalFields = [ - { name: fieldName } - ]; + const nextOridinalFields = [new MockField({ fieldName })]; const { hasChanges } = vectorStyle.getDescriptorWithMissingStylePropsRemoved(nextOridinalFields); expect(hasChanges).toBe(false); }); From 7e8a1fbe913000b3cc28664bd0cf0a3e28217797 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 14:17:38 -0500 Subject: [PATCH 077/112] rename for clarity --- .../maps/public/components/tooltip_selector.js | 2 +- .../maps/public/layers/fields/es_doc_field.js | 2 +- .../plugins/maps/public/layers/fields/field.js | 12 ++---------- .../maps/public/layers/fields/field_with_origin.js | 4 ++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index de77cc7eba389..54f353d419004 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -66,7 +66,7 @@ export class TooltipSelector extends Component { return new Promise(async (resolve, reject) => { try { const label = await field.getLabel(); - const type = await field.getType(); + const type = await field.getIndexPatternType(); resolve({ label: label, type: type, diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 187e046a2eb6c..2399995229113 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -22,7 +22,7 @@ export class ESDocField extends AbstractField { return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); } - async getType() { + async getIndexPatternType() { const field = await this._getField(); return field.type; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 6ccbda474cfd9..52d478fbc53ad 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -9,14 +9,6 @@ import { FIELD_ORIGIN } from '../../../common/constants'; export class AbstractField { - //todo consider removing - //double check if we're actually using this consistently - static FIELD_TYPE = { - STRING: 'string', - NUMBER: 'number', - DATE: 'date' - }; - constructor({ fieldName, source }) { this._fieldName = fieldName; this._source = source; @@ -30,8 +22,8 @@ export class AbstractField { return !!this._fieldName; } - async getType() { - return AbstractField.FIELD_TYPE.STRING; + async getIndexPatternType() { + return 'string'; } async getLabel() { diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js index 6aefa3b974a62..529974275decb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js @@ -26,8 +26,8 @@ export class FieldWithOrigin extends AbstractField { return this._field.isValid(); } - async getType() { - return await this._field.getType(); + async getIndexPatternType() { + return await this._field.getIndexPatternType(); } async getLabel() { From 12698fdf9fe2ebdf3aa90cc47161dbadca07114b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 16:26:49 -0500 Subject: [PATCH 078/112] add kibana region field --- .../layer_panel/join_editor/resources/join.js | 9 ++++++++- .../layers/fields/kibana_region_field.js | 12 +++++++++--- .../sources/ems_file_source/ems_file_source.js | 4 +--- .../es_search_source/es_search_source.js | 5 +---- .../kibana_regionmap_source.js | 18 ++++++++++++------ 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js index 44987e0d241e3..8927bcf316e5c 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js @@ -110,7 +110,14 @@ export class Join extends Component { async _loadLeftFields() { let leftFields; try { - leftFields = await this.props.layer.getLeftJoinFields(); + const leftFieldsInstances = await this.props.layer.getLeftJoinFields(); + leftFields = leftFieldsInstances.map(async (field) => { + return { + name: field.getName(), + label: await field.getLabel() + }; + }); + leftFields = await Promise.all(leftFields); } catch (error) { leftFields = []; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js index f341d05db9a3b..248c34173a8c2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/kibana_region_field.js @@ -6,14 +6,20 @@ import { AbstractField } from './field'; +import { TooltipProperty } from '../tooltips/tooltip_property'; -//todo: need to be implemented export class KibanaRegionField extends AbstractField { static type = 'KIBANA_REGION'; - async getType() { - return AbstractField.FIELD_TYPE.STRING; + async getLabel() { + const meta = await this._source.getVectorFileMeta(); + const field = meta.fields.find(f => f.name === this._fieldName); + return field ? field.description : this._fieldName; } + async createTooltipProperty(value) { + const label = await this.getLabel(); + return new TooltipProperty(this.getName(), label, value); + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index 9c1bd57873a2e..d331fe979d2fd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -146,9 +146,7 @@ export class EMSFileSource extends AbstractVectorSource { async getLeftJoinFields() { const emsFileLayer = await this.getEMSFileLayer(); const fields = emsFileLayer.getFieldsInLanguage(); - return fields.map(f => { - return { name: f.name, label: f.description }; - }); + return fields.map(f => this.createField({ fieldName: f.name })); } canFormatFeatureProperties() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 366819a193f80..c00f2bae21704 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -422,10 +422,7 @@ export class ESSearchSource extends AbstractESSource { async getLeftJoinFields() { const indexPattern = await this.getIndexPattern(); // Left fields are retrieved from _source. - return getSourceFields(indexPattern.fields) - .map(field => { - return { name: field.name, label: field.name }; - }); + return getSourceFields(indexPattern.fields).map(field => this.createField({ fieldName: field.name })); } async getSupportedShapeTypes() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js index c75c5600aaf92..e38e62e7d4177 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js @@ -11,6 +11,7 @@ import { getKibanaRegionList } from '../../../meta'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { FEATURE_ID_PROPERTY_NAME } from '../../../../common/constants'; +import { KibanaRegionField } from '../../fields/kibana_region_field'; export class KibanaRegionmapSource extends AbstractVectorSource { @@ -45,6 +46,13 @@ export class KibanaRegionmapSource extends AbstractVectorSource { ); }; + createField({ fieldName }) { + return new KibanaRegionField({ + fieldName, + source: this + }); + } + async getImmutableProperties() { return [ { @@ -59,7 +67,7 @@ export class KibanaRegionmapSource extends AbstractVectorSource { ]; } - async _getVectorFileMeta() { + async getVectorFileMeta() { const regionList = getKibanaRegionList(); const meta = regionList.find(source => source.name === this._descriptor.name); if (!meta) { @@ -75,7 +83,7 @@ export class KibanaRegionmapSource extends AbstractVectorSource { } async getGeoJsonWithMeta() { - const vectorFileMeta = await this._getVectorFileMeta(); + const vectorFileMeta = await this.getVectorFileMeta(); const featureCollection = await AbstractVectorSource.getGeoJson({ format: vectorFileMeta.format.type, featureCollectionPath: vectorFileMeta.meta.feature_collection_path, @@ -90,10 +98,8 @@ export class KibanaRegionmapSource extends AbstractVectorSource { } async getLeftJoinFields() { - const vectorFileMeta = await this._getVectorFileMeta(); - return vectorFileMeta.fields.map(f => { - return { name: f.name, label: f.description }; - }); + const vectorFileMeta = await this.getVectorFileMeta(); + return vectorFileMeta.fields.map(f => this.createField({ fieldName: f.name })); } async getDisplayName() { From 22432e80b4230b81954f545f05b859b7fbb0259c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 16:29:28 -0500 Subject: [PATCH 079/112] fix text stub --- .../plugins/maps/public/components/tooltip_selector.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js index c5ba55676bbb7..2a813dcea3a2e 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js @@ -25,7 +25,7 @@ class MockField { return this._label || 'foobar_label'; } - async getType() { + async getIndexPatternType() { return this._type || 'foobar_type'; } } From b0c13dd73aea188a384711dcb116426dd7a8c58a Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Nov 2019 23:43:00 -0500 Subject: [PATCH 080/112] tmp commit --- .../maps/public/layers/sources/es_agg_source.js | 6 ++++++ .../maps/public/layers/sources/es_source.js | 9 +++++---- .../legend/style_property_legend_row.js | 17 ++++++++--------- .../components/legend/vector_style_legend.js | 3 ++- .../vector/properties/dynamic_color_property.js | 11 ++++++++++- .../styles/vector/properties/style_property.js | 4 ++++ .../public/layers/styles/vector/vector_style.js | 13 +++++++------ 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 00b19496e2208..cf7693e8b62a5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -84,6 +84,12 @@ export class AbstractESAggSource extends AbstractESSource { return metrics; } + _getRawFieldName(fieldName) { + console.log('rafin', fieldName); + const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getName() === fieldName); + return metricField ? metricField.getESDocFieldName() : null; + } + formatMetricKey(aggType, fieldName) { return aggType !== COUNT_AGG_TYPE ? `${aggType}${AGG_DELIMITER}${fieldName}` : COUNT_PROP_NAME; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 18bbb7e6d492f..75bbd8ad6623f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -55,6 +55,10 @@ export class AbstractESSource extends AbstractVectorSource { return clonedDescriptor; } + _getRawFieldName(fieldName) { + return fieldName; + } + async _runEsQuery(requestName, searchSource, registerCancelCallback, requestDescription) { const abortController = new AbortController(); @@ -224,10 +228,7 @@ export class AbstractESSource extends AbstractVectorSource { return this._descriptor.id; } - _getRawFieldName(fieldName) { - const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getName() === fieldName); - return metricField ? metricField.getESDocFieldName() : null; - } + async getFieldFormatter(fieldName) { // fieldName could be an aggregation so it needs to be unpacked to expose raw field. diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js index 4d091389a360e..46f1372c0bc9f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -9,12 +9,12 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { styleOptionShapes, rangeShape } from '../style_option_shapes'; -import { VectorStyle } from '../../vector_style'; import { ColorGradient } from '../../../components/color_gradient'; import { CircleIcon } from './circle_icon'; import { getVectorStyleLabel } from '../get_vector_style_label'; import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule } from '@elastic/eui'; import { StyleLegendRow } from '../../../components/style_legend_row'; +import { vectorStyles } from '../../vector_style_defaults'; function getLineWidthIcons() { const defaultStyle = { @@ -32,7 +32,6 @@ function getLineWidthIcons() { function getSymbolSizeIcons() { const defaultStyle = { stroke: 'grey', - strokeWidth: 'none', fill: 'grey', }; return [ @@ -121,8 +120,7 @@ export class StylePropertyLegendRow extends Component { } _isStatic() { - return this.props.type === VectorStyle.STYLE_TYPE.STATIC || - !this.props.options.field || !this.props.options.field.name; + return !this.props.style.isDynamic() || !this.props.style.getField() || !this.props.style.getField().getName(); } _formatValue = value => { @@ -134,17 +132,18 @@ export class StylePropertyLegendRow extends Component { } render() { - const { name, options, range } = this.props; + + const { options, range, style } = this.props; if (this._isStatic()) { return null; } let header; if (options.color) { - header = ; - } else if (name === 'lineWidth') { + header = style.renderHeader(); + } else if (style.getStyleName() === vectorStyles.LINE_WIDTH) { header = renderHeaderWithIcons(getLineWidthIcons()); - } else if (name === 'iconSize') { + } else if (style.getStyleName() === vectorStyles.ICON_SIZE) { header = renderHeaderWithIcons(getSymbolSizeIcons()); } @@ -153,7 +152,7 @@ export class StylePropertyLegendRow extends Component { header={header} minLabel={this._formatValue(_.get(range, 'min', EMPTY_VALUE))} maxLabel={this._formatValue(_.get(range, 'max', EMPTY_VALUE))} - propertyLabel={getVectorStyleLabel(name)} + propertyLabel={getVectorStyleLabel(style.getStyleName())} fieldLabel={this.state.label} /> ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js index 60baaff158377..0931c23c84b11 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js @@ -10,10 +10,11 @@ import PropTypes from 'prop-types'; import { styleOptionShapes, rangeShape } from '../style_option_shapes'; import { StylePropertyLegendRow } from './style_property_legend_row'; -export function VectorStyleLegend({ getFieldLabel, getFieldFormatter, styleProperties }) { +export function VectorStyleLegend({ getFieldLabel, getFieldFormatter, styleProperties, stylesWithRanges }) { return styleProperties.map(styleProperty => { return ( ); + } else { + return null; + } + } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index 302fbb10d00b2..56b5765661ddf 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -25,4 +25,8 @@ export class AbstractStyleProperty { getOptions() { return this._options || {}; } + + renderHeader() { + return null; + } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 3a3cdb897b346..06409abf902f3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -298,14 +298,15 @@ export class VectorStyle extends AbstractStyle { } renderLegendDetails(getFieldLabel, getFieldFormatter) { - const styles = this.getRawProperties(); - const styleProperties = Object.keys(styles).map(styleName => { - const { type, options } = styles[styleName]; + const styles = this._getAllStyleProperties(); + const styleProperties = styles.map(style => { + const type = style.isDynamic() ? STYLE_TYPE.DYNAMIC : STYLE_TYPE.STATIC; return { - name: styleName, + name: style.getStyleName(), type, - options, - range: options && options.field && options.field.name ? this._getFieldRange(options.field.name) : null, + options: style.getOptions(), + range: style.isDynamic() && style.getField() && style.getField().getName() ? this._getFieldRange(style.getField().getName()) : null, + style: style }; }); From 74be592eec3e8268fa0576e10a48f01c34fb9a4c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 11:50:14 -0500 Subject: [PATCH 081/112] review feedback --- x-pack/legacy/plugins/maps/common/constants.js | 9 +++++---- .../plugins/maps/public/components/tooltip_selector.js | 2 +- .../fields/{ems_region_field.js => ems_file_field.js} | 4 ++-- .../plugins/maps/public/layers/fields/es_doc_field.js | 2 +- x-pack/legacy/plugins/maps/public/layers/fields/field.js | 2 +- .../maps/public/layers/fields/field_with_origin.js | 4 ++-- .../layers/sources/ems_file_source/ems_file_source.js | 4 ++-- .../sources/ems_file_source/update_source_editor.js | 4 ++-- 8 files changed, 16 insertions(+), 15 deletions(-) rename x-pack/legacy/plugins/maps/public/layers/fields/{ems_region_field.js => ems_file_field.js} (90%) diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index 4fc0d02a33a56..fd99ea300cd3a 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -55,7 +55,7 @@ export const FIELD_ORIGIN = { UNDEFINED: 'undefined' }; -export const SOURCE_DATA_ID_ORIGIN = FIELD_ORIGIN.SOURCE; +export const SOURCE_DATA_ID_ORIGIN = 'source'; export const GEOJSON_FILE = 'GEOJSON_FILE'; @@ -116,6 +116,7 @@ export const COUNT_AGG_TYPE = METRIC_TYPE.COUNT; export const COUNT_PROP_LABEL = METRIC_TYPE.COUNT; export const COUNT_PROP_NAME = 'doc_count'; -export const STYLE_TYPE = { 'STATIC': 'STATIC', 'DYNAMIC': 'DYNAMIC' }; - - +export const STYLE_TYPE = { + 'STATIC': 'STATIC', + 'DYNAMIC': 'DYNAMIC' +}; diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 54f353d419004..937d9bca4549f 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -66,7 +66,7 @@ export class TooltipSelector extends Component { return new Promise(async (resolve, reject) => { try { const label = await field.getLabel(); - const type = await field.getIndexPatternType(); + const type = await field.getDataType(); resolve({ label: label, type: type, diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js similarity index 90% rename from x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js rename to x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js index a078fc6cd3f35..4c4b0e08493e8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/ems_region_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js @@ -9,8 +9,8 @@ import { AbstractField } from './field'; import { TooltipProperty } from '../tooltips/tooltip_property'; //todo: rename to ESMFileField -export class EMSRegionLayerField extends AbstractField { - static type = 'EMS_REGION_LAYER'; +export class EMSFileField extends AbstractField { + static type = 'EMS_FILE'; async getLabel() { const emsFileLayer = await this._source.getEMSFileLayer(); diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 2399995229113..f93053dea24aa 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -22,7 +22,7 @@ export class ESDocField extends AbstractField { return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern); } - async getIndexPatternType() { + async getDataType() { const field = await this._getField(); return field.type; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index 52d478fbc53ad..fa982a0cc4c06 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -22,7 +22,7 @@ export class AbstractField { return !!this._fieldName; } - async getIndexPatternType() { + async getDataType() { return 'string'; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js index 529974275decb..5d7ee7474e028 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js @@ -26,8 +26,8 @@ export class FieldWithOrigin extends AbstractField { return this._field.isValid(); } - async getIndexPatternType() { - return await this._field.getIndexPatternType(); + async getDataType() { + return await this._field.getDataType(); } async getLabel() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index d331fe979d2fd..46711e09b1a01 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -13,7 +13,7 @@ import { EMSFileCreateSourceEditor } from './create_source_editor'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { UpdateSourceEditor } from './update_source_editor'; -import { EMSRegionLayerField } from '../../fields/ems_region_field'; +import { EMSFileField } from '../../fields/ems_file_field'; export class EMSFileSource extends AbstractVectorSource { @@ -49,7 +49,7 @@ export class EMSFileSource extends AbstractVectorSource { } createField({ fieldName }) { - return new EMSRegionLayerField({ + return new EMSFileField({ fieldName, source: this }); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index 705f45a9d69b6..70c6a65044478 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -8,7 +8,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { TooltipSelector } from '../../../components/tooltip_selector'; import { getEMSClient } from '../../../meta'; -import { EMSRegionLayerField } from '../../fields/ems_region_field'; +import { EMSFileField } from '../../fields/ems_file_field'; export class UpdateSourceEditor extends Component { @@ -38,7 +38,7 @@ export class UpdateSourceEditor extends Component { const emsFiles = await emsClient.getFileLayers(); const emsFile = emsFiles.find((emsFile => emsFile.getId() === this.props.layerId)); const emsFields = emsFile.getFieldsInLanguage(); - fields = emsFields.map(field => new EMSRegionLayerField({ + fields = emsFields.map(field => new EMSFileField({ fieldName: field.name, source: this.props.source })); From f36e3b9c3551c4a823145b50b8a3be0893cd6127 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 11:50:56 -0500 Subject: [PATCH 082/112] remove comment --- .../legacy/plugins/maps/public/layers/fields/ems_file_field.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js index 4c4b0e08493e8..c6da7673ba606 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/ems_file_field.js @@ -8,7 +8,6 @@ import { AbstractField } from './field'; import { TooltipProperty } from '../tooltips/tooltip_property'; -//todo: rename to ESMFileField export class EMSFileField extends AbstractField { static type = 'EMS_FILE'; From e54f86f31c483263e64e28205607d9cb7a445f07 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 12:40:14 -0500 Subject: [PATCH 083/112] field formatter --- .../plugins/maps/public/layers/fields/field.js | 4 ++++ .../maps/public/layers/sources/es_agg_source.js | 1 - .../components/legend/style_property_legend_row.js | 12 ++++++++---- .../vector/components/legend/vector_style_legend.js | 4 +--- .../maps/public/layers/styles/vector/vector_style.js | 3 +-- .../plugins/maps/public/layers/vector_layer.js | 11 +---------- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index fa982a0cc4c06..efe20a1088556 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -18,6 +18,10 @@ export class AbstractField { return this._fieldName; } + getSource() { + return this._source; + } + isValid() { return !!this._fieldName; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index cf7693e8b62a5..5d0f20ad4e39f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -85,7 +85,6 @@ export class AbstractESAggSource extends AbstractESSource { } _getRawFieldName(fieldName) { - console.log('rafin', fieldName); const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getName() === fieldName); return metricField ? metricField.getESDocFieldName() : null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js index 46f1372c0bc9f..3031ad502ce1d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -9,7 +9,6 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { styleOptionShapes, rangeShape } from '../style_option_shapes'; -import { ColorGradient } from '../../../components/color_gradient'; import { CircleIcon } from './circle_icon'; import { getVectorStyleLabel } from '../get_vector_style_label'; import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule } from '@elastic/eui'; @@ -96,7 +95,13 @@ export class StylePropertyLegendRow extends Component { } async _loadFieldFormatter() { - this._fieldValueFormatter = await this.props.getFieldFormatter(this.props.options.field); + if (this.props.style.isDynamic() && this.props.style.getField() && this.props.style.getField().getSource()) { + const field = this.props.style.getField(); + const source = field.getSource(); + this._fieldValueFormatter = await source.getFieldFormatter(field.getName()); + } else { + this._fieldValueFormatter = null; + } if (this._isMounted) { this.setState({ hasLoadedFieldFormatter: true }); } @@ -108,7 +113,7 @@ export class StylePropertyLegendRow extends Component { } // have to load label and then check for changes since field name stays constant while label may change - const label = await this.props.getFieldLabel(this.props.options.field.name); + const label = await this.props.style.getField().getLabel(); if (this._prevLabel === label) { return; } @@ -164,6 +169,5 @@ StylePropertyLegendRow.propTypes = { type: PropTypes.string, options: PropTypes.oneOfType(styleOptionShapes).isRequired, range: rangeShape, - getFieldLabel: PropTypes.func.isRequired, getFieldFormatter: PropTypes.func.isRequired, }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js index 0931c23c84b11..c14751d2e0836 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js @@ -10,7 +10,7 @@ import PropTypes from 'prop-types'; import { styleOptionShapes, rangeShape } from '../style_option_shapes'; import { StylePropertyLegendRow } from './style_property_legend_row'; -export function VectorStyleLegend({ getFieldLabel, getFieldFormatter, styleProperties, stylesWithRanges }) { +export function VectorStyleLegend({ getFieldFormatter, styleProperties }) { return styleProperties.map(styleProperty => { return ( ); @@ -36,6 +35,5 @@ const stylePropertyShape = PropTypes.shape({ VectorStyleLegend.propTypes = { styleProperties: PropTypes.arrayOf(stylePropertyShape).isRequired, - getFieldLabel: PropTypes.func.isRequired, getFieldFormatter: PropTypes.func.isRequired, }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 06409abf902f3..7594479ba3b56 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -297,7 +297,7 @@ export class VectorStyle extends AbstractStyle { ); } - renderLegendDetails(getFieldLabel, getFieldFormatter) { + renderLegendDetails(getFieldFormatter) { const styles = this._getAllStyleProperties(); const styleProperties = styles.map(style => { const type = style.isDynamic() ? STYLE_TYPE.DYNAMIC : STYLE_TYPE.STATIC; @@ -313,7 +313,6 @@ export class VectorStyle extends AbstractStyle { return ( ); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index d0b96a8cd64bd..8824f7e558623 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -185,15 +185,6 @@ export class VectorLayer extends AbstractLayer { } getLegendDetails() { - - const getFieldLabel = async fieldName => { - const ordinalFields = await this.getOrdinalFields(); - const field = ordinalFields.find(field => { - return field.getName() === fieldName; - }); - return field ? await field.getLabel() : fieldName; - }; - const getFieldFormatter = async field => { const source = this._getFieldSource(field); if (!source) { @@ -203,7 +194,7 @@ export class VectorLayer extends AbstractLayer { return await source.getFieldFormatter(field.name); }; - return this._style.renderLegendDetails(getFieldLabel, getFieldFormatter); + return this._style.renderLegendDetails(getFieldFormatter); } _getBoundsBasedOnData() { From 4ab5ce0fa8de74f6fd6a62b1a5b4bb608b49a7eb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 12:50:20 -0500 Subject: [PATCH 084/112] remove records --- .../legend/style_property_legend_row.js | 9 +++------ .../components/legend/vector_style_legend.js | 15 ++++----------- .../public/layers/styles/vector/vector_style.js | 7 +------ 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js index 3031ad502ce1d..4b3d80fcbf7e4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -138,13 +138,13 @@ export class StylePropertyLegendRow extends Component { render() { - const { options, range, style } = this.props; + const { range, style } = this.props; if (this._isStatic()) { return null; } let header; - if (options.color) { + if (style.getOptions().color) { header = style.renderHeader(); } else if (style.getStyleName() === vectorStyles.LINE_WIDTH) { header = renderHeaderWithIcons(getLineWidthIcons()); @@ -165,9 +165,6 @@ export class StylePropertyLegendRow extends Component { } StylePropertyLegendRow.propTypes = { - name: PropTypes.string.isRequired, - type: PropTypes.string, options: PropTypes.oneOfType(styleOptionShapes).isRequired, - range: rangeShape, - getFieldFormatter: PropTypes.func.isRequired, + range: rangeShape }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js index c14751d2e0836..aa41202243b85 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/vector_style_legend.js @@ -7,33 +7,26 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { styleOptionShapes, rangeShape } from '../style_option_shapes'; +import { rangeShape } from '../style_option_shapes'; import { StylePropertyLegendRow } from './style_property_legend_row'; -export function VectorStyleLegend({ getFieldFormatter, styleProperties }) { +export function VectorStyleLegend({ styleProperties }) { return styleProperties.map(styleProperty => { return ( ); }); } const stylePropertyShape = PropTypes.shape({ - name: PropTypes.string.isRequired, - type: PropTypes.string, - options: PropTypes.oneOfType(styleOptionShapes).isRequired, range: rangeShape, + style: PropTypes.object }); VectorStyleLegend.propTypes = { - styleProperties: PropTypes.arrayOf(stylePropertyShape).isRequired, - getFieldFormatter: PropTypes.func.isRequired, + styleProperties: PropTypes.arrayOf(stylePropertyShape).isRequired }; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 7594479ba3b56..40ea22cd00f4f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -297,14 +297,10 @@ export class VectorStyle extends AbstractStyle { ); } - renderLegendDetails(getFieldFormatter) { + renderLegendDetails() { const styles = this._getAllStyleProperties(); const styleProperties = styles.map(style => { - const type = style.isDynamic() ? STYLE_TYPE.DYNAMIC : STYLE_TYPE.STATIC; return { - name: style.getStyleName(), - type, - options: style.getOptions(), range: style.isDynamic() && style.getField() && style.getField().getName() ? this._getFieldRange(style.getField().getName()) : null, style: style }; @@ -313,7 +309,6 @@ export class VectorStyle extends AbstractStyle { return ( ); } From 788573e977f3a9471ad9c39e1d7233597f700f78 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 13:02:27 -0500 Subject: [PATCH 085/112] rename for clarity --- .../layer_control/layer_toc/toc_entry/view.js | 2 +- .../plugins/maps/public/layers/heatmap_layer.js | 4 ++-- x-pack/legacy/plugins/maps/public/layers/layer.js | 2 +- .../public/layers/styles/heatmap/heatmap_style.js | 2 +- .../components/legend/style_property_legend_row.js | 4 +--- .../vector/components/legend/vector_style_legend.js | 2 +- .../public/layers/styles/vector/vector_style.js | 2 +- .../plugins/maps/public/layers/vector_layer.js | 13 ++----------- 8 files changed, 10 insertions(+), 21 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.js index 8fd4ba8b13354..dc0756978010e 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.js @@ -227,7 +227,7 @@ export class TOCEntry extends React.Component { return null; } - const tocDetails = this.props.layer.getLegendDetails(); + const tocDetails = this.props.layer.renderLegendDetails(); if (!tocDetails) { return null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 0ddfb2b7e3bc7..422c0d9c06683 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -102,8 +102,8 @@ export class HeatmapLayer extends VectorLayer { return true; } - getLegendDetails() { + renderLegendDetails() { const metricFields = this._source.getMetricFields(); - return this._style.getLegendDetails(metricFields[0]); + return this._style.renderLegendDetails(metricFields[0]); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index a26ad6a40581f..b5ad205ed6df6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -195,7 +195,7 @@ export class AbstractLayer { return false; } - getLegendDetails() { + renderLegendDetails() { return null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js index eae494b5b9a44..e4982c86b53bb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js @@ -50,7 +50,7 @@ export class HeatmapStyle extends AbstractStyle { ); } - getLegendDetails(field) { + renderLegendDetails(field) { return ( ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 40ea22cd00f4f..0a9eabd26ef94 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -299,7 +299,7 @@ export class VectorStyle extends AbstractStyle { renderLegendDetails() { const styles = this._getAllStyleProperties(); - const styleProperties = styles.map(style => { + const styleProperties = styles.map((style) => { return { range: style.isDynamic() && style.getField() && style.getField().getName() ? this._getFieldRange(style.getField().getName()) : null, style: style diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 8824f7e558623..2f32a4840e538 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -184,17 +184,8 @@ export class VectorLayer extends AbstractLayer { return this._style.getDynamicPropertiesArray().length > 0; } - getLegendDetails() { - const getFieldFormatter = async field => { - const source = this._getFieldSource(field); - if (!source) { - return null; - } - - return await source.getFieldFormatter(field.name); - }; - - return this._style.renderLegendDetails(getFieldFormatter); + renderLegendDetails() { + return this._style.renderLegendDetails(); } _getBoundsBasedOnData() { From 20c00bf92dfe59029681cda002d85d66bdc6ba65 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 14:03:08 -0500 Subject: [PATCH 086/112] fix jest --- .../plugins/maps/public/components/tooltip_selector.test.js | 2 +- .../layer_control/layer_toc/toc_entry/view.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js index 2a813dcea3a2e..6f012cf4e82a9 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js @@ -25,7 +25,7 @@ class MockField { return this._label || 'foobar_label'; } - async getIndexPatternType() { + async getDataType() { return this._type || 'foobar_type'; } } diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.test.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.test.js index dc0f9950919e4..ebb9fc27be149 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.test.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/view.test.js @@ -13,7 +13,7 @@ const LAYER_ID = '1'; const mockLayer = { getId: () => { return LAYER_ID; }, - getLegendDetails: () => { return (
TOC details mock
); }, + renderLegendDetails: () => { return (
TOC details mock
); }, getDisplayName: () => { return 'layer 1'; }, isVisible: () => { return true; }, showAtZoomLevel: () => { return true; }, From 88e748726d7b63dfa44844cfd2cb15c0486258a1 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Nov 2019 14:39:10 -0500 Subject: [PATCH 087/112] optimize initialization --- .../public/components/tooltip_selector.js | 69 ++++++++++++------- .../es_search_source/es_search_source.js | 1 + 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 937d9bca4549f..84e0a5a91c7d1 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -31,11 +31,28 @@ const reorder = (list, startIndex, endIndex) => { return result; }; +const getProps = async field => { + return new Promise(async (resolve, reject) => { + try { + const label = await field.getLabel(); + const type = await field.getDataType(); + resolve({ + label: label, + type: type, + name: field.getName() + }); + } catch(e) { + reject(e); + } + }); +}; + export class TooltipSelector extends Component { state = { fieldProps: [], - selectedFieldProps: [] + selectedFieldProps: [], + fieldPropsInitialized: false }; constructor() { @@ -46,6 +63,7 @@ export class TooltipSelector extends Component { componentDidMount() { this._isMounted = true; this._loadFieldProps(); + this._loadTooltipFieldProps(); } componentWillUnmount() { @@ -53,43 +71,41 @@ export class TooltipSelector extends Component { } componentDidUpdate() { + this._loadTooltipFieldProps(); this._loadFieldProps(); } - async _loadFieldProps() { - if (!this.props.fields || !this.props.tooltipFields) { + async _loadTooltipFieldProps() { + + if (!this.props.tooltipFields) { return; } - const getProps = async field => { - return new Promise(async (resolve, reject) => { - try { - const label = await field.getLabel(); - const type = await field.getDataType(); - resolve({ - label: label, - type: type, - name: field.getName() - }); - } catch(e) { - reject(e); - } - }); - }; - - const props = this.props.fields.map(getProps); const selectedProps = this.props.tooltipFields.map(getProps); + const selectedFieldProps = await Promise.all(selectedProps); + if (this._isMounted) { + if (!_.isEqual(this.state.selectedFieldProps, selectedFieldProps)) { + this.setState({ selectedFieldProps }); + } + } + + } - const newState = { - fieldProps: await Promise.all(props), - selectedFieldProps: await Promise.all(selectedProps) - }; + async _loadFieldProps() { + if (!this.props.fields || this.state.fieldPropsInitialized) { + return; + } + const props = this.props.fields.map(getProps); + const fieldProps = await Promise.all(props); if (this._isMounted) { - if (!_.isEqual(this.state, newState)) { - this.setState(newState); + if (!_.isEqual(this.state.fieldProps, fieldProps)) { + this.setState({ + fieldProps, + fieldPropsInitialized: true + }); } } @@ -225,3 +241,4 @@ export class TooltipSelector extends Component { ); } } + diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index c00f2bae21704..efa16a4955f86 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -69,6 +69,7 @@ export class ESSearchSource extends AbstractESSource { }, inspectorAdapters); this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField({ fieldName: property })); + console.log('ttf', this._tooltipFields); } createField({ fieldName }) { From ae8fd4cf5aa13d836d797d323a8700da595a2ec9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 15 Nov 2019 15:07:49 -0500 Subject: [PATCH 088/112] lint --- .../layers/styles/vector/properties/dynamic_color_property.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js index 2b5322c692908..4b4b853c274cb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.js @@ -9,8 +9,8 @@ import { DynamicStyleProperty } from './dynamic_style_property'; import _ from 'lodash'; import { getComputedFieldName } from '../style_util'; import { getColorRampStops } from '../../color_utils'; -import {ColorGradient} from "../../components/color_gradient"; -import React from "react"; +import { ColorGradient } from '../../components/color_gradient'; +import React from 'react'; export class DynamicColorProperty extends DynamicStyleProperty { From 1681e17f8797a4ac5a5c94dec9a622280ff4ee7b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 15 Nov 2019 15:09:33 -0500 Subject: [PATCH 089/112] regenerate after rename --- .../layer_toc/toc_entry/__snapshots__/view.test.js.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/__snapshots__/view.test.js.snap b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/__snapshots__/view.test.js.snap index 7fb7e58e81c99..2ca994647e1da 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/__snapshots__/view.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/__snapshots__/view.test.js.snap @@ -19,10 +19,10 @@ exports[`TOCEntry is rendered 1`] = ` Object { "getDisplayName": [Function], "getId": [Function], - "getLegendDetails": [Function], "hasErrors": [Function], "hasLegendDetails": [Function], "isVisible": [Function], + "renderLegendDetails": [Function], "showAtZoomLevel": [Function], } } @@ -87,10 +87,10 @@ exports[`TOCEntry props isReadOnly 1`] = ` Object { "getDisplayName": [Function], "getId": [Function], - "getLegendDetails": [Function], "hasErrors": [Function], "hasLegendDetails": [Function], "isVisible": [Function], + "renderLegendDetails": [Function], "showAtZoomLevel": [Function], } } @@ -137,10 +137,10 @@ exports[`TOCEntry props should display layer details when isLegendDetailsOpen is Object { "getDisplayName": [Function], "getId": [Function], - "getLegendDetails": [Function], "hasErrors": [Function], "hasLegendDetails": [Function], "isVisible": [Function], + "renderLegendDetails": [Function], "showAtZoomLevel": [Function], } } From f278cd57943c19bde2d948c80c90cd456f298492 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 15 Nov 2019 15:49:01 -0500 Subject: [PATCH 090/112] keep track of object reference --- .../plugins/maps/public/components/tooltip_selector.js | 10 ++++++---- .../sources/es_search_source/es_search_source.js | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 84e0a5a91c7d1..8d2542d3a0deb 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -50,9 +50,9 @@ const getProps = async field => { export class TooltipSelector extends Component { state = { + previousFields: null, fieldProps: [], - selectedFieldProps: [], - fieldPropsInitialized: false + selectedFieldProps: [] }; constructor() { @@ -94,17 +94,19 @@ export class TooltipSelector extends Component { async _loadFieldProps() { - if (!this.props.fields || this.state.fieldPropsInitialized) { + if (!this.props.fields || this.props.fields === this.state.previousFields) { + console.log('skip!', this.props.fields, this.state.previousFields); return; } + const previousFields = this.props.fields; const props = this.props.fields.map(getProps); const fieldProps = await Promise.all(props); if (this._isMounted) { if (!_.isEqual(this.state.fieldProps, fieldProps)) { this.setState({ fieldProps, - fieldPropsInitialized: true + previousFields: previousFields }); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index efa16a4955f86..c00f2bae21704 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -69,7 +69,6 @@ export class ESSearchSource extends AbstractESSource { }, inspectorAdapters); this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField({ fieldName: property })); - console.log('ttf', this._tooltipFields); } createField({ fieldName }) { From 2ae2023c0437cf69b352239ba70ae56de94b50a2 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 15 Nov 2019 15:58:48 -0500 Subject: [PATCH 091/112] remove log --- x-pack/legacy/plugins/maps/public/components/tooltip_selector.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 8d2542d3a0deb..2cdaaee6d261d 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -95,7 +95,6 @@ export class TooltipSelector extends Component { async _loadFieldProps() { if (!this.props.fields || this.props.fields === this.state.previousFields) { - console.log('skip!', this.props.fields, this.state.previousFields); return; } From 6852056eb9bd8a49c76af98b471926cac34d38a9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 15 Nov 2019 16:27:09 -0500 Subject: [PATCH 092/112] use getter, so count is loaded --- .../legacy/plugins/maps/public/layers/sources/es_agg_source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 5d0f20ad4e39f..096f7985c0eef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -68,7 +68,7 @@ export class AbstractESAggSource extends AbstractESSource { } getMetricFieldForName(fieldName) { - return this._metricFields.find(metricField => { + return this.getMetricFields().find(metricField => { return metricField.getName() === fieldName; }); } From 9cb869c8710b85cb4be0f321a11839290c79b0c4 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 18 Nov 2019 13:12:37 -0500 Subject: [PATCH 093/112] ensure styleprops get cleared --- .../layers/styles/vector/vector_style.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 0a9eabd26ef94..8d4694b8359c2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -114,19 +114,22 @@ export class VectorStyle extends AbstractStyle { */ getDescriptorWithMissingStylePropsRemoved(nextOrdinalFields) { - const originalProperties = this.getRawProperties(); const updatedProperties = {}; + const dynamicProperties = Object.keys(originalProperties).filter(key => { + const { type, options } = originalProperties[key] || {}; + return type === STYLE_TYPE.DYNAMIC && options.field && options.field.name; + }); - this.getDynamicPropertiesArray().forEach(dynamicProperty =>{ + dynamicProperties.forEach(key => { - const field = dynamicProperty.getField(); - if (!field || !field.isValid()) { + const dynamicProperty = originalProperties[key]; + const fieldName = dynamicProperty && dynamicProperty.options.field && dynamicProperty.options.field.name; + if (!fieldName) { return; } - const fieldName = field.getName(); const matchingOrdinalField = nextOrdinalFields.find(ordinalField => { return fieldName === ordinalField.getName(); }); @@ -135,20 +138,20 @@ export class VectorStyle extends AbstractStyle { return; } - updatedProperties[dynamicProperty.getStyleName()] = { + updatedProperties[key] = { type: DynamicStyleProperty.type, options: { - ...originalProperties[dynamicProperty.getStyleName()].options + ...originalProperties[key].options } }; - delete updatedProperties[dynamicProperty.getStyleName()].options.field; + delete updatedProperties[key].options.field; }); if (Object.keys(updatedProperties).length === 0) { return { hasChanges: false, - nextStyleDescriptor: { ...this._descriptor }, + nextStyleDescriptor: { ...this._descriptor } }; } From 86e0dec90d8462b791f01e8cdb44de9175b3f741 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 18 Nov 2019 13:26:35 -0500 Subject: [PATCH 094/112] review --- x-pack/legacy/plugins/maps/common/constants.js | 7 ++++++- .../maps/public/components/tooltip_selector.js | 1 - .../public/components/tooltip_selector.test.js | 14 ++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index fd99ea300cd3a..3a266d07ec6f7 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -3,6 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; + export const EMS_CATALOGUE_PATH = 'ems/catalogue'; export const EMS_FILES_CATALOGUE_PATH = 'ems/files'; @@ -113,7 +115,10 @@ export const METRIC_TYPE = { }; export const COUNT_AGG_TYPE = METRIC_TYPE.COUNT; -export const COUNT_PROP_LABEL = METRIC_TYPE.COUNT; +export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', { + defaultMessage: 'count' +}); + export const COUNT_PROP_NAME = 'doc_count'; export const STYLE_TYPE = { diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 2cdaaee6d261d..1038463b038f8 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -75,7 +75,6 @@ export class TooltipSelector extends Component { this._loadFieldProps(); } - async _loadTooltipFieldProps() { if (!this.props.tooltipFields) { diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js index 6f012cf4e82a9..9797bce2cf8c9 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.test.js @@ -48,7 +48,7 @@ const defaultProps = { describe('TooltipSelector', () => { - test('should render component', (done) => { + test('should render component', async () => { const component = shallow( { /> ); - setTimeout(() => { - component.update(); - expect(component) - .toMatchSnapshot(); - done(); - }); - + // Ensure all promises resolve + await new Promise(resolve => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + expect(component).toMatchSnapshot(); }); From 2e707bc383456762eca2ab04b483047232293560 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 18 Nov 2019 13:47:00 -0500 Subject: [PATCH 095/112] make state-checking consistent --- .../public/components/tooltip_selector.js | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 1038463b038f8..186e02dd7f620 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -19,7 +19,6 @@ import { import { AddTooltipFieldPopover } from './add_tooltip_field_popover'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import _ from 'lodash'; // TODO import reorder from EUI once its exposed as service // https://github.com/elastic/eui/issues/2372 @@ -50,7 +49,6 @@ const getProps = async field => { export class TooltipSelector extends Component { state = { - previousFields: null, fieldProps: [], selectedFieldProps: [] }; @@ -58,6 +56,8 @@ export class TooltipSelector extends Component { constructor() { super(); this._isMounted = false; + this._previousFields = null; + this._previousSelectedTooltips = null; } componentDidMount() { @@ -77,36 +77,29 @@ export class TooltipSelector extends Component { async _loadTooltipFieldProps() { - if (!this.props.tooltipFields) { + if (!this.props.tooltipFields && this.props.fields === this._previousSelectedTooltips) { return; } const selectedProps = this.props.tooltipFields.map(getProps); const selectedFieldProps = await Promise.all(selectedProps); if (this._isMounted) { - if (!_.isEqual(this.state.selectedFieldProps, selectedFieldProps)) { - this.setState({ selectedFieldProps }); - } + this.setState({ selectedFieldProps }); } } async _loadFieldProps() { - if (!this.props.fields || this.props.fields === this.state.previousFields) { + if (!this.props.fields || this.props.fields === this._previousFields) { return; } - const previousFields = this.props.fields; + this._previousFields = this.props.fields; const props = this.props.fields.map(getProps); const fieldProps = await Promise.all(props); if (this._isMounted) { - if (!_.isEqual(this.state.fieldProps, fieldProps)) { - this.setState({ - fieldProps, - previousFields: previousFields - }); - } + this.setState({ fieldProps }); } } From c71be8958d15efe7d71421dc9c82020e7025433e Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 18 Nov 2019 16:37:29 -0500 Subject: [PATCH 096/112] fix infinite loop --- .../legacy/plugins/maps/public/components/tooltip_selector.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js index 186e02dd7f620..50cbbdb3b7180 100644 --- a/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js +++ b/x-pack/legacy/plugins/maps/public/components/tooltip_selector.js @@ -77,10 +77,11 @@ export class TooltipSelector extends Component { async _loadTooltipFieldProps() { - if (!this.props.tooltipFields && this.props.fields === this._previousSelectedTooltips) { + if (!this.props.tooltipFields || this.props.tooltipFields === this._previousSelectedTooltips) { return; } + this._previousSelectedTooltips = this.props.tooltipFields; const selectedProps = this.props.tooltipFields.map(getProps); const selectedFieldProps = await Promise.all(selectedProps); if (this._isMounted) { From a586646db5ac281c12e576029473772f1e7f88f4 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 18 Nov 2019 17:42:10 -0500 Subject: [PATCH 097/112] fix agg tooltip creation --- .../maps/public/layers/fields/es_agg_field.js | 13 +++++++++++++ .../maps/public/layers/sources/es_agg_source.js | 16 +--------------- .../tooltips/es_aggmetric_tooltip_property.js | 4 ++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 8851e765e540f..6cc4b075bae81 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -7,6 +7,7 @@ import { AbstractField } from './field'; import { COUNT_AGG_TYPE } from '../../../common/constants'; +import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; export class ESAggMetricField extends AbstractField { @@ -43,6 +44,18 @@ export class ESAggMetricField extends AbstractField { return this.getAggType() !== COUNT_AGG_TYPE ? `${this.getAggType()} ${this.getESDocFieldName()}` : COUNT_AGG_TYPE; } + async createTooltipProperty(value) { + const indexPattern = await this._source.getIndexPattern(); + return new ESAggMetricTooltipProperty( + this.getName(), + await this.getLabel(), + value, + indexPattern, + this + ); + } + + makeMetricAggConfig() { const metricAggConfig = { id: this.getName(), diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 096f7985c0eef..d65fc8c6e4c6a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -5,7 +5,6 @@ */ import { AbstractESSource } from './es_source'; -import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; 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 } from '../../../common/constants'; @@ -107,13 +106,6 @@ export class AbstractESAggSource extends AbstractESSource { } async filterAndFormatPropertiesToHtmlForMetricFields(properties) { - let indexPattern; - try { - indexPattern = await this.getIndexPattern(); - } catch(error) { - console.warn(`Unable to find Index pattern ${this._descriptor.indexPatternId}, values are not formatted`); - return properties; - } const metricFields = this.getMetricFields(); const tooltipPropertiesPromises = []; @@ -127,13 +119,7 @@ export class AbstractESAggSource extends AbstractESSource { } const tooltipPromise = new Promise(async (resolve) => { - const tooltipProperty = new ESAggMetricTooltipProperty( - metricField.getName(), - await metricField.getLabel(), - value, - indexPattern, - metricField - ); + const tooltipProperty = await metricField.createTooltipProperty(value); resolve(tooltipProperty); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js b/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js index 48fa4327a5217..dce9ed479a4d7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js @@ -23,10 +23,10 @@ export class ESAggMetricTooltipProperty extends ESTooltipProperty { if (typeof this._rawValue === 'undefined') { return '-'; } - if (this._metricField.type === METRIC_TYPE.COUNT || this._metricField.type === METRIC_TYPE.UNIQUE_COUNT) { + if (this._metricField.getAggType() === METRIC_TYPE.COUNT || this._metricField.getAggType() === METRIC_TYPE.UNIQUE_COUNT) { return this._rawValue; } - const indexPatternField = this._indexPattern.fields.getByName(this._metricField.field); + const indexPatternField = this._indexPattern.fields.getByName(this._metricField.getESDocFieldName()); if (!indexPatternField) { return this._rawValue; } From ff424e9298e78000d0c4ffe8668ab27a5aaf295d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 19 Nov 2019 09:27:56 -0500 Subject: [PATCH 098/112] feedback --- .../maps/public/layers/fields/es_doc_field.js | 2 +- .../plugins/maps/public/layers/fields/field.js | 9 --------- .../maps/public/layers/fields/field_with_origin.js | 14 ++------------ .../vector/components/vector_style_editor.js | 2 +- 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index f93053dea24aa..5cc0c9a29ce02 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -14,7 +14,7 @@ export class ESDocField extends AbstractField { async _getField() { const indexPattern = await this._source.getIndexPattern(); - return indexPattern.fields.find((field) => field.name === this._fieldName); + return indexPattern.fields.getByName(this._fieldName); } async createTooltipProperty(value) { diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index efe20a1088556..c7f5c881c42f0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -42,12 +42,3 @@ export class AbstractField { return FIELD_ORIGIN.UNDEFINED; } } - - - - - - - - - diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js index 5d7ee7474e028..f74b9a0283b78 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js @@ -10,8 +10,8 @@ import { AbstractField } from './field'; export class FieldWithOrigin extends AbstractField { //todo: This annotated field was introduced due to legacy constraints in the code. - //Field-descriptors in styles use a combination of field-name and FIELD_ORIGIN-enumeration to uniquely identify a field - //across layer-source and joins. + //Field-descriptors in styles use a combination of field-name and FIELD_ORIGIN-enumeration + //to uniquely identify a field across layer-source and joins. constructor({ field, origin }) { super({}); this._field = field; @@ -37,14 +37,4 @@ export class FieldWithOrigin extends AbstractField { getOrigin() { return this._origin; } - } - - - - - - - - - diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 2bab2bf8966fb..cd200ee2b5a07 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -77,7 +77,7 @@ export class VectorStyleEditor extends Component { return { label: await field.getLabel(), name: field.getName(), - origin: field.getOrigin() + origin: field.ggetOrigin() }; }); From 47e98a4c22280a3ef58da9330328eb1403994af2 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 19 Nov 2019 09:43:51 -0500 Subject: [PATCH 099/112] remove field_with_origin --- .../legacy/plugins/maps/common/constants.js | 3 +- .../maps/public/layers/fields/field.js | 5 ++- .../public/layers/fields/field_with_origin.js | 40 ------------------- .../public/layers/sources/es_agg_source.js | 12 ++++-- .../public/layers/sources/es_term_source.js | 6 ++- .../vector/components/vector_style_editor.js | 2 +- .../maps/public/layers/vector_layer.js | 24 ++--------- 7 files changed, 23 insertions(+), 69 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index 3094f287c7ac2..691c679e5290b 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -53,8 +53,7 @@ export const ES_PEW_PEW = 'ES_PEW_PEW'; export const FIELD_ORIGIN = { SOURCE: 'source', - JOIN: 'join', - UNDEFINED: 'undefined' + JOIN: 'join' }; export const SOURCE_DATA_ID_ORIGIN = 'source'; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js index c7f5c881c42f0..b53c6991c6ebe 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.js @@ -9,9 +9,10 @@ import { FIELD_ORIGIN } from '../../../common/constants'; export class AbstractField { - constructor({ fieldName, source }) { + constructor({ fieldName, source, origin }) { this._fieldName = fieldName; this._source = source; + this._origin = origin || FIELD_ORIGIN.SOURCE; } getName() { @@ -39,6 +40,6 @@ export class AbstractField { } getOrigin() { - return FIELD_ORIGIN.UNDEFINED; + return this._origin; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js b/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js deleted file mode 100644 index f74b9a0283b78..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field_with_origin.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 { AbstractField } from './field'; - -export class FieldWithOrigin extends AbstractField { - - //todo: This annotated field was introduced due to legacy constraints in the code. - //Field-descriptors in styles use a combination of field-name and FIELD_ORIGIN-enumeration - //to uniquely identify a field across layer-source and joins. - constructor({ field, origin }) { - super({}); - this._field = field; - this._origin = origin; - } - - getName() { - return this._field.getName(); - } - - isValid() { - return this._field.isValid(); - } - - async getDataType() { - return await this._field.getDataType(); - } - - async getLabel() { - return await this._field.getLabel(); - } - - getOrigin() { - return this._origin; - } -} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index d65fc8c6e4c6a..709eade64622f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -7,7 +7,7 @@ import { AbstractESSource } from './es_source'; 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 } from '../../../common/constants'; +import { METRIC_TYPE, COUNT_AGG_TYPE, COUNT_PROP_LABEL, COUNT_PROP_NAME, FIELD_ORIGIN } from '../../../common/constants'; const AGG_DELIMITER = '_of_'; @@ -41,7 +41,8 @@ export class AbstractESAggSource extends AbstractESSource { label: metric.label, esDocField: esDocField, aggType: metric.type, - source: this + source: this, + origin: this.getOriginForField() }); }) : []; } @@ -61,7 +62,8 @@ export class AbstractESAggSource extends AbstractESSource { label: label, esDocField, aggType, - source: this + source: this, + origin: this.getOriginForField() }); } } @@ -72,6 +74,10 @@ export class AbstractESAggSource extends AbstractESSource { }); } + getOriginForField() { + return FIELD_ORIGIN.SOURCE; + } + getMetricFields() { const metrics = this._metricFields.filter(esAggField => esAggField.isValid()); if (metrics.length === 0) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index 5d13890096f0c..f765f7ff4d555 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -9,7 +9,7 @@ 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, METRIC_TYPE } from '../../../common/constants'; +import { ES_SIZE_LIMIT, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants'; import { ESDocField } from '../fields/es_doc_field'; import { AbstractESAggSource } from './es_agg_source'; @@ -77,6 +77,10 @@ export class ESTermSource extends AbstractESAggSource { return this._termField; } + getOriginForField() { + return FIELD_ORIGIN.JOIN; + } + getWhereQuery() { return this._descriptor.whereQuery; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index cd200ee2b5a07..2bab2bf8966fb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -77,7 +77,7 @@ export class VectorStyleEditor extends Component { return { label: await field.getLabel(), name: field.getName(), - origin: field.ggetOrigin() + origin: field.getOrigin() }; }); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 50296a99d9e57..85592a35ccf4a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -24,7 +24,6 @@ import { isRefreshOnlyQuery } from './util/is_refresh_only_query'; import { EuiIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { DataRequestAbortError } from './util/data_request'; -import { FieldWithOrigin } from './fields/field_with_origin'; const VISIBILITY_FILTER_CLAUSE = ['all', [ @@ -227,31 +226,16 @@ export class VectorLayer extends AbstractLayer { } async getDateFields() { - const timeFields = await this._source.getDateFields(); - return timeFields.map((field) => { - return new FieldWithOrigin({ field: field, origin: FIELD_ORIGIN.SOURCE }); - }); + return await this._source.getDateFields(); } async getNumberFields() { - const numberFields = await this._source.getNumberFields(); - const numberFieldOptions = numberFields.map(field => { - return new FieldWithOrigin({ - field: field, - origin: FIELD_ORIGIN.SOURCE - }); - }); + const numberFieldOptions = await this._source.getNumberFields(); const joinFields = []; this.getValidJoins().forEach(join => { - const fields = join.getJoinFields().map(joinField => { - return new FieldWithOrigin({ - field: joinField, - origin: FIELD_ORIGIN.JOIN - }); - }); + const fields = join.getJoinFields(); joinFields.push(...fields); }); - return [...numberFieldOptions, ...joinFields]; } @@ -518,7 +502,7 @@ export class VectorLayer extends AbstractLayer { _assignIdsToFeatures(featureCollection) { //wrt https://github.com/elastic/kibana/issues/39317 - // In constrained resource environments, mapbox-gl may throw a stackoverflow error due to hitting the browser's recursion limit. This crashes Kibana. + //In constrained resource environments, mapbox-gl may throw a stackoverflow error due to hitting the browser's recursion limit. This crashes Kibana. //This error is thrown in mapbox-gl's quicksort implementation, when it is sorting all the features by id. //This is a work-around to avoid hitting such a worst-case //This was tested as a suitable work-around for mapbox-gl 0.54 From ba63cfb2660013151e6d3399d10762f74833dd18 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 19 Nov 2019 10:00:34 -0500 Subject: [PATCH 100/112] remove style from layer constructor --- x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js | 8 ++++---- x-pack/legacy/plugins/maps/public/layers/layer.js | 3 +-- x-pack/legacy/plugins/maps/public/layers/tile_layer.js | 4 ---- .../plugins/maps/public/layers/vector_tile_layer.js | 4 ---- .../legacy/plugins/maps/public/selectors/map_selectors.js | 4 +--- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index 422c0d9c06683..0342975ce3192 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -22,13 +22,13 @@ export class HeatmapLayer extends VectorLayer { return heatmapLayerDescriptor; } - constructor({ layerDescriptor, source, style }) { - super({ layerDescriptor, source, style }); - if (!style) { + constructor({ layerDescriptor, source }) { + super({ layerDescriptor, source }); + if (!layerDescriptor.style) { const defaultStyle = HeatmapStyle.createDescriptor(); this._style = new HeatmapStyle(defaultStyle); } else { - this._style = style; + this._style = new HeatmapStyle(layerDescriptor.style); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index bc8b1efda63b6..72a89046ed2f5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -24,10 +24,9 @@ const NO_SOURCE_UPDATE_REQUIRED = false; export class AbstractLayer { - constructor({ layerDescriptor, source, style }) { + constructor({ layerDescriptor, source }) { this._descriptor = AbstractLayer.createDescriptor(layerDescriptor); this._source = source; - this._style = style; if (this._descriptor.__dataRequests) { this._dataRequests = this._descriptor.__dataRequests.map(dataRequest => new DataRequest(dataRequest)); } else { diff --git a/x-pack/legacy/plugins/maps/public/layers/tile_layer.js b/x-pack/legacy/plugins/maps/public/layers/tile_layer.js index 3dfe83ac83d02..70cfb6939e0d2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tile_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/tile_layer.js @@ -12,10 +12,6 @@ export class TileLayer extends AbstractLayer { static type = LAYER_TYPE.TILE; - constructor({ layerDescriptor, source, style }) { - super({ layerDescriptor, source, style }); - } - static createDescriptor(options) { const tileLayerDescriptor = super.createDescriptor(options); tileLayerDescriptor.type = TileLayer.type; diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js index d714ac3b092f6..7b7cf76cd365c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js @@ -25,10 +25,6 @@ export class VectorTileLayer extends TileLayer { static type = LAYER_TYPE.VECTOR_TILE; - constructor({ layerDescriptor, source, style }) { - super({ layerDescriptor, source, style }); - } - static createDescriptor(options) { const tileLayerDescriptor = super.createDescriptor(options); tileLayerDescriptor.type = VectorTileLayer.type; diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index c5e953fd4cd2f..8699d376d9d08 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -11,7 +11,6 @@ import { VectorTileLayer } from '../layers/vector_tile_layer'; import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; -import { HeatmapStyle } from '../layers/styles/heatmap/heatmap_style'; import { timefilter } from 'ui/timefilter'; import { getInspectorAdapters } from '../reducers/non_serializable_instances'; import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/util'; @@ -27,8 +26,7 @@ function createLayerInstance(layerDescriptor, inspectorAdapters) { case VectorTileLayer.type: return new VectorTileLayer({ layerDescriptor, source }); case HeatmapLayer.type: - const style = layerDescriptor.style ? new HeatmapStyle(layerDescriptor.style) : null; - return new HeatmapLayer({ layerDescriptor, source, style }); + return new HeatmapLayer({ layerDescriptor, source }); default: throw new Error(`Unrecognized layerType ${layerDescriptor.type}`); } From 9b5fce9f494e22aab3ef5720a2961ac5e266ef20 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 19 Nov 2019 11:30:01 -0500 Subject: [PATCH 101/112] feedback --- .../layer_panel/join_editor/resources/join.js | 4 +-- .../maps/public/layers/fields/es_agg_field.js | 3 +- .../public/layers/sources/es_agg_source.js | 28 ++++++++----------- .../es_pew_pew_source/es_pew_pew_source.js | 10 +++---- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js index 3733ac118fcf2..68d4656880666 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js @@ -112,13 +112,13 @@ export class Join extends Component { let leftFields; try { const leftFieldsInstances = await this.props.layer.getLeftJoinFields(); - leftFields = leftFieldsInstances.map(async (field) => { + const leftFieldPromises = leftFieldsInstances.map(async (field) => { return { name: field.getName(), label: await field.getLabel() }; }); - leftFields = await Promise.all(leftFields); + leftFields = await Promise.all(leftFieldPromises); } catch (error) { leftFields = []; } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 6cc4b075bae81..f9b471c64aa06 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -33,7 +33,7 @@ export class ESAggMetricField extends AbstractField { } isValid() { - return (this.getAggType() === COUNT_AGG_TYPE) ? true : !!this._esDocField; + return (this.getAggType() === COUNT_AGG_TYPE) ? true : !!this._esDocField; } getESDocFieldName() { @@ -69,5 +69,4 @@ export class ESAggMetricField extends AbstractField { } return metricAggConfig; } - } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 709eade64622f..de7b6d657958a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -54,18 +54,17 @@ export class AbstractESAggSource extends AbstractESSource { label: label, source: this }); - } else { - //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() - }); } + //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() + }); } getMetricFieldForName(fieldName) { @@ -124,12 +123,7 @@ export class AbstractESAggSource extends AbstractESSource { } } - const tooltipPromise = new Promise(async (resolve) => { - const tooltipProperty = await metricField.createTooltipProperty(value); - resolve(tooltipProperty); - }); - - + const tooltipPromise = metricField.createTooltipProperty(value); tooltipPropertiesPromises.push(tooltipPromise); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index c0282042043f9..01220136b14f3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -14,7 +14,7 @@ import { UpdateSourceEditor } from './update_source_editor'; import { VectorStyle } from '../../styles/vector/vector_style'; import { vectorStyles } from '../../styles/vector/vector_style_defaults'; import { i18n } from '@kbn/i18n'; -import { SOURCE_DATA_ID_ORIGIN, ES_PEW_PEW } from '../../../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN, ES_PEW_PEW, COUNT_PROP_NAME, COUNT_PROP_LABEL } from '../../../../common/constants'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { convertToLines } from './convert_to_lines'; import { Schemas } from 'ui/vis/editors/default/schemas'; @@ -128,8 +128,8 @@ export class ESPewPewSource extends AbstractESAggSource { type: DynamicStyleProperty.type, options: { field: { - label: AbstractESAggSource.COUNT_PROP_LABEL, - name: AbstractESAggSource.COUNT_PROP_NANE, + label: COUNT_PROP_LABEL, + name: COUNT_PROP_NAME, origin: SOURCE_DATA_ID_ORIGIN }, color: 'Blues' @@ -139,8 +139,8 @@ export class ESPewPewSource extends AbstractESAggSource { type: DynamicStyleProperty.type, options: { field: { - label: AbstractESAggSource.COUNT_PROP_LABEL, - name: AbstractESAggSource.COUNT_PROP_NANE, + label: COUNT_PROP_LABEL, + name: COUNT_PROP_NAME, origin: SOURCE_DATA_ID_ORIGIN }, minSize: 4, From 69a605cfa2f1086a56d01173ab1d5d77d9acc9fa Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 19 Nov 2019 13:25:31 -0500 Subject: [PATCH 102/112] feedback --- .../maps/public/layers/fields/es_agg_field.js | 4 ++-- .../sources/ems_file_source/ems_file_source.js | 5 +++-- .../sources/ems_file_source/update_source_editor.js | 4 +++- .../maps/public/layers/sources/es_agg_source.js | 7 ++++--- .../sources/es_search_source/update_source_editor.js | 8 ++++---- .../plugins/maps/public/layers/sources/es_source.js | 12 +++++++++++- .../maps/public/layers/sources/es_term_source.js | 6 +----- .../kibana_regionmap_source.js | 8 +++++--- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index f9b471c64aa06..22b6861e28b9e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -13,8 +13,8 @@ export class ESAggMetricField extends AbstractField { static type = 'ES_AGG'; - constructor({ label, source, aggType, esDocField }) { - super({ source }); + constructor({ label, source, aggType, esDocField, origin }) { + super({ source, origin }); this._label = label; this._aggType = aggType; this._esDocField = esDocField; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js index 46711e09b1a01..b2e04f56e5718 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js @@ -7,7 +7,7 @@ import { AbstractVectorSource } from '../vector_source'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import React from 'react'; -import { EMS_FILE, FEATURE_ID_PROPERTY_NAME } from '../../../../common/constants'; +import { EMS_FILE, FEATURE_ID_PROPERTY_NAME, FIELD_ORIGIN } from '../../../../common/constants'; import { getEMSClient } from '../../../meta'; import { EMSFileCreateSourceEditor } from './create_source_editor'; import { i18n } from '@kbn/i18n'; @@ -51,7 +51,8 @@ export class EMSFileSource extends AbstractVectorSource { createField({ fieldName }) { return new EMSFileField({ fieldName, - source: this + source: this, + origin: FIELD_ORIGIN.SOURCE }); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index 70c6a65044478..28be7f791e197 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -9,6 +9,7 @@ import PropTypes from 'prop-types'; import { TooltipSelector } from '../../../components/tooltip_selector'; import { getEMSClient } from '../../../meta'; import { EMSFileField } from '../../fields/ems_file_field'; +import { FIELD_ORIGIN } from '../../../../common/constants'; export class UpdateSourceEditor extends Component { @@ -40,7 +41,8 @@ export class UpdateSourceEditor extends Component { const emsFields = emsFile.getFieldsInLanguage(); fields = emsFields.map(field => new EMSFileField({ fieldName: field.name, - source: this.props.source + source: this.props.source, + origin: FIELD_ORIGIN.SOURCE })); } catch(e) { //swallow this error. when a matching EMS-config cannot be found, the source already will have thrown errors during the data request. This will propagate to the vector-layer and be displayed in the UX diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index de7b6d657958a..96d9fa6aed53f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -9,7 +9,6 @@ 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 class AbstractESAggSource extends AbstractESSource { @@ -52,7 +51,8 @@ export class AbstractESAggSource extends AbstractESSource { return new ESAggMetricField({ aggType: COUNT_AGG_TYPE, label: label, - source: this + source: this, + origin: this.getOriginForField() }); } //this only works because aggType is a fixed set and does not include the `_of_` string @@ -82,7 +82,8 @@ export class AbstractESAggSource extends AbstractESSource { if (metrics.length === 0) { metrics.push(new ESAggMetricField({ aggType: COUNT_AGG_TYPE, - source: this + source: this, + origin: this.getOriginForField() })); } return metrics; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index 01cc5ff644819..1b4e999c29d0a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -39,7 +39,7 @@ export class UpdateSourceEditor extends Component { }; state = { - tooltipFields: null, + sourceFields: null, termFields: null, sortFields: null, }; @@ -77,7 +77,7 @@ export class UpdateSourceEditor extends Component { //todo move this all to the source const rawTooltipFields = getSourceFields(indexPattern.fields); - const tooltipFields = rawTooltipFields.map(field => { + const sourceFields = rawTooltipFields.map(field => { return new ESDocField({ fieldName: field.name, source: this.props.source @@ -85,7 +85,7 @@ export class UpdateSourceEditor extends Component { }); this.setState({ - tooltipFields: tooltipFields, + sourceFields: sourceFields, termFields: getTermsFields(indexPattern.fields), //todo change term fields to use fields sortFields: indexPattern.fields.filter(field => field.sortable), //todo change sort fields to use fields }); @@ -186,7 +186,7 @@ export class UpdateSourceEditor extends Component {
diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 3d8c8d3102174..6d41fcb0e72dc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -17,7 +17,7 @@ import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; import { copyPersistentState } from '../../reducers/util'; -import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; +import { ES_GEO_FIELD_TYPE, METRIC_TYPE } from '../../../common/constants'; import { DataRequestAbortError } from '../util/data_request'; export class AbstractESSource extends AbstractVectorSource { @@ -245,6 +245,16 @@ export class AbstractESSource extends AbstractVectorSource { async getFieldFormatter(fieldName) { + + const metricField = this.getMetricFields().find(({ propertyKey }) => { + return propertyKey === fieldName; + }); + + // Do not use field formatters for counting metrics + if (metricField && metricField.type === METRIC_TYPE.COUNT || metricField.type === METRIC_TYPE.UNIQUE_COUNT) { + return null; + } + // fieldName could be an aggregation so it needs to be unpacked to expose raw field. const rawFieldName = this._getRawFieldName(fieldName); if (!rawFieldName) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js index f765f7ff4d555..afc402fa81bcb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js @@ -53,7 +53,7 @@ export class ESTermSource extends AbstractESAggSource { constructor(descriptor, inspectorAdapters) { super(descriptor, inspectorAdapters); - this._termField = new ESDocField({ fieldName: descriptor.term, source: this }); + this._termField = new ESDocField({ fieldName: descriptor.term, source: this, origin: this.getOriginForField() }); } static renderEditor({}) { @@ -61,10 +61,6 @@ export class ESTermSource extends AbstractESAggSource { return `
editor details
`; } - createField() { - throw new Error('Not implemented. Should retrieve corresponding field from the inner_join.metrics config.'); - } - hasCompleteConfig() { return (_.has(this._descriptor, 'indexPatternId') && _.has(this._descriptor, 'term')); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js index e38e62e7d4177..ffccb18a69192 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_source.js @@ -10,7 +10,7 @@ import { CreateSourceEditor } from './create_source_editor'; import { getKibanaRegionList } from '../../../meta'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; -import { FEATURE_ID_PROPERTY_NAME } from '../../../../common/constants'; +import { FEATURE_ID_PROPERTY_NAME, FIELD_ORIGIN } from '../../../../common/constants'; import { KibanaRegionField } from '../../fields/kibana_region_field'; export class KibanaRegionmapSource extends AbstractVectorSource { @@ -49,7 +49,8 @@ export class KibanaRegionmapSource extends AbstractVectorSource { createField({ fieldName }) { return new KibanaRegionField({ fieldName, - source: this + source: this, + origin: FIELD_ORIGIN.SOURCE }); } @@ -57,7 +58,8 @@ export class KibanaRegionmapSource extends AbstractVectorSource { return [ { label: getDataSourceLabel(), - value: KibanaRegionmapSource.title }, + value: KibanaRegionmapSource.title + }, { label: i18n.translate('xpack.maps.source.kbnRegionMap.vectorLayerLabel', { defaultMessage: 'Vector layer' From f51b2c18fec1ece8502ccd9d5b6c89194a3205bc Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 20 Nov 2019 12:07:09 -0500 Subject: [PATCH 103/112] feedback --- .../public/layers/sources/es_agg_source.js | 5 -- .../maps/public/layers/sources/es_source.js | 11 ++- .../public/layers/sources/vector_source.js | 1 + .../public/layers/styles/color_gradient.js | 27 ------- .../components/legend/heatmap_legend.js | 2 +- .../legend/style_property_legend_row.js | 72 ++----------------- .../properties/dynamic_size_property.js | 65 +++++++++++++++++ 7 files changed, 77 insertions(+), 106 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 96d9fa6aed53f..ecc882796b452 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -89,11 +89,6 @@ export class AbstractESAggSource extends AbstractESSource { return metrics; } - _getRawFieldName(fieldName) { - const metricField = this.getMetricFields().find((esAggMetricField) => esAggMetricField.getName() === fieldName); - return metricField ? metricField.getESDocFieldName() : null; - } - formatMetricKey(aggType, fieldName) { return aggType !== COUNT_AGG_TYPE ? `${aggType}${AGG_DELIMITER}${fieldName}` : COUNT_PROP_NAME; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 6d41fcb0e72dc..f48be377d3b5f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -69,11 +69,10 @@ export class AbstractESSource extends AbstractVectorSource { return clonedDescriptor; } - _getRawFieldName(fieldName) { - return fieldName; + getMetricFields() { + return []; } - async _runEsQuery(requestName, searchSource, registerCancelCallback, requestDescription) { const abortController = new AbortController(); registerCancelCallback(() => abortController.abort()); @@ -256,8 +255,8 @@ export class AbstractESSource extends AbstractVectorSource { } // fieldName could be an aggregation so it needs to be unpacked to expose raw field. - const rawFieldName = this._getRawFieldName(fieldName); - if (!rawFieldName) { + const realFieldName = metricField ? metricField.getESDocFieldName() : fieldName; + if (!realFieldName) { return null; } @@ -268,7 +267,7 @@ export class AbstractESSource extends AbstractVectorSource { return null; } - const fieldFromIndexPattern = indexPattern.fields.getByName(rawFieldName); + const fieldFromIndexPattern = indexPattern.fields.getByName(realFieldName); if (!fieldFromIndexPattern) { return null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index e8f0829cfd8b8..e255e2478a37d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -139,4 +139,5 @@ export class AbstractVectorSource extends AbstractSource { getSourceTooltipContent(/* sourceDataRequest */) { return { tooltipContent: null, areResultsTrimmed: false }; } + } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js b/x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js deleted file mode 100644 index d5a75586eb80a..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/styles/color_gradient.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 React from 'react'; -import { COLOR_RAMP_NAMES, getRGBColorRangeStrings, getLinearGradient } from './color_utils'; -import classNames from 'classnames'; - -export const ColorGradient = ({ colorRamp, colorRampName, className }) => { - if (!colorRamp && (!colorRampName || !COLOR_RAMP_NAMES.includes(colorRampName))) { - return null; - } - - const classes = classNames('mapColorGradient', className); - const rgbColorStrings = colorRampName - ? getRGBColorRangeStrings(colorRampName) - : colorRamp; - const background = getLinearGradient(rgbColorStrings); - return ( -
- ); -}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js index 2f8850ae70d80..bb10b7686ae3b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/components/legend/heatmap_legend.js @@ -36,7 +36,7 @@ export class HeatmapLegend extends React.Component { async _loadLabel() { const label = await this.props.field.getLabel(); - if (this.state.label !== label) { + if (this._isMounted && this.state.label !== label) { this.setState({ label }); } } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js index 0ff5506347d21..79b4cd8c018b3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -5,67 +5,12 @@ */ import _ from 'lodash'; -import React, { Component, Fragment } from 'react'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import { rangeShape } from '../style_option_shapes'; -import { CircleIcon } from './circle_icon'; import { getVectorStyleLabel } from '../get_vector_style_label'; -import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule } from '@elastic/eui'; import { StyleLegendRow } from '../../../components/style_legend_row'; -import { vectorStyles } from '../../vector_style_defaults'; - -function getLineWidthIcons() { - const defaultStyle = { - stroke: 'grey', - fill: 'none', - width: '12px', - }; - return [ - , - , - , - ]; -} - -function getSymbolSizeIcons() { - const defaultStyle = { - stroke: 'grey', - fill: 'grey', - }; - return [ - , - , - , - ]; -} - -function renderHeaderWithIcons(icons) { - return ( - - { - icons.map((icon, index) => { - const isLast = index === icons.length - 1; - let spacer; - if (!isLast) { - spacer = ( - - - - ); - } - return ( - - - {icon} - - {spacer} - - ); - }) - } - - ); -} const EMPTY_VALUE = ''; @@ -142,15 +87,7 @@ export class StylePropertyLegendRow extends Component { return null; } - let header; - if (style.getOptions().color) { - header = style.renderHeader(); - } else if (style.getStyleName() === vectorStyles.LINE_WIDTH) { - header = renderHeaderWithIcons(getLineWidthIcons()); - } else if (style.getStyleName() === vectorStyles.ICON_SIZE) { - header = renderHeaderWithIcons(getSymbolSizeIcons()); - } - + const header = style.renderHeader(); return ( , + , + , + ]; +} + +function getSymbolSizeIcons() { + const defaultStyle = { + stroke: 'grey', + fill: 'grey', + }; + return [ + , + , + , + ]; +} export class DynamicSizeProperty extends DynamicStyleProperty { @@ -84,4 +112,41 @@ export class DynamicSizeProperty extends DynamicStyleProperty { } return this._field.isValid() && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); } + + renderHeader() { + let icons; + if (this.getStyleName() === vectorStyles.LINE_WIDTH) { + icons = getLineWidthIcons(); + } else if (this.getStyleName() === vectorStyles.ICON_SIZE) { + icons = getSymbolSizeIcons(); + } else { + return null; + } + + return ( + + { + icons.map((icon, index) => { + const isLast = index === icons.length - 1; + let spacer; + if (!isLast) { + spacer = ( + + + + ); + } + return ( + + + {icon} + + {spacer} + + ); + }) + } + + ); + } } From 6bda091f84c063b17332c263a28ea1c9a11ebd03 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 20 Nov 2019 12:18:09 -0500 Subject: [PATCH 104/112] remove style options --- .../sources/ems_file_source/update_source_editor.js | 8 +------- .../styles/vector/components/style_option_shapes.js | 9 --------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index 28be7f791e197..46d4766ac03cc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -8,8 +8,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { TooltipSelector } from '../../../components/tooltip_selector'; import { getEMSClient } from '../../../meta'; -import { EMSFileField } from '../../fields/ems_file_field'; -import { FIELD_ORIGIN } from '../../../../common/constants'; export class UpdateSourceEditor extends Component { @@ -39,11 +37,7 @@ export class UpdateSourceEditor extends Component { const emsFiles = await emsClient.getFileLayers(); const emsFile = emsFiles.find((emsFile => emsFile.getId() === this.props.layerId)); const emsFields = emsFile.getFieldsInLanguage(); - fields = emsFields.map(field => new EMSFileField({ - fieldName: field.name, - source: this.props.source, - origin: FIELD_ORIGIN.SOURCE - })); + fields = emsFields.map(field => this.props.source.createField({ fieldName: field.name })); } catch(e) { //swallow this error. when a matching EMS-config cannot be found, the source already will have thrown errors during the data request. This will propagate to the vector-layer and be displayed in the UX fields = []; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js index d595dccaea425..a2edc8cb4f686 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/style_option_shapes.js @@ -36,15 +36,6 @@ export const dynamicSizeShape = PropTypes.shape({ field: fieldShape, }); -export const styleOptionShapes = [ - staticColorShape, - dynamicColorShape, - staticOrientationShape, - dynamicOrientationShape, - staticSizeShape, - dynamicSizeShape -]; - export const rangeShape = PropTypes.shape({ min: PropTypes.number.isRequired, max: PropTypes.number.isRequired, From 590498b630d11e0b2b47c7b81b15d1bee6772237 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 20 Nov 2019 15:53:21 -0500 Subject: [PATCH 105/112] feedback --- .../properties/dynamic_size_property.js | 5 +-- .../properties/dynamic_style_property.js | 2 +- .../vector/properties/style_property.js | 5 +-- .../layers/styles/vector/vector_style.js | 5 +-- .../maps/public/layers/vector_layer.js | 39 +++---------------- 5 files changed, 10 insertions(+), 46 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js index 6e496306a880a..bd011b27d81c8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.js @@ -107,10 +107,7 @@ export class DynamicSizeProperty extends DynamicStyleProperty { } _isSizeDynamicConfigComplete() { - if (!this._field) { - return false; - } - return this._field.isValid() && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); + return this._field && this._field.isValid() && _.has(this._options, 'minSize') && _.has(this._options, 'maxSize'); } renderHeader() { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 9ee4c3a1eb9bb..078c1c6edbfb2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -25,7 +25,7 @@ export class DynamicStyleProperty extends AbstractStyleProperty { } getFieldOrigin() { - return this._options.field.origin; + return this._field.getOrigin(); } supportsFeatureState() { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index 56b5765661ddf..bc95be2c8f3b2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -4,10 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ - - - - export class AbstractStyleProperty { constructor(options, styleName) { @@ -22,6 +18,7 @@ export class AbstractStyleProperty { getStyleName() { return this._styleName; } + getOptions() { return this._options || {}; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 8d4694b8359c2..36fba77e3a777 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { VectorStyleEditor } from './components/vector_style_editor'; import { getDefaultProperties, vectorStyles } from './vector_style_defaults'; import { AbstractStyle } from '../abstract_style'; -import { SOURCE_DATA_ID_ORIGIN, GEO_JSON_TYPE, FIELD_ORIGIN, STYLE_TYPE } from '../../../../common/constants'; +import { GEO_JSON_TYPE, FIELD_ORIGIN, STYLE_TYPE } from '../../../../common/constants'; import { VectorIcon } from './components/legend/vector_icon'; import { VectorStyleLegend } from './components/legend/vector_style_legend'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; @@ -53,7 +53,6 @@ export class VectorStyle extends AbstractStyle { static description = ''; - constructor(descriptor = {}, source, layer) { super(); this._source = source; @@ -236,7 +235,7 @@ export class VectorStyle extends AbstractStyle { getSourceFieldNames() { const fieldNames = []; this.getDynamicPropertiesArray().forEach(styleProperty => { - if (styleProperty.getFieldOrigin() === SOURCE_DATA_ID_ORIGIN) { + if (styleProperty.getFieldOrigin() === FIELD_ORIGIN.SOURCE) { fieldNames.push(styleProperty.getField().getName()); } }); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 85592a35ccf4a..362c7bfd72540 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -15,8 +15,7 @@ import { SOURCE_DATA_ID_ORIGIN, FEATURE_VISIBLE_PROPERTY_NAME, EMPTY_FEATURE_COLLECTION, - LAYER_TYPE, - FIELD_ORIGIN, + LAYER_TYPE } from '../../common/constants'; import _ from 'lodash'; import { JoinTooltipProperty } from './tooltips/join_tooltip_property'; @@ -241,8 +240,8 @@ export class VectorLayer extends AbstractLayer { async getOrdinalFields() { return [ - ... await this.getDateFields(), - ... await this.getNumberFields() + ...await this.getDateFields(), + ...await this.getNumberFields() ]; } @@ -353,7 +352,7 @@ export class VectorLayer extends AbstractLayer { const joinSource = join.getRightJoinSource(); const sourceDataId = join.getSourceId(); - const requestToken = Symbol(`layer-join-refresh:${ this.getId()} - ${sourceDataId}`); + const requestToken = Symbol(`layer-join-refresh:${this.getId()} - ${sourceDataId}`); const searchFilters = { ...dataFilters, @@ -465,7 +464,7 @@ export class VectorLayer extends AbstractLayer { startLoading, stopLoading, onLoadError, registerCancelCallback, dataFilters }) { - const requestToken = Symbol(`layer-source-refresh:${ this.getId()} - source`); + const requestToken = Symbol(`layer-source-refresh:${this.getId()} - source`); const searchFilters = this._getSearchFilters(dataFilters); const canSkip = await this._canSkipSourceUpdate(this._source, SOURCE_DATA_ID_ORIGIN, searchFilters); if (canSkip) { @@ -765,32 +764,4 @@ export class VectorLayer extends AbstractLayer { return feature.properties[FEATURE_ID_PROPERTY_NAME] === id; }); } - - _getFieldSource(field) { - if (!field) { - return null; - } - - if (field.origin === FIELD_ORIGIN.SOURCE) { - return this._source; - } else if (field.origin === FIELD_ORIGIN.JOIN) { - const join = this.getValidJoins().find(join => { - const matchingField = join.getJoinFields().find(joinField => { - return joinField.getName() === field.name; - }); - return !!matchingField; - }); - - if (!join) { - return null; - } - - return join.getRightJoinSource(); - } else { - return null; - } - - - } - } From 51a4107eb3a974af18d4d1433c475a65801524cf Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 20 Nov 2019 16:08:19 -0500 Subject: [PATCH 106/112] operator precedence madness --- x-pack/legacy/plugins/maps/public/layers/sources/es_source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index f48be377d3b5f..f57698daccbe5 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -250,7 +250,7 @@ export class AbstractESSource extends AbstractVectorSource { }); // Do not use field formatters for counting metrics - if (metricField && metricField.type === METRIC_TYPE.COUNT || metricField.type === METRIC_TYPE.UNIQUE_COUNT) { + if (metricField && (metricField.type === METRIC_TYPE.COUNT || metricField.type === METRIC_TYPE.UNIQUE_COUNT)) { return null; } From 35b460456d130b77df0c517bab09e0698150d2da Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 20 Nov 2019 16:38:37 -0500 Subject: [PATCH 107/112] feedback --- .../ems_file_source/update_source_editor.js | 4 --- .../maps/public/layers/sources/es_source.js | 2 -- .../vector/components/vector_style_editor.js | 25 ++++++------------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js index 46d4766ac03cc..f901c8b93e8cd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/update_source_editor.js @@ -54,10 +54,6 @@ export class UpdateSourceEditor extends Component { render() { - if (!this.state.fields) { - return null; - } - return ( { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 2bab2bf8966fb..c8e4150fd2c26 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -52,37 +52,26 @@ export class VectorStyleEditor extends Component { async _loadOrdinalFields() { - const dateFields = await this.props.layer.getDateFields(); - if (!this._isMounted) { - return; - } - const dateFieldPromises = dateFields.map(async (field) => { + const getFieldMeta = async (field) => { return { label: await field.getLabel(), name: field.getName(), origin: field.getOrigin() }; - }); + }; + const dateFields = await this.props.layer.getDateFields(); + const dateFieldPromises = dateFields.map(getFieldMeta); const dateFieldsArray = await Promise.all(dateFieldPromises); - if (!_.isEqual(dateFieldsArray, this.state.dateFields)) { + if (this._isMounted && !_.isEqual(dateFieldsArray, this.state.dateFields)) { this.setState({ dateFields: dateFieldsArray }); } const numberFields = await this.props.layer.getNumberFields(); - if (!this._isMounted) { - return; - } - const numberFieldPromises = numberFields.map(async (field) => { - return { - label: await field.getLabel(), - name: field.getName(), - origin: field.getOrigin() - }; - }); + const numberFieldPromises = numberFields.map(getFieldMeta); const numberFieldsArray = await Promise.all(numberFieldPromises); - if (!_.isEqual(numberFieldsArray, this.state.numberFields)) { + if (this._isMounted && !_.isEqual(numberFieldsArray, this.state.numberFields)) { this.setState({ numberFields: numberFieldsArray }); } From e7e79c1876fc044603c7a36aabda4bfa4f5a351d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 20 Nov 2019 16:43:47 -0500 Subject: [PATCH 108/112] remove cruft --- .../maps/public/layers/styles/vector/vector_style.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 36fba77e3a777..5c77a38d70b39 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -6,7 +6,6 @@ import _ from 'lodash'; import React from 'react'; -import { i18n } from '@kbn/i18n'; import { VectorStyleEditor } from './components/vector_style_editor'; import { getDefaultProperties, vectorStyles } from './vector_style_defaults'; import { AbstractStyle } from '../abstract_style'; @@ -45,14 +44,6 @@ export class VectorStyle extends AbstractStyle { return getDefaultProperties(mapColors); } - static getDisplayName() { - return i18n.translate('xpack.maps.style.vector.displayNameLabel', { - defaultMessage: 'Vector style' - }); - } - - static description = ''; - constructor(descriptor = {}, source, layer) { super(); this._source = source; From 8d97ff4dc81f64c28a6460c062694f0b6fc56a7b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 21 Nov 2019 09:51:22 -0500 Subject: [PATCH 109/112] remove dangling i18n translations --- x-pack/plugins/translations/translations/ja-JP.json | 1 - x-pack/plugins/translations/translations/zh-CN.json | 1 - 2 files changed, 2 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 8312ba3d0c83f..b19b313dd33e7 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6616,7 +6616,6 @@ "xpack.maps.source.wmsTitle": "ウェブマップサービス", "xpack.maps.style.heatmap.displayNameLabel": "ヒートマップスタイル", "xpack.maps.style.heatmap.resolutionStyleErrorMessage": "解像度パラメーターが認識されません: {resolution}", - "xpack.maps.style.vector.displayNameLabel": "ベクタースタイル", "xpack.maps.styles.staticDynamic.dynamicDescription": "プロパティ値で特徴をシンボル化します。", "xpack.maps.styles.staticDynamic.staticDescription": "静的スタイルプロパティで特徴をシンボル化します。", "xpack.maps.styles.vector.borderColorLabel": "境界線の色", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index f90d2f9522c31..e03a14f4a5b21 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6618,7 +6618,6 @@ "xpack.maps.source.wmsTitle": "Web 地图服务", "xpack.maps.style.heatmap.displayNameLabel": "热图样式", "xpack.maps.style.heatmap.resolutionStyleErrorMessage": "无法识别分辨率参数:{resolution}", - "xpack.maps.style.vector.displayNameLabel": "矢量样式", "xpack.maps.styles.staticDynamic.dynamicDescription": "使用属性值代表功能。", "xpack.maps.styles.staticDynamic.staticDescription": "使用静态样式属性代表功能。", "xpack.maps.styles.vector.borderColorLabel": "边框颜色", From b925c34fee534df6a68c9cc5e6a2b88b7bcb2660 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 21 Nov 2019 12:44:29 -0500 Subject: [PATCH 110/112] use custom label, if any --- .../plugins/maps/public/layers/fields/es_agg_field.js | 2 +- .../plugins/maps/public/layers/sources/es_agg_source.js | 9 +++++++++ .../maps/public/layers/styles/vector/vector_style.js | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js index 22b6861e28b9e..eb80169e94eab 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -25,7 +25,7 @@ export class ESAggMetricField extends AbstractField { } async getLabel() { - return this._label ? this._label : this._source.formatMetricLabel(this.getAggType(), this.getESDocFieldName()); + return this._label ? await this._label : this._source.formatMetricLabel(this.getAggType(), this.getESDocFieldName()); } getAggType() { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index ecc882796b452..fc28f4cf3a900 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -47,6 +47,15 @@ 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, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 5c77a38d70b39..099d12968799e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -448,10 +448,11 @@ export class VectorStyle extends AbstractStyle { return null; } + //fieldDescriptor.label is ignored. This is essentially cruft duplicating label-info from the metric-selection + //Ignore this custom label if (fieldDescriptor.origin === FIELD_ORIGIN.SOURCE) { return this._source.createField({ - fieldName: fieldDescriptor.name, - label: fieldDescriptor.label + fieldName: fieldDescriptor.name }); } else if (fieldDescriptor.origin === FIELD_ORIGIN.JOIN) { let matchingField = null; From 9ecaf763a76c530eaa4aa000fadf29d064b57a14 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 21 Nov 2019 14:07:35 -0500 Subject: [PATCH 111/112] improve naming --- .../components/legend/style_property_legend_row.js | 10 +++++----- .../styles/vector/properties/dynamic_style_property.js | 4 ++++ .../layers/styles/vector/properties/style_property.js | 10 ++++++++++ .../maps/public/layers/styles/vector/vector_style.js | 5 +++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js index 79b4cd8c018b3..35c7066b7fd0f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -39,7 +39,7 @@ export class StylePropertyLegendRow extends Component { } async _loadFieldFormatter() { - if (this.props.style.isDynamic() && this.props.style.getField() && this.props.style.getField().getSource()) { + if (this.props.style.isDynamic() && this.props.style.isComplete() && this.props.style.getField().getSource()) { const field = this.props.style.getField(); const source = field.getSource(); this._fieldValueFormatter = await source.getFieldFormatter(field.getName()); @@ -52,7 +52,7 @@ export class StylePropertyLegendRow extends Component { } _loadLabel = async () => { - if (this._isStatic()) { + if (this._excludeFromHeader()) { return; } @@ -68,8 +68,8 @@ export class StylePropertyLegendRow extends Component { } } - _isStatic() { - return !this.props.style.isDynamic() || !this.props.style.getField() || !this.props.style.getField().getName(); + _excludeFromHeader() { + return !this.props.style.isDynamic() || !this.props.style.isComplete() || !this.props.style.getField().getName(); } _formatValue = value => { @@ -83,7 +83,7 @@ export class StylePropertyLegendRow extends Component { render() { const { range, style } = this.props; - if (this._isStatic()) { + if (this._excludeFromHeader()) { return null; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js index 078c1c6edbfb2..e87bcc12c99be 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_style_property.js @@ -21,6 +21,10 @@ export class DynamicStyleProperty extends AbstractStyleProperty { } isDynamic() { + return true; + } + + isComplete() { return !!this._field; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js index bc95be2c8f3b2..9d182eac9fa8a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/style_property.js @@ -15,6 +15,16 @@ export class AbstractStyleProperty { return false; } + /** + * Is the style fully defined and usable? (e.g. for rendering, in legend UX, ...) + * Why? during editing, partially-completed descriptors may be added to the layer-descriptor + * e.g. dynamic-fields can have an incomplete state when the field is not yet selected from the drop-down + * @returns {boolean} + */ + isComplete() { + return true; + } + getStyleName() { return this._styleName; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 099d12968799e..2e2f10cc74935 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -239,7 +239,7 @@ export class VectorStyle extends AbstractStyle { getDynamicPropertiesArray() { const styleProperties = this._getAllStyleProperties(); - return styleProperties.filter(styleProperty => styleProperty.isDynamic()); + return styleProperties.filter(styleProperty => (styleProperty.isDynamic() && styleProperty.isComplete())); } _checkIfOnlyFeatureType = async (featureType) => { @@ -294,7 +294,8 @@ export class VectorStyle extends AbstractStyle { const styles = this._getAllStyleProperties(); const styleProperties = styles.map((style) => { return { - range: style.isDynamic() && style.getField() && style.getField().getName() ? this._getFieldRange(style.getField().getName()) : null, + // eslint-disable-next-line max-len + range: (style.isDynamic() && style.isComplete() && style.getField().getName()) ? this._getFieldRange(style.getField().getName()) : null, style: style }; }); From 1c50238121c2155ed6bc1bc93ebd0f402cd89d92 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 21 Nov 2019 14:57:25 -0500 Subject: [PATCH 112/112] fix field-formatter lookup --- x-pack/legacy/plugins/maps/public/layers/sources/es_source.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 1489a382205cc..c2f4f7e755288 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -243,9 +243,7 @@ export class AbstractESSource extends AbstractVectorSource { async getFieldFormatter(fieldName) { - const metricField = this.getMetricFields().find(({ propertyKey }) => { - return propertyKey === fieldName; - }); + const metricField = this.getMetricFields().find(field => field.getName() === fieldName); // Do not use field formatters for counting metrics if (metricField && (metricField.type === METRIC_TYPE.COUNT || metricField.type === METRIC_TYPE.UNIQUE_COUNT)) {