-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Maps] Add DynamicStyleProperty#getMbPropertyName and DynamicStyleProperty#getMbPropertyValue #77366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomasneirynck
merged 15 commits into
elastic:master
from
thomasneirynck:chore/reuse_mb_codepath
Sep 15, 2020
Merged
[Maps] Add DynamicStyleProperty#getMbPropertyName and DynamicStyleProperty#getMbPropertyValue #77366
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a7f25d6
init
thomasneirynck 092d4ef
remove comment
thomasneirynck ea382b9
use interface-methods
thomasneirynck 78502d4
add missing import
thomasneirynck f86f671
move getMbPropertyName to style for clarity
thomasneirynck e2414bd
remove duplicate implementation
thomasneirynck c70e99c
simplify
thomasneirynck 4d45113
type check
thomasneirynck 9b092a6
feedback
thomasneirynck 31a77f5
add clarifying comment
thomasneirynck c5ec78c
align types
thomasneirynck 0c0eb69
ts fixes
thomasneirynck 51b376e
reuse type
thomasneirynck d570f9a
isolate type
thomasneirynck cdbbc08
Merge branch 'master' of github.com:elastic/kibana into chore/reuse_m…
thomasneirynck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,9 @@ import { IField } from '../../../fields/field'; | |
| import { IVectorLayer } from '../../../layers/vector_layer/vector_layer'; | ||
| import { IJoin } from '../../../joins/join'; | ||
| import { IVectorStyle } from '../vector_style'; | ||
| import { getComputedFieldName } from '../style_util'; | ||
|
|
||
| export type RawValue = string | number | undefined | null; | ||
|
|
||
| export interface IDynamicStyleProperty<T> extends IStyleProperty<T> { | ||
| getFieldMetaOptions(): FieldMetaOptions; | ||
|
|
@@ -46,6 +49,15 @@ export interface IDynamicStyleProperty<T> extends IStyleProperty<T> { | |
| pluckOrdinalStyleMetaFromFeatures(features: Feature[]): RangeFieldMeta | null; | ||
| pluckCategoricalStyleMetaFromFeatures(features: Feature[]): CategoryFieldMeta | null; | ||
| getValueSuggestions(query: string): Promise<string[]>; | ||
|
|
||
| // Returns the name that should be used for accessing the data from the mb-style rule | ||
| // Depending on | ||
| // - whether the field is used for labeling, icon-orientation, or other properties (color, size, ...), `feature-state` and or `get` is used | ||
| // - whether the field was run through a field-formatter, a new dynamic field is created with the formatted-value | ||
| // The combination of both will inform what field-name (e.g. the "raw" field name from the properties, the "computed field-name" for an on-the-fly created property (e.g. for feature-state or field-formatting). | ||
| // todo: There is an existing limitation to .mvt backed sources, where the field-formatters are not applied. Here, the raw-data needs to be accessed. | ||
| getMbPropertyName(): string; | ||
| getMbPropertyValue(value: RawValue): RawValue; | ||
| } | ||
|
|
||
| export type FieldFormatter = (value: string | number | undefined) => string | number; | ||
|
|
@@ -313,11 +325,11 @@ export class DynamicStyleProperty<T> | |
| }; | ||
| } | ||
|
|
||
| formatField(value: string | number | undefined): string | number { | ||
| formatField(value: string | number | undefined | null): string | number { | ||
thomasneirynck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (this.getField()) { | ||
| const fieldName = this.getFieldName(); | ||
| const fieldFormatter = this._getFieldFormatter(fieldName); | ||
| return fieldFormatter ? fieldFormatter(value) : super.formatField(value); | ||
| return fieldFormatter && value !== null ? fieldFormatter(value) : super.formatField(value); | ||
|
||
| } else { | ||
| return super.formatField(value); | ||
| } | ||
|
|
@@ -345,4 +357,43 @@ export class DynamicStyleProperty<T> | |
| /> | ||
| ); | ||
| } | ||
|
|
||
| getMbPropertyName() { | ||
| if (!this._field) { | ||
| return ''; | ||
| } | ||
|
|
||
| let targetName; | ||
| if (this.supportsMbFeatureState()) { | ||
| // Base case for any properties that can support feature-state (e.g. color, size, ...) | ||
| // They just re-use the original property-name | ||
| targetName = this._field.getName(); | ||
| } else { | ||
| if (this._field.canReadFromGeoJson() && this._field.supportsAutoDomain()) { | ||
| // Geojson-sources can support rewrite | ||
| // e.g. field-formatters will create duplicate field | ||
| targetName = getComputedFieldName(this.getStyleName(), this._field.getName()); | ||
| } else { | ||
| // Non-geojson sources (e.g. 3rd party mvt or ES-source as mvt) | ||
| targetName = this._field.getName(); | ||
| } | ||
| } | ||
| return targetName; | ||
| } | ||
|
|
||
| getMbPropertyValue(rawValue: RawValue): RawValue { | ||
| // Maps only uses feature-state for numerical values. | ||
| // `supportsMbFeatureState` will only return true when the mb-style rule does a feature-state lookup on a numerical value | ||
| // Calling `isOrdinal` would be equivalent. | ||
| return this.supportsMbFeatureState() ? getNumericalMbFeatureStateValue(rawValue) : rawValue; | ||
thomasneirynck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| export function getNumericalMbFeatureStateValue(value: string | number | null | undefined) { | ||
thomasneirynck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (typeof value !== 'string') { | ||
| return value; | ||
| } | ||
|
|
||
| const valueAsFloat = parseFloat(value); | ||
| return isNaN(valueAsFloat) ? null : valueAsFloat; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.