From 5eda3bfedb20cb884f09804b51e9a75826645042 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 18 Feb 2020 15:29:17 -0500 Subject: [PATCH 1/6] boilerplate --- .../components/color/color_map_select.js | 59 ++++++++++++-- .../components/color/dynamic_color_form.js | 76 ++++++++++++++----- .../properties/dynamic_color_property.test.js | 27 +++++++ 3 files changed, 135 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index e8d5754ef4206..8d487fe7f5e20 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -6,10 +6,11 @@ import React, { Component, Fragment } from 'react'; -import { EuiSuperSelect, EuiSpacer } from '@elastic/eui'; +import { EuiSuperSelect, EuiSpacer, EuiSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ColorStopsOrdinal } from './color_stops_ordinal'; import { COLOR_MAP_TYPE } from '../../../../../../common/constants'; import { ColorStopsCategorical } from './color_stops_categorical'; +import { i18n } from '@kbn/i18n'; const CUSTOM_COLOR_MAP = 'CUSTOM_COLOR_MAP'; @@ -27,6 +28,45 @@ export class ColorMapSelect extends Component { }; } + _renderColorMapToggle() { + if (!this.props.showColorMapTypeToggle) { + return null; + } + const options = [ + { + value: COLOR_MAP_TYPE.ORDINAL, + text: i18n.translate('xpack.maps.styles.dynamicColorSelect.quantitativeLabel', { + defaultMessage: 'Quantitative', + }), + }, + { + value: COLOR_MAP_TYPE.CATEGORICAL, + text: i18n.translate('xpack.maps.styles.dynamicColorSelect.qualitativeLavel', { + defaultMessage: 'Qualitative', + }), + }, + ]; + + const selectedValue = this.props.styleProperty.isOrdinal() + ? COLOR_MAP_TYPE.ORDINAL + : COLOR_MAP_TYPE.CATEGORICAL; + + return ( + + ); + } + _onColorMapSelect = selectedValue => { const useCustomColorMap = selectedValue === CUSTOM_COLOR_MAP; this.props.onChange({ @@ -100,12 +140,17 @@ export class ColorMapSelect extends Component { return ( - + + {this._renderColorMapToggle()} + + + + {this._renderColorStopsInput()} ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js index af5e5b37f5467..04ba358fb7bf3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js @@ -13,6 +13,12 @@ import { CATEGORICAL_DATA_TYPES, COLOR_MAP_TYPE } from '../../../../../../common import { COLOR_GRADIENTS, COLOR_PALETTES } from '../../../color_utils'; import { i18n } from '@kbn/i18n'; +function getDefaultColorMapType(fieldType) { + return CATEGORICAL_DATA_TYPES.includes(fieldType) + ? COLOR_MAP_TYPE.CATEGORICAL + : COLOR_MAP_TYPE.ORDINAL; +} + export function DynamicColorForm({ fields, onDynamicStyleChange, @@ -40,21 +46,47 @@ export function DynamicColorForm({ }; const onFieldChange = async ({ field }) => { - const { name, origin, type } = field; + const { name, origin, type: fieldType } = field; + const defaultColorMapType = getDefaultColorMapType(fieldType); onDynamicStyleChange(styleProperty.getStyleName(), { ...styleOptions, field: { name, origin }, - type: CATEGORICAL_DATA_TYPES.includes(type) - ? COLOR_MAP_TYPE.CATEGORICAL - : COLOR_MAP_TYPE.ORDINAL, + type: defaultColorMapType, + }); + }; + + const onColorMapTypeChange = async e => { + const colorMapType = e.target.value; + onDynamicStyleChange(styleProperty.getStyleName(), { + ...styleOptions, + type: colorMapType, + }); + }; + + const getField = () => { + const fieldName = styleProperty.getFieldName(); + if (!fieldName) { + return null; + } + + return fields.find(field => { + return field.name === fieldName; }); }; const renderColorMapSelect = () => { - if (!styleOptions.field || !styleOptions.field.name) { + // if (!styleOptions.field || !styleOptions.field.name) { + // return null; + // } + + const field = getField(); + + if (!field) { return null; } + const showColorMapTypeToggle = !CATEGORICAL_DATA_TYPES.includes(field.type); + if (styleProperty.isOrdinal()) { return ( + ); + } else if (styleProperty.isCategorical()) { + return ( + ); } - - return ( - - ); }; return ( 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 6b08fc2a105c3..7a03d8a7bed20 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 @@ -222,3 +222,30 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => { ], }); }); + +test('Should read out ordinal/categorical correctly', async () => { + const categoricalColorStyle = makeProperty({ + type: COLOR_MAP_TYPE.CATEGORICAL, + colorCategory: 'palette_0', + getCategoricalFieldMeta, + }); + + expect(categoricalColorStyle.isOrdinal()).toEqual(false); + expect(categoricalColorStyle.isCategorical()).toEqual(true); + + const ordinalColorStyle = makeProperty({ + type: undefined, + color: 'Blues', + }); + + expect(ordinalColorStyle.isOrdinal()).toEqual(true); + expect(ordinalColorStyle.isCategorical()).toEqual(false); + + const ordinalColorStyle2 = makeProperty({ + type: COLOR_MAP_TYPE.ORDINAL, + colorCategory: 'palette_0', + }); + + expect(ordinalColorStyle2.isOrdinal()).toEqual(true); + expect(ordinalColorStyle2.isCategorical()).toEqual(false); +}); From 4d0dde5ed9444c99d990661ff8eeec5350b76540 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 18 Feb 2020 16:20:26 -0500 Subject: [PATCH 2/6] styling --- .../components/color/color_map_select.js | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 8d487fe7f5e20..3a40ac0ffc3d4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; -import { EuiSuperSelect, EuiSpacer, EuiSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { EuiSpacer, EuiSelect, EuiSuperSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ColorStopsOrdinal } from './color_stops_ordinal'; import { COLOR_MAP_TYPE } from '../../../../../../common/constants'; import { ColorStopsCategorical } from './color_stops_categorical'; @@ -29,9 +29,6 @@ export class ColorMapSelect extends Component { } _renderColorMapToggle() { - if (!this.props.showColorMapTypeToggle) { - return null; - } const options = [ { value: COLOR_MAP_TYPE.ORDINAL, @@ -91,10 +88,6 @@ export class ColorMapSelect extends Component { }; _renderColorStopsInput() { - if (!this.props.useCustomColorMap) { - return null; - } - if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { return ( @@ -120,7 +113,7 @@ export class ColorMapSelect extends Component { ); } - render() { + _renderColorMapSelections() { const colorMapOptionsWithCustom = [ { value: CUSTOM_COLOR_MAP, @@ -138,20 +131,43 @@ export class ColorMapSelect extends Component { : ''; } + let toggle; + if (this.props.showColorMapTypeToggle) { + toggle = {this._renderColorMapToggle()}; + } else { + toggle = ; + } + return ( - - {this._renderColorMapToggle()} + {toggle} + + + + + ); + } + + render() { + return ( + + + + + {this._renderColorMapSelections()} + + - + + {this._renderColorStopsInput()} + - {this._renderColorStopsInput()} ); } From 8adb584ddc3397e70dbc614cfdf376025d42e88c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 18 Feb 2020 16:23:58 -0500 Subject: [PATCH 3/6] fix --- .../layers/styles/vector/components/color/color_map_select.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 3a40ac0ffc3d4..cd5a799f27128 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -88,6 +88,10 @@ export class ColorMapSelect extends Component { }; _renderColorStopsInput() { + if (!this.props.useCustomColorMap) { + return null; + } + if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { return ( From 69de1b826d00b8df5564bdd4e6d78e8ece067aca Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 20 Feb 2020 11:39:28 -0500 Subject: [PATCH 4/6] remove cruft --- .../styles/vector/components/color/dynamic_color_form.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js index 04ba358fb7bf3..1d53fc05f9dec 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js @@ -75,12 +75,7 @@ export function DynamicColorForm({ }; const renderColorMapSelect = () => { - // if (!styleOptions.field || !styleOptions.field.name) { - // return null; - // } - const field = getField(); - if (!field) { return null; } From c96a65e5e2a367a6be22670509489b63cd1c4271 Mon Sep 17 00:00:00 2001 From: miukimiu Date: Thu, 20 Feb 2020 16:56:30 +0000 Subject: [PATCH 5/6] Improving color map select styles --- .../components/color/color_map_select.js | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 3a40ac0ffc3d4..c87a3e22f0c10 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -90,26 +90,20 @@ export class ColorMapSelect extends Component { _renderColorStopsInput() { if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { return ( - - - - + ); } return ( - - - - + ); } @@ -133,40 +127,36 @@ export class ColorMapSelect extends Component { let toggle; if (this.props.showColorMapTypeToggle) { - toggle = {this._renderColorMapToggle()}; + toggle = {this._renderColorMapToggle()}; } else { toggle = ; } return ( - + {toggle} - + ); } render() { return ( - - - - {this._renderColorMapSelections()} - - - - - {this._renderColorStopsInput()} - - + {this._renderColorMapSelections()} + + + + + {this._renderColorStopsInput()} ); From 64c865027ee00241ef500f97a8010b06ab8411ee Mon Sep 17 00:00:00 2001 From: miukimiu Date: Fri, 21 Feb 2020 19:12:12 +0000 Subject: [PATCH 6/6] Improving styles --- .../layer_panel/_index.scss | 3 +- .../style_settings/_style_settings.scss | 3 ++ .../style_settings/style_settings.js | 2 +- .../vector/components/color/_color_stops.scss | 21 --------- .../components/color/color_map_select.js | 8 +++- .../vector/components/color/color_stops.js | 44 ++++++++++++------- .../components/color/dynamic_color_form.js | 6 ++- .../components/color/static_color_form.js | 6 ++- .../components/label/dynamic_label_form.js | 6 ++- .../components/label/static_label_form.js | 6 ++- .../orientation/dynamic_orientation_form.js | 6 ++- .../orientation/static_orientation_form.js | 6 ++- .../components/size/dynamic_size_form.js | 6 ++- .../components/size/static_size_form.js | 6 ++- .../vector/components/style_prop_editor.js | 6 ++- .../components/symbol/dynamic_icon_form.js | 6 ++- .../vector/components/symbol/icon_select.js | 1 + .../components/symbol/static_icon_form.js | 6 ++- 18 files changed, 85 insertions(+), 63 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/_style_settings.scss diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/_index.scss b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/_index.scss index b219f59476ce9..fd074edf032fa 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/_index.scss +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/_index.scss @@ -1,3 +1,4 @@ @import './layer_panel'; @import './filter_editor/filter_editor'; -@import './join_editor/resources/join'; \ No newline at end of file +@import './join_editor/resources/join'; +@import './style_settings/style_settings'; \ No newline at end of file diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/_style_settings.scss b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/_style_settings.scss new file mode 100644 index 0000000000000..c671368552440 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/_style_settings.scss @@ -0,0 +1,3 @@ +.mapStyleSettings__fixedBox { + width: 120px; +} \ No newline at end of file diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/style_settings.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/style_settings.js index 2857065f04c70..69cf51fb29c0d 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/style_settings.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/style_settings/style_settings.js @@ -21,7 +21,7 @@ export function StyleSettings({ layer, updateStyleDescriptor }) { return ( - + 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 index 001ca0685d0e9..519e97f4b30cd 100644 --- 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 @@ -1,6 +1,5 @@ .mapColorStop { position: relative; - padding-right: $euiSizeXL + $euiSizeS; & + & { margin-top: $euiSizeS; @@ -17,23 +16,3 @@ } } -.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_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index eb6bb35cc0c14..f71bd52210cd7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -131,13 +131,17 @@ export class ColorMapSelect extends Component { let toggle; if (this.props.showColorMapTypeToggle) { - toggle = {this._renderColorMapToggle()}; + toggle = ( + + {this._renderColorMapToggle()} + + ); } else { toggle = ; } return ( - + {toggle} + {deleteButton} + + + ); return ( -
- - {stopInput} - {colorInput} - -
- {deleteButton} - + + {stopInput} + + + -
-
+
+
); } @@ -87,7 +96,10 @@ export const ColorStops = ({ defaultMessage: 'Color must provide a valid hex value', }) : undefined, - colorInput: , + colorInput: { + onColorChange: onColorChange, + color: color, + }, }; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js index 1d53fc05f9dec..673f84c04bd4c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js @@ -121,8 +121,10 @@ export function DynamicColorForm({ return ( - - {staticDynamicSelect} + + + {staticDynamicSelect} + - {staticDynamicSelect} + + + {staticDynamicSelect} + - {staticDynamicSelect} + + + {staticDynamicSelect} + - {staticDynamicSelect} + + + {staticDynamicSelect} + - {staticDynamicSelect} + + + {staticDynamicSelect} + - {staticDynamicSelect} + + + {staticDynamicSelect} + - - {staticDynamicSelect} + + + {staticDynamicSelect} + - {staticDynamicSelect} + + + {staticDynamicSelect} + - - {staticDynamicSelect} + + + {staticDynamicSelect} + diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/dynamic_icon_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/dynamic_icon_form.js index afa11daf45217..9065102dc8bd7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/dynamic_icon_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/dynamic_icon_form.js @@ -53,8 +53,10 @@ export function DynamicIconForm({ return ( - - {staticDynamicSelect} + + + {staticDynamicSelect} + {this._renderIconSelectable()} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/static_icon_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/static_icon_form.js index b20d8f2eba162..9b00b2fe38d7b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/static_icon_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/static_icon_form.js @@ -20,8 +20,10 @@ export function StaticIconForm({ }; return ( - - {staticDynamicSelect} + + + {staticDynamicSelect} +