diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index f0aa0ba2fdbe1..f03f828200bbd 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -119,3 +119,36 @@ export type VectorLayerDescriptor = LayerDescriptor & { joins?: JoinDescriptor[]; style?: unknown; }; + +export type RangeFieldMeta = { + min: number; + max: number; + delta: number; + isMinOutsideStdRange?: boolean; + isMaxOutsideStdRange?: boolean; +}; + +export type Category = { + key: string; + count: number; +}; + +export type CategoryFieldMeta = { + categories: Category[]; +}; + +export type GeometryTypes = { + isPointsOnly: boolean; + isLinesOnly: boolean; + isPolygonsOnly: boolean; +}; + +export type StyleMetaDescriptor = { + geometryTypes?: GeometryTypes; + fieldMeta: { + [key: string]: { + range: RangeFieldMeta; + categories: CategoryFieldMeta; + }; + }; +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/components/ordinal_legend.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/components/ordinal_legend.js index 564bae3ef3f72..1ebd042118480 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/components/ordinal_legend.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/components/ordinal_legend.js @@ -46,7 +46,7 @@ export class OrdinalLegend extends React.Component { this._loadParams(); } render() { - const fieldMeta = this.props.style.getFieldMeta(); + const fieldMeta = this.props.style.getRangeFieldMeta(); let minLabel = EMPTY_VALUE; let maxLabel = EMPTY_VALUE; 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 70e905907bc79..9404c2da3d274 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 @@ -169,7 +169,7 @@ export class DynamicColorProperty extends DynamicStyleProperty { }; } - const fieldMeta = this.getFieldMeta(); + const fieldMeta = this.getCategoryFieldMeta(); if (!fieldMeta || !fieldMeta.categories) { return EMPTY_STOPS; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js index 8648b073a7b79..c2f7a1313d02a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js @@ -16,7 +16,8 @@ import { shallow } from 'enzyme'; import { VECTOR_STYLES } from '../vector_style_defaults'; import { DynamicColorProperty } from './dynamic_color_property'; -import { COLOR_MAP_TYPE } from '../../../../../common/constants'; +import { StyleMeta } from '../style_meta'; +import { COLOR_MAP_TYPE, FIELD_ORIGIN } from '../../../../../common/constants'; const mockField = { async getLabel() { @@ -28,35 +29,59 @@ const mockField = { getRootName() { return 'foobar'; }, + getOrigin() { + return FIELD_ORIGIN.SOURCE; + }, supportsFieldMeta() { return true; }, }; -const getOrdinalFieldMeta = () => { - return { min: 0, max: 100 }; -}; - -const getCategoricalFieldMeta = () => { - return { - categories: [ - { - key: 'US', - count: 10, +class MockStyle { + getStyleMeta() { + return new StyleMeta({ + geometryTypes: { + isPointsOnly: false, + isLinesOnly: false, + isPolygonsOnly: false, }, - { - key: 'CN', - count: 8, + fieldMeta: { + foobar: { + range: { min: 0, max: 100 }, + categories: { + categories: [ + { + key: 'US', + count: 10, + }, + { + key: 'CN', + count: 8, + }, + ], + }, + }, }, - ], - }; -}; -const makeProperty = (options, getFieldMeta) => { + }); + } +} + +class MockLayer { + getStyle() { + return new MockStyle(); + } + + findDataRequestById() { + return null; + } +} + +const makeProperty = options => { return new DynamicColorProperty( options, VECTOR_STYLES.LINE_COLOR, mockField, - getFieldMeta, + new MockLayer(), () => { return x => x + '_format'; } @@ -69,13 +94,10 @@ const defaultLegendParams = { }; test('Should render ordinal legend', async () => { - const colorStyle = makeProperty( - { - color: 'Blues', - type: undefined, - }, - getOrdinalFieldMeta - ); + const colorStyle = makeProperty({ + color: 'Blues', + type: undefined, + }); const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams); @@ -85,23 +107,20 @@ test('Should render ordinal legend', async () => { }); test('Should render ordinal legend with breaks', async () => { - const colorStyle = makeProperty( - { - type: COLOR_MAP_TYPE.ORDINAL, - useCustomColorRamp: true, - customColorRamp: [ - { - stop: 0, - color: '#FF0000', - }, - { - stop: 10, - color: '#00FF00', - }, - ], - }, - getOrdinalFieldMeta - ); + const colorStyle = makeProperty({ + type: COLOR_MAP_TYPE.ORDINAL, + useCustomColorRamp: true, + customColorRamp: [ + { + stop: 0, + color: '#FF0000', + }, + { + stop: 10, + color: '#00FF00', + }, + ], + }); const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams); @@ -116,14 +135,11 @@ test('Should render ordinal legend with breaks', async () => { }); test('Should render categorical legend with breaks from default', async () => { - const colorStyle = makeProperty( - { - type: COLOR_MAP_TYPE.CATEGORICAL, - useCustomColorPalette: false, - colorCategory: 'palette_0', - }, - getCategoricalFieldMeta - ); + const colorStyle = makeProperty({ + type: COLOR_MAP_TYPE.CATEGORICAL, + useCustomColorPalette: false, + colorCategory: 'palette_0', + }); const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams); @@ -138,27 +154,24 @@ test('Should render categorical legend with breaks from default', async () => { }); test('Should render categorical legend with breaks from custom', async () => { - const colorStyle = makeProperty( - { - type: COLOR_MAP_TYPE.CATEGORICAL, - useCustomColorPalette: true, - customColorPalette: [ - { - stop: null, //should include the default stop - color: '#FFFF00', - }, - { - stop: 'US_STOP', - color: '#FF0000', - }, - { - stop: 'CN_STOP', - color: '#00FF00', - }, - ], - }, - getCategoricalFieldMeta - ); + const colorStyle = makeProperty({ + type: COLOR_MAP_TYPE.CATEGORICAL, + useCustomColorPalette: true, + customColorPalette: [ + { + stop: null, //should include the default stop + color: '#FFFF00', + }, + { + stop: 'US_STOP', + color: '#FF0000', + }, + { + stop: 'CN_STOP', + color: '#00FF00', + }, + ], + }); const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams); @@ -182,11 +195,10 @@ test('Should pluck the categorical style-meta', async () => { const colorStyle = makeProperty({ type: COLOR_MAP_TYPE.CATEGORICAL, colorCategory: 'palette_0', - getCategoricalFieldMeta, }); const features = makeFeatures(['CN', 'CN', 'US', 'CN', 'US', 'IN']); - const meta = colorStyle.pluckStyleMetaFromFeatures(features); + const meta = colorStyle.pluckCategoricalStyleMetaFromFeatures(features); expect(meta).toEqual({ categories: [ @@ -201,10 +213,9 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => { const colorStyle = makeProperty({ type: COLOR_MAP_TYPE.CATEGORICAL, colorCategory: 'palette_0', - getCategoricalFieldMeta, }); - const meta = colorStyle.pluckStyleMetaFromFieldMetaData({ + const meta = colorStyle.pluckCategoricalStyleMetaFromFieldMetaData({ foobar: { buckets: [ { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_icon_property.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_icon_property.js index c0e56f962db74..c492efbdf4ba3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_icon_property.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_icon_property.js @@ -62,7 +62,7 @@ export class DynamicIconProperty extends DynamicStyleProperty { } return assignCategoriesToPalette({ - categories: _.get(this.getFieldMeta(), 'categories', []), + categories: _.get(this.getCategoryFieldMeta(), 'categories', []), paletteValues: getIconPalette(this._options.iconPaletteId), }); } 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 dfc5c530cc90f..77f2d09982291 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 @@ -43,8 +43,8 @@ function getSymbolSizeIcons() { } export class DynamicSizeProperty extends DynamicStyleProperty { - constructor(options, styleName, field, getFieldMeta, getFieldFormatter, isSymbolizedAsIcon) { - super(options, styleName, field, getFieldMeta, getFieldFormatter); + constructor(options, styleName, field, vectorLayer, getFieldFormatter, isSymbolizedAsIcon) { + super(options, styleName, field, vectorLayer, getFieldFormatter); this._isSymbolizedAsIcon = isSymbolizedAsIcon; } 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 f33e723854cc2..7b94e58f0e7d4 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 @@ -7,7 +7,12 @@ import _ from 'lodash'; import { AbstractStyleProperty } from './style_property'; import { DEFAULT_SIGMA } from '../vector_style_defaults'; -import { COLOR_PALETTE_MAX_SIZE, STYLE_TYPE } from '../../../../../common/constants'; +import { + COLOR_PALETTE_MAX_SIZE, + STYLE_TYPE, + SOURCE_META_ID_ORIGIN, + FIELD_ORIGIN, +} from '../../../../../common/constants'; import { scaleValue, getComputedFieldName } from '../style_util'; import React from 'react'; import { OrdinalLegend } from './components/ordinal_legend'; @@ -17,10 +22,10 @@ import { OrdinalFieldMetaOptionsPopover } from '../components/ordinal_field_meta export class DynamicStyleProperty extends AbstractStyleProperty { static type = STYLE_TYPE.DYNAMIC; - constructor(options, styleName, field, getFieldMeta, getFieldFormatter) { + constructor(options, styleName, field, vectorLayer, getFieldFormatter) { super(options, styleName); this._field = field; - this._getFieldMeta = getFieldMeta; + this._layer = vectorLayer; this._getFieldFormatter = getFieldFormatter; } @@ -30,8 +35,57 @@ export class DynamicStyleProperty extends AbstractStyleProperty { return fieldSource && field ? fieldSource.getValueSuggestions(field, query) : []; }; - getFieldMeta() { - return this._getFieldMeta && this._field ? this._getFieldMeta(this._field.getName()) : null; + _getStyleMetaDataRequestId(fieldName) { + if (this.getFieldOrigin() === FIELD_ORIGIN.SOURCE) { + return SOURCE_META_ID_ORIGIN; + } + + const join = this._layer.getValidJoins().find(join => { + return join.getRightJoinSource().hasMatchingMetricField(fieldName); + }); + return join ? join.getSourceMetaDataRequestId() : null; + } + + getRangeFieldMeta() { + const style = this._layer.getStyle(); + const styleMeta = style.getStyleMeta(); + const fieldName = this.getFieldName(); + const rangeFieldMetaFromLocalFeatures = styleMeta.getRangeFieldMetaDescriptor(fieldName); + + const dataRequestId = this._getStyleMetaDataRequestId(fieldName); + if (!dataRequestId) { + return rangeFieldMetaFromLocalFeatures; + } + + const styleMetaDataRequest = this._layer.findDataRequestById(dataRequestId); + if (!styleMetaDataRequest || !styleMetaDataRequest.hasData()) { + return rangeFieldMetaFromLocalFeatures; + } + + const data = styleMetaDataRequest.getData(); + const rangeFieldMeta = this.pluckOrdinalStyleMetaFromFieldMetaData(data); + return rangeFieldMeta ? rangeFieldMeta : rangeFieldMetaFromLocalFeatures; + } + + getCategoryFieldMeta() { + const style = this._layer.getStyle(); + const styleMeta = style.getStyleMeta(); + const fieldName = this.getFieldName(); + const rangeFieldMetaFromLocalFeatures = styleMeta.getCategoryFieldMetaDescriptor(fieldName); + + const dataRequestId = this._getStyleMetaDataRequestId(fieldName); + if (!dataRequestId) { + return rangeFieldMetaFromLocalFeatures; + } + + const styleMetaDataRequest = this._layer.findDataRequestById(dataRequestId); + if (!styleMetaDataRequest || !styleMetaDataRequest.hasData()) { + return rangeFieldMetaFromLocalFeatures; + } + + const data = styleMetaDataRequest.getData(); + const rangeFieldMeta = this.pluckCategoricalStyleMetaFromFieldMetaData(data); + return rangeFieldMeta ? rangeFieldMeta : rangeFieldMetaFromLocalFeatures; } getField() { @@ -118,7 +172,11 @@ export class DynamicStyleProperty extends AbstractStyleProperty { return _.get(this.getOptions(), 'fieldMetaOptions', {}); } - _pluckOrdinalStyleMetaFromFeatures(features) { + pluckOrdinalStyleMetaFromFeatures(features) { + if (!this.isOrdinal()) { + return null; + } + const name = this.getField().getName(); let min = Infinity; let max = -Infinity; @@ -140,7 +198,11 @@ export class DynamicStyleProperty extends AbstractStyleProperty { }; } - _pluckCategoricalStyleMetaFromFeatures(features) { + pluckCategoricalStyleMetaFromFeatures(features) { + if (!this.isCategorical()) { + return null; + } + const fieldName = this.getField().getName(); const counts = new Map(); for (let i = 0; i < features.length; i++) { @@ -170,17 +232,11 @@ export class DynamicStyleProperty extends AbstractStyleProperty { }; } - pluckStyleMetaFromFeatures(features) { - if (this.isOrdinal()) { - return this._pluckOrdinalStyleMetaFromFeatures(features); - } else if (this.isCategorical()) { - return this._pluckCategoricalStyleMetaFromFeatures(features); - } else { + pluckOrdinalStyleMetaFromFieldMetaData(fieldMetaData) { + if (!this.isOrdinal()) { return null; } - } - _pluckOrdinalStyleMetaFromFieldMetaData(fieldMetaData) { const stats = fieldMetaData[this._field.getRootName()]; if (!stats) { return null; @@ -200,7 +256,11 @@ export class DynamicStyleProperty extends AbstractStyleProperty { }; } - _pluckCategoricalStyleMetaFromFieldMetaData(fieldMetaData) { + pluckCategoricalStyleMetaFromFieldMetaData(fieldMetaData) { + if (!this.isCategorical()) { + return null; + } + const rootFieldName = this._field.getRootName(); if (!fieldMetaData[rootFieldName] || !fieldMetaData[rootFieldName].buckets) { return null; @@ -217,16 +277,6 @@ export class DynamicStyleProperty extends AbstractStyleProperty { }; } - pluckStyleMetaFromFieldMetaData(fieldMetaData) { - if (this.isOrdinal()) { - return this._pluckOrdinalStyleMetaFromFieldMetaData(fieldMetaData); - } else if (this.isCategorical()) { - return this._pluckCategoricalStyleMetaFromFieldMetaData(fieldMetaData); - } else { - return null; - } - } - formatField(value) { if (this.getField()) { const fieldName = this.getField().getName(); @@ -244,7 +294,7 @@ export class DynamicStyleProperty extends AbstractStyleProperty { const valueAsFloat = parseFloat(value); if (this.isOrdinalScaled()) { - return scaleValue(valueAsFloat, this.getFieldMeta()); + return scaleValue(valueAsFloat, this.getRangeFieldMeta()); } if (isNaN(valueAsFloat)) { return 0; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts new file mode 100644 index 0000000000000..646b88d005af7 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts @@ -0,0 +1,42 @@ +/* + * 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 { + StyleMetaDescriptor, + RangeFieldMeta, + CategoryFieldMeta, +} from '../../../../common/descriptor_types'; + +export class StyleMeta { + private readonly _descriptor: StyleMetaDescriptor; + constructor(styleMetaDescriptor: StyleMetaDescriptor | null | undefined) { + this._descriptor = styleMetaDescriptor ? styleMetaDescriptor : { fieldMeta: {} }; + } + + getRangeFieldMetaDescriptor(fieldName: string): RangeFieldMeta | null { + return this._descriptor && this._descriptor.fieldMeta[fieldName] + ? this._descriptor.fieldMeta[fieldName].range + : null; + } + + getCategoryFieldMetaDescriptor(fieldName: string): CategoryFieldMeta | null { + return this._descriptor && this._descriptor.fieldMeta[fieldName] + ? this._descriptor.fieldMeta[fieldName].categories + : null; + } + + isPointsOnly(): boolean { + return this._descriptor.geometryTypes ? !!this._descriptor.geometryTypes.isPointsOnly : false; + } + + isLinesOnly(): boolean { + return this._descriptor.geometryTypes ? !!this._descriptor.geometryTypes.isLinesOnly : false; + } + + isPolygonsOnly(): boolean { + return this._descriptor.geometryTypes ? !!this._descriptor.geometryTypes.isPolygonsOnly : 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 053aa114d94ae..528c5a9bfdc85 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 @@ -18,11 +18,11 @@ import { GEO_JSON_TYPE, FIELD_ORIGIN, STYLE_TYPE, - SOURCE_META_ID_ORIGIN, SOURCE_FORMATTERS_ID_ORIGIN, LAYER_STYLE_TYPE, DEFAULT_ICON, } from '../../../../common/constants'; +import { StyleMeta } from './style_meta'; import { VectorIcon } from './components/legend/vector_icon'; import { VectorStyleLegend } from './components/legend/vector_style_legend'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; @@ -71,6 +71,8 @@ export class VectorStyle extends AbstractStyle { ...VectorStyle.createDescriptor(descriptor.properties, descriptor.isTimeAware), }; + this._styleMeta = new StyleMeta(this._descriptor.__styleMeta); + this._symbolizeAsStyleProperty = new SymbolizeAsProperty( this._descriptor.properties[VECTOR_STYLES.SYMBOLIZE_AS].options, VECTOR_STYLES.SYMBOLIZE_AS @@ -272,7 +274,7 @@ export class VectorStyle extends AbstractStyle { } } - const featuresMeta = { + const styleMeta = { geometryTypes: { isPointsOnly: isOnlySingleFeatureType( VECTOR_SHAPE_TYPES.POINT, @@ -290,23 +292,32 @@ export class VectorStyle extends AbstractStyle { hasFeatureType ), }, + fieldMeta: {}, }; const dynamicProperties = this.getDynamicPropertiesArray(); if (dynamicProperties.length === 0 || features.length === 0) { // no additional meta data to pull from source data request. - return featuresMeta; + return styleMeta; } dynamicProperties.forEach(dynamicProperty => { - const styleMeta = dynamicProperty.pluckStyleMetaFromFeatures(features); - if (styleMeta) { - const name = dynamicProperty.getField().getName(); - featuresMeta[name] = styleMeta; + const categoricalStyleMeta = dynamicProperty.pluckCategoricalStyleMetaFromFeatures(features); + const ordinalStyleMeta = dynamicProperty.pluckOrdinalStyleMetaFromFeatures(features); + const name = dynamicProperty.getField().getName(); + if (!styleMeta.fieldMeta[name]) { + styleMeta.fieldMeta[name] = {}; + } + if (categoricalStyleMeta) { + styleMeta.fieldMeta[name].categories = categoricalStyleMeta; + } + + if (ordinalStyleMeta) { + styleMeta.fieldMeta[name].range = ordinalStyleMeta; } }); - return featuresMeta; + return styleMeta; } getSourceFieldNames() { @@ -335,15 +346,15 @@ export class VectorStyle extends AbstractStyle { } _getIsPointsOnly = () => { - return _.get(this._getStyleMeta(), 'geometryTypes.isPointsOnly', false); + return this._styleMeta.isPointsOnly(); }; _getIsLinesOnly = () => { - return _.get(this._getStyleMeta(), 'geometryTypes.isLinesOnly', false); + return this._styleMeta.isLinesOnly(); }; _getIsPolygonsOnly = () => { - return _.get(this._getStyleMeta(), 'geometryTypes.isPolygonsOnly', false); + return this._styleMeta.isPolygonsOnly(); }; _getDynamicPropertyByFieldName(fieldName) { @@ -353,39 +364,9 @@ export class VectorStyle extends AbstractStyle { }); } - _getFieldMeta = fieldName => { - const fieldMetaFromLocalFeatures = _.get(this._descriptor, ['__styleMeta', fieldName]); - - const dynamicProp = this._getDynamicPropertyByFieldName(fieldName); - if (!dynamicProp || !dynamicProp.isFieldMetaEnabled()) { - return fieldMetaFromLocalFeatures; - } - - let dataRequestId; - if (dynamicProp.getFieldOrigin() === FIELD_ORIGIN.SOURCE) { - dataRequestId = SOURCE_META_ID_ORIGIN; - } else { - const join = this._layer.getValidJoins().find(join => { - return join.getRightJoinSource().hasMatchingMetricField(fieldName); - }); - if (join) { - dataRequestId = join.getSourceMetaDataRequestId(); - } - } - - if (!dataRequestId) { - return fieldMetaFromLocalFeatures; - } - - const styleMetaDataRequest = this._layer._findDataRequestById(dataRequestId); - if (!styleMetaDataRequest || !styleMetaDataRequest.hasData()) { - return fieldMetaFromLocalFeatures; - } - - const data = styleMetaDataRequest.getData(); - const fieldMeta = dynamicProp.pluckStyleMetaFromFieldMetaData(data); - return fieldMeta ? fieldMeta : fieldMetaFromLocalFeatures; - }; + getStyleMeta() { + return this._styleMeta; + } _getFieldFormatter = fieldName => { const dynamicProp = this._getDynamicPropertyByFieldName(fieldName); @@ -409,7 +390,7 @@ export class VectorStyle extends AbstractStyle { return null; } - const formattersDataRequest = this._layer._findDataRequestById(dataRequestId); + const formattersDataRequest = this._layer.findDataRequestById(dataRequestId); if (!formattersDataRequest || !formattersDataRequest.hasData()) { return null; } @@ -418,10 +399,6 @@ export class VectorStyle extends AbstractStyle { return formatters[fieldName]; }; - _getStyleMeta = () => { - return _.get(this._descriptor, '__styleMeta', {}); - }; - _getSymbolId() { return this.arePointsSymbolizedAsCircles() ? undefined @@ -623,7 +600,7 @@ export class VectorStyle extends AbstractStyle { descriptor.options, styleName, field, - this._getFieldMeta, + this._layer, this._getFieldFormatter, isSymbolizedAsIcon ); @@ -643,7 +620,7 @@ export class VectorStyle extends AbstractStyle { descriptor.options, styleName, field, - this._getFieldMeta, + this._layer, this._getFieldFormatter ); } else { @@ -658,7 +635,13 @@ export class VectorStyle extends AbstractStyle { return new StaticOrientationProperty(descriptor.options, styleName); } else if (descriptor.type === DynamicStyleProperty.type) { const field = this._makeField(descriptor.options.field); - return new DynamicOrientationProperty(descriptor.options, styleName, field); + return new DynamicOrientationProperty( + descriptor.options, + styleName, + field, + this._layer, + this._getFieldFormatter + ); } else { throw new Error(`${descriptor} not implemented`); } @@ -675,7 +658,7 @@ export class VectorStyle extends AbstractStyle { descriptor.options, VECTOR_STYLES.LABEL_TEXT, field, - this._getFieldMeta, + this._layer, this._getFieldFormatter ); } else { @@ -694,7 +677,7 @@ export class VectorStyle extends AbstractStyle { descriptor.options, VECTOR_STYLES.ICON, field, - this._getFieldMeta, + this._layer, this._getFieldFormatter ); } else { 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 cc52d44aed8d3..66b7ae5e02c5f 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 @@ -279,8 +279,8 @@ describe('pluckStyleMetaFromSourceDataRequest', () => { new MockSource() ); - const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); - expect(featuresMeta.myDynamicField).toEqual({ + const styleMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); + expect(styleMeta.fieldMeta.myDynamicField.range).toEqual({ delta: 9, max: 10, min: 1, 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 b03dfc38f3841..32fdbcf965414 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -61,6 +61,10 @@ export class VectorLayer extends AbstractLayer { this._style = new VectorStyle(this._descriptor.style, this._source, this); } + getStyle() { + return this._style; + } + destroy() { if (this._source) { this._source.destroy(); @@ -227,7 +231,7 @@ export class VectorLayer extends AbstractLayer { return indexPatternIds; } - _findDataRequestById(sourceDataId) { + findDataRequestById(sourceDataId) { return this._dataRequests.find(dataRequest => dataRequest.getDataId() === sourceDataId); } @@ -248,7 +252,7 @@ export class VectorLayer extends AbstractLayer { sourceQuery: joinSource.getWhereQuery(), applyGlobalQuery: joinSource.getApplyGlobalQuery(), }; - const prevDataRequest = this._findDataRequestById(sourceDataId); + const prevDataRequest = this.findDataRequestById(sourceDataId); const canSkipFetch = await canSkipSourceUpdate({ source: joinSource, @@ -471,7 +475,7 @@ export class VectorLayer extends AbstractLayer { isTimeAware: this._style.isTimeAware() && (await source.isTimeAware()), timeFilters: dataFilters.timeFilters, }; - const prevDataRequest = this._findDataRequestById(dataRequestId); + const prevDataRequest = this.findDataRequestById(dataRequestId); const canSkipFetch = canSkipStyleMetaUpdate({ prevDataRequest, nextMeta }); if (canSkipFetch) { return; @@ -547,7 +551,7 @@ export class VectorLayer extends AbstractLayer { const nextMeta = { fieldNames: _.uniq(fieldNames).sort(), }; - const prevDataRequest = this._findDataRequestById(dataRequestId); + const prevDataRequest = this.findDataRequestById(dataRequestId); const canSkipUpdate = canSkipFormattersUpdate({ prevDataRequest, nextMeta }); if (canSkipUpdate) { return;