-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] fix unable to edit cluster vector styles styled by count when …
…switching to super fine grid resolution (#81525) * [Maps] fix unable to edit cluster vector styles styled by count when switching to super fine grid resolution * fix typo * tslint fixes * review feedback * more renames Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
ee7f16e
commit 0592938
Showing
6 changed files
with
182 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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 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
96 changes: 96 additions & 0 deletions
96
x-pack/plugins/maps/public/classes/styles/vector/style_fields_helper.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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 { | ||
CATEGORICAL_DATA_TYPES, | ||
FIELD_ORIGIN, | ||
ORDINAL_DATA_TYPES, | ||
VECTOR_STYLES, | ||
} from '../../../../common/constants'; | ||
import { IField } from '../../fields/field'; | ||
|
||
export interface StyleField { | ||
label: string; | ||
name: string; | ||
origin: FIELD_ORIGIN; | ||
type: string; | ||
supportsAutoDomain: boolean; | ||
} | ||
|
||
export async function createStyleFieldsHelper(fields: IField[]): Promise<StyleFieldsHelper> { | ||
const promises: Array<Promise<StyleField>> = fields.map(async (field: IField) => { | ||
return { | ||
label: await field.getLabel(), | ||
name: field.getName(), | ||
origin: field.getOrigin(), | ||
type: await field.getDataType(), | ||
supportsAutoDomain: field.supportsAutoDomain(), | ||
}; | ||
}); | ||
const styleFields = await Promise.all(promises); | ||
return new StyleFieldsHelper(styleFields); | ||
} | ||
|
||
class StyleFieldsHelper { | ||
private readonly _styleFields: StyleField[]; | ||
private readonly _ordinalAndCategoricalFields: StyleField[]; | ||
private readonly _numberFields: StyleField[]; | ||
private readonly _ordinalFields: StyleField[]; | ||
|
||
constructor(styleFields: StyleField[]) { | ||
const ordinalAndCategoricalFields: StyleField[] = []; | ||
const numberFields: StyleField[] = []; | ||
const ordinalFields: StyleField[] = []; | ||
|
||
styleFields.forEach((styleField: StyleField) => { | ||
if ( | ||
CATEGORICAL_DATA_TYPES.includes(styleField.type) || | ||
ORDINAL_DATA_TYPES.includes(styleField.type) | ||
) { | ||
ordinalAndCategoricalFields.push(styleField); | ||
} | ||
|
||
if (styleField.type === 'date' || styleField.type === 'number') { | ||
if (styleField.type === 'number') { | ||
numberFields.push(styleField); | ||
} | ||
if (styleField.supportsAutoDomain) { | ||
ordinalFields.push(styleField); | ||
} | ||
} | ||
}); | ||
|
||
this._styleFields = styleFields; | ||
this._ordinalAndCategoricalFields = ordinalAndCategoricalFields; | ||
this._numberFields = numberFields; | ||
this._ordinalFields = ordinalFields; | ||
} | ||
|
||
getFieldsForStyle(styleName: VECTOR_STYLES): StyleField[] { | ||
switch (styleName) { | ||
case VECTOR_STYLES.ICON_ORIENTATION: | ||
return this._numberFields; | ||
case VECTOR_STYLES.FILL_COLOR: | ||
case VECTOR_STYLES.LINE_COLOR: | ||
case VECTOR_STYLES.LABEL_COLOR: | ||
case VECTOR_STYLES.LABEL_BORDER_COLOR: | ||
case VECTOR_STYLES.ICON: | ||
return this._ordinalAndCategoricalFields; | ||
case VECTOR_STYLES.LINE_WIDTH: | ||
case VECTOR_STYLES.LABEL_SIZE: | ||
case VECTOR_STYLES.ICON_SIZE: | ||
return this._ordinalFields; | ||
case VECTOR_STYLES.LABEL_TEXT: | ||
return this._styleFields; | ||
default: | ||
return []; | ||
} | ||
} | ||
|
||
getStyleFields(): StyleField[] { | ||
return this._styleFields; | ||
} | ||
} |
Oops, something went wrong.