Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[feat] Text layer: add outline width, outline color, background color (#2342)
Igor Dykhta4383bffdfaf0
diff --git a/src/actions/src/vis-state-actions.ts b/src/actions/src/vis-state-actions.tsindex c82a5e437..c830d1d74 100644--- a/src/actions/src/vis-state-actions.ts+++ b/src/actions/src/vis-state-actions.ts@@ -101,7 +101,7 @@ export type LayerTextLabelChangeUpdaterAction = {* Update layer text label* @param oldLayer - layer to be updated* @param idx -`idx` of text label to be updated- * @param prop - `prop` of text label, e,g, `anchor`, `alignment`, `color`, `size`, `field`+ * @param prop - `prop` of text label, e,g, `anchor`, `alignment`, `color`, `size`, `field`, `outlineWidth`, `outlineColor`* @param value - new value* @returns action* @publicdiff --git a/src/components/src/index.ts b/src/components/src/index.tsindex 259a8f995..bd18ae20a 100644--- a/src/components/src/index.ts+++ b/src/components/src/index.ts@@ -33,6 +33,12 @@ import FieldSelectorFactory, {FieldListItemFactoryFactory} from './common/field-import FieldTokenFactory from './common/field-token';import PanelHeaderActionFactory from './side-panel/panel-header-action';import InfoHelperFactory from './common/info-helper';+import ColorSelectorFactory from './side-panel/layer-panel/color-selector';+import {+ LayerColorSelectorFactory,+ LayerColorRangeSelectorFactory,+ ArcLayerColorSelectorFactory+} from './side-panel/layer-panel/layer-color-selector';import {appInjector} from './container';// Components@@ -66,7 +72,7 @@ export {default as PanelToggleFactory} from './side-panel/panel-toggle';export {default as PanelTabFactory} from './side-panel/panel-tab';export {default as LayerManagerFactory} from './side-panel/layer-manager';-export {default as ColorSelector, ColorSelectorInput, ColorBlock} from './side-panel/layer-panel/color-selector';+export {ColorSelectorInput, ColorBlock} from './side-panel/layer-panel/color-selector';export {default as CustomSelector} from './side-panel/layer-panel/color-selector';export {default as ColorPalette} from './side-panel/layer-panel/color-palette';export {default as ColorRangeSelector, PaletteConfig, ColorPaletteGroup, ALL_TYPES} from './side-panel/layer-panel/color-range-selector';@@ -74,12 +80,9 @@ export {default as LayerPanelFactory} from './side-panel/layer-panel/layer-panelexport {default as SingleColorPalette} from './side-panel/layer-panel/single-color-palette';export {default as LayerConfiguratorFactory,- LayerColorRangeSelector,getLayerConfiguratorProps,getLayerDataset,getVisConfiguratorProps,- ArcLayerColorSelector,- LayerColorSelector} from './side-panel/layer-panel/layer-configurator';export {default as TextLabelPanelFactory} from './side-panel/layer-panel/text-label-panel';@@ -352,6 +355,10 @@ export const PanelHeaderAction = appInjector.get(PanelHeaderActionFactory);export const FieldListItemFactory = appInjector.get(FieldListItemFactoryFactory);export const LayerTypeListItem = appInjector.get(LayerTypeListItemFactory);export const InfoHelper = appInjector.get(InfoHelperFactory);+export const ColorSelector = appInjector.get(ColorSelectorFactory);+export const LayerColorSelector = appInjector.get(LayerColorSelectorFactory);+export const LayerColorRangeSelector = appInjector.get(LayerColorRangeSelectorFactory);+export const ArcLayerColorSelector = appInjector.get(ArcLayerColorSelectorFactory);export {appInjector,TimeRangeSliderFactory,@@ -363,5 +370,9 @@ export {LayerTypeListItemFactory,ChannelByValueSelectorFactory,FieldListItemFactoryFactory,- InfoHelperFactory+ InfoHelperFactory,+ ColorSelectorFactory,+ LayerColorSelectorFactory,+ LayerColorRangeSelectorFactory,+ ArcLayerColorSelectorFactory};diff --git a/src/components/src/side-panel/layer-panel/color-selector.tsx b/src/components/src/side-panel/layer-panel/color-selector.tsxindex 260f4b51b..3e06c09f4 100644--- a/src/components/src/side-panel/layer-panel/color-selector.tsx+++ b/src/components/src/side-panel/layer-panel/color-selector.tsx@@ -18,16 +18,18 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {Component, createRef, MouseEvent} from 'react';+import React, {Component, createRef, MouseEvent, ComponentType} from 'react';import styled from 'styled-components';+import {FormattedMessage} from 'react-intl';import {rgbToHex} from '@kepler.gl/utils';import SingleColorPalette from './single-color-palette';import ColorRangeSelector from './color-range-selector';import ColorPalette from './color-palette';-import {StyledPanelDropdown} from '../../common/styled-components';+import {StyledPanelDropdown, PanelLabel} from '../../common/styled-components';import onClickOutside from 'react-onclickoutside';import {ColorRange} from '@kepler.gl/constants';-import {NestedPartial, RGBColor, ColorUI} from '@kepler.gl/types';+import RangeSliderFactory from '../../common/range-slider';+import {NestedPartial, RGBColor, RGBAColor, ColorUI} from '@kepler.gl/types';type ColorSelectorInputProps = {active: boolean;@@ -35,19 +37,36 @@ type ColorSelectorInputProps = {inputTheme?: string;};+export type ColorSet = {+ selectedColor: RGBColor | RGBAColor | ColorRange;+ setColor: (v: RGBColor | RGBAColor | ColorRange) => void;+ isRange?: boolean;+ label?: string;+};+type ColorSelectorProps = {- colorSets: {- selectedColor: RGBColor | ColorRange;- setColor: ((v: RGBColor) => void) | ((v: ColorRange) => void);- isRange?: boolean;- label?: string;- }[];+ colorSets: ColorSet[];colorUI?: ColorUI;inputTheme?: string;disabled?: boolean;+ useOpacity?: boolean;setColorUI?: (newConfig: NestedPartial<ColorUI>) => void;};+const OpacitySliderWrapper = styled.div`+ padding: 0px 12px 12px 12px;+`;++const OPACITY_SLIDER_PROPS = {+ type: 'number',+ range: [0, 1],+ value0: 0,+ step: 0.01,+ isRanged: false,+ label: 'Opacity',+ showInput: true+};+export const ColorBlock = styled.div<{backgroundcolor: RGBColor}>`width: 32px;height: 18px;@@ -82,118 +101,150 @@ export const InputBoxContainer = styled.div`}`;-class ColorSelector extends Component<ColorSelectorProps> {- static defaultProps = {- colorSets: []- };-- state = {- showDropdown: false- };-- node = createRef<HTMLDivElement>();-- handleClickOutside = e => {- if (this.props.colorUI && Number.isInteger(this.props.colorUI.showSketcher)) {- // if sketcher is open, let sketch to close itself first- return;- }-- this._closePanelDropdown();- };-- _getEditing = () => {- return this.props.colorUI ? this.props.colorUI.showDropdown : this.state.showDropdown;- };-- _closePanelDropdown = () => {- if (this._getEditing() === false) {- return;- }-- if (this.props.setColorUI) {- this.props.setColorUI({showDropdown: false, showSketcher: false});- } else {- this.setState({showDropdown: false});- }- };-- _onSelectColor = (color: RGBColor | ColorRange, e: MouseEvent) => {- e.stopPropagation();-- const editing = this._getEditing();-- if (typeof editing === 'number' && this.props.colorSets[editing]) {- // @ts-ignore- this.props.colorSets[editing].setColor(color);- }- };-- _showDropdown = (e, i) => {- e.stopPropagation();- e.preventDefault();-- if (this.props.setColorUI) {- this.props.setColorUI({showDropdown: i});- } else {- this.setState({showDropdown: i});- }- };-- render() {- const {colorSets, disabled, inputTheme, colorUI} = this.props;-- const editing = this._getEditing();- const currentEditing =- typeof editing === 'number' && colorSets[editing] && typeof colorSets[editing] === 'object';-- return (- <div className="color-selector" ref={this.node}>- <InputBoxContainer>- {colorSets.map((cSet, i) => (- <div className="color-select__input-group" key={i}>- <ColorSelectorInput- className="color-selector__selector"- active={editing === i}- disabled={disabled}- inputTheme={inputTheme}- onMouseDown={e => this._showDropdown(e, i)}- >- {cSet.isRange ? (- <ColorPalette colors={(cSet.selectedColor as ColorRange).colors} />- ) : (- <ColorBlock- className="color-selector__selector__block"- backgroundcolor={cSet.selectedColor as RGBColor}+ColorSelectorFactory.deps = [RangeSliderFactory];++function ColorSelectorFactory(RangeSlider): ComponentType<ColorSelectorProps> {+ class ColorSelector extends Component<ColorSelectorProps> {+ static defaultProps = {+ colorSets: []+ };++ state = {+ showDropdown: false+ };++ node = createRef<HTMLDivElement>();++ handleClickOutside = e => {+ if (this.props.colorUI && Number.isInteger(this.props.colorUI.showSketcher)) {+ // if sketcher is open, let sketch to close itself first+ return;+ }++ this._closePanelDropdown();+ };++ _getEditing = () => {+ return this.props.colorUI ? this.props.colorUI.showDropdown : this.state.showDropdown;+ };++ _closePanelDropdown = () => {+ if (this._getEditing() === false) {+ return;+ }++ if (this.props.setColorUI) {+ this.props.setColorUI({showDropdown: false, showSketcher: false});+ } else {+ this.setState({showDropdown: false});+ }+ };++ _onSelectColor = (color: RGBColor | ColorRange, e: MouseEvent) => {+ e.stopPropagation();+ const editing = this._getEditing();+ const colorSet = typeof editing === 'number' && this.props.colorSets[editing];+ if (colorSet) {+ this._setColor(colorSet, color, colorSet.selectedColor[3]);+ }+ };++ _onSelectOpacity = (opacity: number[], e: MouseEvent) => {+ if (e) e.stopPropagation();+ const editing = this._getEditing();+ const colorSet = typeof editing === 'number' && this.props.colorSets[editing];+ if (colorSet) {+ this._setColor(colorSet, colorSet.selectedColor, Math.round(opacity[1] * 255));+ }+ };++ _setColor = (colorSet: ColorSet, color: RGBColor | RGBAColor | ColorRange, opacity: number) => {+ if (this.props.useOpacity && Array.isArray(color)) {+ colorSet.setColor([...color.slice(0, 3), opacity] as RGBAColor);+ } else {+ colorSet.setColor(color);+ }+ };++ _showDropdown = (e, i) => {+ e.stopPropagation();+ e.preventDefault();++ if (this.props.setColorUI) {+ this.props.setColorUI({showDropdown: i});+ } else {+ this.setState({showDropdown: i});+ }+ };++ render() {+ const {colorSets, useOpacity, disabled, inputTheme, colorUI} = this.props;++ const editing = this._getEditing();+ const currentEditing =+ typeof editing === 'number' && colorSets[editing] && typeof colorSets[editing] === 'object';++ return (+ <div className="color-selector" ref={this.node}>+ <InputBoxContainer>+ {colorSets.map((cSet, i) => (+ <div className="color-select__input-group" key={i}>+ <ColorSelectorInput+ className="color-selector__selector"+ active={editing === i}+ disabled={disabled}+ inputTheme={inputTheme}+ onMouseDown={e => this._showDropdown(e, i)}+ >+ {cSet.isRange ? (+ <ColorPalette colors={(cSet.selectedColor as ColorRange).colors} />+ ) : (+ <ColorBlock+ className="color-selector__selector__block"+ backgroundcolor={cSet.selectedColor as RGBColor}+ />+ )}+ {cSet.label ? (+ <div className="color-selector__selector__label">{cSet.label}</div>+ ) : null}+ </ColorSelectorInput>+ </div>+ ))}+ </InputBoxContainer>+ {currentEditing ? (+ <StyledPanelDropdown className="color-selector__dropdown">+ {colorSets[editing as number].isRange ? (+ <ColorRangeSelector+ selectedColorRange={colorSets[editing as number].selectedColor as ColorRange}+ onSelectColorRange={this._onSelectColor}+ setColorPaletteUI={this.props.setColorUI}+ colorPaletteUI={colorUI as ColorUI}+ />+ ) : (+ <SingleColorPalette+ selectedColor={rgbToHex(colorSets[editing as number].selectedColor as RGBColor)}+ onSelectColor={this._onSelectColor}+ />+ )}+ {useOpacity ? (+ <OpacitySliderWrapper>+ <PanelLabel>+ <FormattedMessage id="color.opacity" />+ </PanelLabel>+ <RangeSlider+ {...OPACITY_SLIDER_PROPS}+ value1={colorSets[editing as number].selectedColor[3] / 255}+ onChange={this._onSelectOpacity}/>- )}- {cSet.label ? (- <div className="color-selector__selector__label">{cSet.label}</div>- ) : null}- </ColorSelectorInput>- </div>- ))}- </InputBoxContainer>- {currentEditing ? (- <StyledPanelDropdown className="color-selector__dropdown">- {colorSets[editing as number].isRange ? (- <ColorRangeSelector- selectedColorRange={colorSets[editing as number].selectedColor as ColorRange}- onSelectColorRange={this._onSelectColor}- setColorPaletteUI={this.props.setColorUI}- colorPaletteUI={colorUI as ColorUI}- />- ) : (- <SingleColorPalette- selectedColor={rgbToHex(colorSets[editing as number].selectedColor as RGBColor)}- onSelectColor={this._onSelectColor}- />- )}- </StyledPanelDropdown>- ) : null}- </div>- );+ </OpacitySliderWrapper>+ ) : null}+ </StyledPanelDropdown>+ ) : null}+ </div>+ );+ }}+ return onClickOutside(ColorSelector) as ComponentType<ColorSelectorProps>;}-export default onClickOutside(ColorSelector);+export default ColorSelectorFactory;diff --git a/src/components/src/side-panel/layer-panel/layer-color-selector.tsx b/src/components/src/side-panel/layer-panel/layer-color-selector.tsxnew file mode 100644index 000000000..df08adf3e--- /dev/null+++ b/src/components/src/side-panel/layer-panel/layer-color-selector.tsx@@ -0,0 +1,153 @@+// Copyright (c) 2023 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import React, {useCallback} from 'react';++import {ColorRange} from '@kepler.gl/constants';+import {Layer} from '@kepler.gl/layers';+import {NestedPartial, RGBColor, ColorUI} from '@kepler.gl/types';++import ColorSelectorFactory from './color-selector';+import {SidePanelSection} from '../../common/styled-components';++type LayerColorSelectorProps = {+ layer: Layer;+ onChange: (v: Record<string, RGBColor>) => void;+ selectedColor?: RGBColor;+ property?: string;+ setColorUI: (prop: string, newConfig: NestedPartial<ColorUI>) => void;+};++type ArcLayerColorSelectorProps = {+ layer: Layer;+ onChangeConfig: (v: {color: RGBColor}) => void;+ onChangeVisConfig: (v: {targetColor: RGBColor}) => void;+ property?: string;+ setColorUI: (prop: string, newConfig: NestedPartial<ColorUI>) => void;+};++type LayerColorRangeSelectorProps = {+ layer: Layer;+ onChange: (v: Record<string, ColorRange>) => void;+ property?: string;+ setColorUI: (prop: string, newConfig: NestedPartial<ColorUI>) => void;+};++LayerColorSelectorFactory.deps = [ColorSelectorFactory];+export function LayerColorSelectorFactory(ColorSelector) {+ const LayerColorSelector = ({+ layer,+ onChange,+ selectedColor,+ property = 'color',+ setColorUI+ }: LayerColorSelectorProps) => {+ const onSetColorUI = useCallback(newConfig => setColorUI(property, newConfig), [+ setColorUI,+ property+ ]);++ return (+ <SidePanelSection>+ <ColorSelector+ colorSets={[+ {+ selectedColor: selectedColor || layer.config.color,+ setColor: (rgbValue: RGBColor) => onChange({[property]: rgbValue})+ }+ ]}+ colorUI={layer.config.colorUI[property]}+ setColorUI={onSetColorUI}+ />+ </SidePanelSection>+ );+ };+ return LayerColorSelector;+}++LayerColorRangeSelectorFactory.deps = [ColorSelectorFactory];+export function LayerColorRangeSelectorFactory(ColorSelector) {+ const LayerColorRangeSelector = ({+ layer,+ onChange,+ property = 'colorRange',+ setColorUI+ }: LayerColorRangeSelectorProps) => {+ const onSetColorUI = useCallback(newConfig => setColorUI(property, newConfig), [+ setColorUI,+ property+ ]);++ return (+ <SidePanelSection>+ <ColorSelector+ colorSets={[+ {+ selectedColor: layer.config.visConfig[property],+ isRange: true,+ setColor: (colorRange: ColorRange) => onChange({[property]: colorRange})+ }+ ]}+ colorUI={layer.config.colorUI[property]}+ setColorUI={onSetColorUI}+ />+ </SidePanelSection>+ );+ };+ return LayerColorRangeSelector;+}++ArcLayerColorSelectorFactory.deps = [ColorSelectorFactory];+export function ArcLayerColorSelectorFactory(ColorSelector) {+ const ArcLayerColorSelector = ({+ layer,+ onChangeConfig,+ onChangeVisConfig,+ property = 'color',+ setColorUI+ }: ArcLayerColorSelectorProps) => {+ const onSetColorUI = useCallback(newConfig => setColorUI(property, newConfig), [+ setColorUI,+ property+ ]);++ return (+ <SidePanelSection>+ <ColorSelector+ colorSets={[+ {+ selectedColor: layer.config.color,+ setColor: (rgbValue: RGBColor) => onChangeConfig({color: rgbValue}),+ label: 'Source'+ },+ {+ selectedColor: layer.config.visConfig.targetColor || layer.config.color,+ setColor: (rgbValue: RGBColor) => onChangeVisConfig({targetColor: rgbValue}),+ label: 'Target'+ }+ ]}+ colorUI={layer.config.colorUI[property]}+ setColorUI={onSetColorUI}+ />+ </SidePanelSection>+ );+ };+ return ArcLayerColorSelector;+}diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsxindex ad678a1c1..fd6519748 100644--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx@@ -30,21 +30,25 @@ import VisConfigByFieldSelectorFactory from './vis-config-by-field-selector';import LayerColumnConfigFactory from './layer-column-config';import LayerTypeSelectorFactory from './layer-type-selector';import DimensionScaleSelector from './dimension-scale-selector';-import ColorSelector from './color-selector';import SourceDataSelectorFactory from '../common/source-data-selector';import VisConfigSwitchFactory from './vis-config-switch';import VisConfigSliderFactory from './vis-config-slider';import LayerConfigGroupFactory, {ConfigGroupCollapsibleContent} from './layer-config-group';import TextLabelPanelFactory from './text-label-panel';+import {+ LayerColorSelectorFactory,+ LayerColorRangeSelectorFactory,+ ArcLayerColorSelectorFactory+} from './layer-color-selector';import HowToButton from './how-to-button';import LayerErrorMessage from './layer-error-message';import {capitalizeFirstLetter} from '@kepler.gl/utils';-import {CHANNEL_SCALE_SUPPORTED_FIELDS, LAYER_TYPES, ColorRange} from '@kepler.gl/constants';+import {CHANNEL_SCALE_SUPPORTED_FIELDS, LAYER_TYPES} from '@kepler.gl/constants';import {Layer, LayerBaseConfig, VisualChannel, AggregationLayer} from '@kepler.gl/layers';-import {NestedPartial, RGBColor, LayerVisConfig, ColorUI, Field} from '@kepler.gl/types';+import {NestedPartial, LayerVisConfig, ColorUI, Field} from '@kepler.gl/types';import {toggleModal, ActionHandler} from '@kepler.gl/actions';import {Datasets} from '@kepler.gl/table';@@ -71,29 +75,6 @@ type LayerConfiguratorProps = {disableTypeSelect?: boolean;};-type LayerColorSelectorProps = {- layer: Layer;- onChange: (v: Record<string, RGBColor>) => void;- selectedColor?: RGBColor;- property?: string;- setColorUI: (prop: string, newConfig: NestedPartial<ColorUI>) => void;-};--type ArcLayerColorSelectorProps = {- layer: Layer;- onChangeConfig: (v: {color: RGBColor}) => void;- onChangeVisConfig: (v: {targetColor: RGBColor}) => void;- property?: string;- setColorUI: (prop: string, newConfig: NestedPartial<ColorUI>) => void;-};--type LayerColorRangeSelectorProps = {- layer: Layer;- onChange: (v: Record<string, ColorRange>) => void;- property?: string;- setColorUI: (prop: string, newConfig: NestedPartial<ColorUI>) => void;-};-type ChannelByValueSelectorProps = {layer: Layer;channel: VisualChannel;@@ -171,7 +152,10 @@ LayerConfiguratorFactory.deps = [ChannelByValueSelectorFactory,LayerColumnConfigFactory,LayerTypeSelectorFactory,- VisConfigSwitchFactory+ VisConfigSwitchFactory,+ LayerColorSelectorFactory,+ LayerColorRangeSelectorFactory,+ ArcLayerColorSelectorFactory];export default function LayerConfiguratorFactory(@@ -182,7 +166,10 @@ export default function LayerConfiguratorFactory(ChannelByValueSelector: ReturnType<typeof ChannelByValueSelectorFactory>,LayerColumnConfig: ReturnType<typeof LayerColumnConfigFactory>,LayerTypeSelector: ReturnType<typeof LayerTypeSelectorFactory>,- VisConfigSwitch: ReturnType<typeof VisConfigSwitchFactory>+ VisConfigSwitch: ReturnType<typeof VisConfigSwitchFactory>,+ LayerColorSelector: ReturnType<typeof LayerColorSelectorFactory>,+ LayerColorRangeSelector: ReturnType<typeof LayerColorRangeSelectorFactory>,+ ArcLayerColorSelector: ReturnType<typeof ArcLayerColorSelectorFactory>): React.ComponentType<LayerConfiguratorProps> {class LayerConfigurator extends Component<LayerConfiguratorProps> {_renderPointLayerConfig(props) {@@ -284,6 +271,7 @@ export default function LayerConfiguratorFactory({/* text label */}<TextLabelPanel+ id={layer.id}fields={visConfiguratorProps.fields}updateLayerTextLabel={this.props.updateLayerTextLabel}textLabel={layer.config.textLabel}@@ -602,6 +590,7 @@ export default function LayerConfiguratorFactory({/* text label */}<TextLabelPanel+ id={layer.id}fields={visConfiguratorProps.fields}updateLayerTextLabel={this.props.updateLayerTextLabel}textLabel={layer.config.textLabel}@@ -1124,75 +1113,6 @@ export default function LayerConfiguratorFactory(return LayerConfigurator;}-export const LayerColorSelector = ({- layer,- onChange,- selectedColor,- property = 'color',- setColorUI-}: LayerColorSelectorProps) => (- <SidePanelSection>- <ColorSelector- colorSets={[- {- selectedColor: selectedColor || layer.config.color,- setColor: (rgbValue: RGBColor) => onChange({[property]: rgbValue})- }- ]}- colorUI={layer.config.colorUI[property]}- setColorUI={newConfig => setColorUI(property, newConfig)}- />- </SidePanelSection>-);--export const ArcLayerColorSelector = ({- layer,- onChangeConfig,- onChangeVisConfig,- property = 'color',- setColorUI-}: ArcLayerColorSelectorProps) => (- <SidePanelSection>- <ColorSelector- colorSets={[- {- selectedColor: layer.config.color,- setColor: (rgbValue: RGBColor) => onChangeConfig({color: rgbValue}),- label: 'Source'- },- {- selectedColor: layer.config.visConfig.targetColor || layer.config.color,- setColor: (rgbValue: RGBColor) => onChangeVisConfig({targetColor: rgbValue}),- label: 'Target'- }- ]}- colorUI={layer.config.colorUI[property]}- setColorUI={newConfig => setColorUI(property, newConfig)}- />- </SidePanelSection>-);--export const LayerColorRangeSelector = ({- layer,- onChange,- property = 'colorRange',- setColorUI-}: LayerColorRangeSelectorProps) => (- <SidePanelSection>- <ColorSelector- colorSets={[- {- selectedColor: layer.config.visConfig[property],- isRange: true,- setColor: (colorRange: ColorRange) => onChange({[property]: colorRange})- }- ]}- colorUI={layer.config.colorUI[property]}- setColorUI={newConfig => setColorUI(property, newConfig)}- />- </SidePanelSection>-);-ChannelByValueSelectorFactory.deps = [VisConfigByFieldSelectorFactory];export function ChannelByValueSelectorFactory(diff --git a/src/components/src/side-panel/layer-panel/text-label-panel.tsx b/src/components/src/side-panel/layer-panel/text-label-panel.tsxindex 37d71f925..9a9f67386 100644--- a/src/components/src/side-panel/layer-panel/text-label-panel.tsx+++ b/src/components/src/side-panel/layer-panel/text-label-panel.tsx@@ -20,6 +20,8 @@import React, {Component} from 'react';import {FormattedMessage} from '@kepler.gl/localization';+import {ColorRange} from '@kepler.gl/constants';+import styled from 'styled-components';import {Button,@@ -29,7 +31,8 @@ import {SpaceBetweenFlexbox} from '../../common/styled-components';import {Add} from '../../common/icons';-import ColorSelector from './color-selector';+import ColorSelectorFactory from './color-selector';+import Switch from '../../common/switch';import ItemSelector from '../../common/item-selector/item-selector';import LayerConfigGroupFactory, {ConfigGroupCollapsibleContent,@@ -38,21 +41,35 @@ import LayerConfigGroupFactory, {import RangeSliderFactory from '../../common/range-slider';import FieldSelectorFactory from '../../common/field-selector';-import {RGBColor, LayerTextLabel, Field} from '@kepler.gl/types';+import {RGBColor, RGBAColor, LayerTextLabel, Field} from '@kepler.gl/types';import {LAYER_TEXT_CONFIGS} from '@kepler.gl/constants';+const SwitchWrapper = styled.div`+ display: flex;+ justify-content: space-between;+ line-height: 11px;+ margin-bottom: 8px;+`;+type TextLabelPanelProps = {+ id?: string;fields: Field[];textLabel: LayerTextLabel[];updateLayerTextLabel: (idx: number | 'all', prop: string, value: any) => void;};-TextLabelPanelFactory.deps = [RangeSliderFactory, LayerConfigGroupFactory, FieldSelectorFactory];+TextLabelPanelFactory.deps = [+ RangeSliderFactory,+ LayerConfigGroupFactory,+ FieldSelectorFactory,+ ColorSelectorFactory+];function TextLabelPanelFactory(RangeSlider: ReturnType<typeof RangeSliderFactory>,LayerConfigGroup: ReturnType<typeof LayerConfigGroupFactory>,- FieldSelector: ReturnType<typeof FieldSelectorFactory>+ FieldSelector: ReturnType<typeof FieldSelectorFactory>,+ ColorSelector: ReturnType<typeof ColorSelectorFactory>): React.ComponentType<TextLabelPanelProps> {class TextLabelPanel extends Component<TextLabelPanelProps> {render() {@@ -103,11 +120,63 @@ function TextLabelPanelFactory(colorSets={[{selectedColor: tl.color,- setColor: (v: RGBColor) => updateLayerTextLabel(idx, 'color', v)+ setColor: (v: RGBColor | RGBAColor | ColorRange) =>+ updateLayerTextLabel(idx, 'color', v)+ }+ ]}+ />+ </SidePanelSection>++ <SidePanelSection>+ <PanelLabel>+ <FormattedMessage id="panel.text.outlineWidth" />+ </PanelLabel>+ <RangeSlider+ {...LAYER_TEXT_CONFIGS.outlineWidth}+ value1={tl.outlineWidth}+ isRanged={false}+ onChange={v => updateLayerTextLabel(idx, 'outlineWidth', v[1])}+ />+ </SidePanelSection>+ <SidePanelSection>+ <PanelLabel>+ <FormattedMessage id="panel.text.outlineColor" />+ </PanelLabel>+ <ColorSelector+ colorSets={[+ {+ selectedColor: tl.outlineColor,+ setColor: v => updateLayerTextLabel(idx, 'outlineColor', v)}]}+ useOpacity={true}/></SidePanelSection>++ <SidePanelSection>+ <SwitchWrapper>+ <PanelLabel>+ <FormattedMessage id="panel.text.backgroundColor" />+ </PanelLabel>+ <Switch+ checked={tl.background}+ id={`${this.props.id}-textBackgroundEnabled-${idx}`}+ onChange={() => updateLayerTextLabel(idx, 'background', !tl.background)}+ />+ </SwitchWrapper>++ <ColorSelector+ colorSets={[+ {+ selectedColor: tl.backgroundColor,+ setColor: v => updateLayerTextLabel(idx, 'backgroundColor', v)+ }+ ]}+ useOpacity={true}+ disabled={!tl.background}+ />+ </SidePanelSection>+<SidePanelSection><SpaceBetweenFlexbox><SBFlexboxItem>diff --git a/src/constants/src/layers.ts b/src/constants/src/layers.tsindex aed26df26..e803b92bd 100644--- a/src/constants/src/layers.ts+++ b/src/constants/src/layers.ts@@ -56,7 +56,11 @@ export const DEFAULT_TEXT_LABEL: LayerTextLabel = {size: 18,offset: [0, 0],anchor: 'start',- alignment: 'center'+ alignment: 'center',+ outlineWidth: 0,+ outlineColor: [255, 0, 0, 255],+ background: false,+ backgroundColor: [0, 0, 200, 255]};export const DEFAULT_CUSTOM_PALETTE: ColorRange = {@@ -469,6 +473,15 @@ export const LAYER_TEXT_CONFIGS: LayerTextConfig = {label: 'Font size',showInput: true},+ outlineWidth: {+ type: 'number',+ range: [0, 1],+ value0: 0,+ step: 0.01,+ isRanged: false,+ label: 'Outline width',+ showInput: true+ },textAnchor: {type: 'select',options: ['start', 'middle', 'end'],diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.tsindex e435ff764..fbd9e3caa 100644--- a/src/layers/src/base-layer.ts+++ b/src/layers/src/base-layer.ts@@ -1326,12 +1326,29 @@ class Layer {};}- renderTextLabelLayer({getPosition, getPixelOffset, updateTriggers, sharedProps}, renderOpts) {+ renderTextLabelLayer(+ {+ getPosition,+ getPixelOffset,+ backgroundProps,+ updateTriggers,+ sharedProps+ }: {+ getPosition: any;+ getPixelOffset: any;+ backgroundProps?: any;+ updateTriggers: any;+ sharedProps: any;+ },+ renderOpts+ ) {const {data, mapState} = renderOpts;const {textLabel} = this.config;return data.textLabels.reduce((accu, d, i) => {if (d.getText) {+ const background = textLabel[i].background || backgroundProps?.background;+accu.push(new TextLayer({...sharedProps,@@ -1347,6 +1364,13 @@ class Layer {getTextAnchor: textLabel[i].anchor,getAlignmentBaseline: textLabel[i].alignment,getColor: textLabel[i].color,+ outlineWidth: textLabel[i].outlineWidth,+ outlineColor: textLabel[i].outlineColor,+ background,+ getBackgroundColor: textLabel[i].backgroundColor,+ fontSettings: {+ sdf: textLabel[i].outlineWidth > 0+ },parameters: {// text will always show on top of all layersdepthTest: false@@ -1365,6 +1389,17 @@ class Layer {getTextAnchor: textLabel[i].anchor,getAlignmentBaseline: textLabel[i].alignment,getColor: textLabel[i].color+ },+ _subLayerProps: {+ ...(background+ ? {+ background: {+ parameters: {+ cull: false+ }+ }+ }+ : null)}}));diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.tsindex 48fdfb15b..83b868a72 100644--- a/src/localization/src/translations/en.ts+++ b/src/localization/src/translations/en.ts@@ -71,9 +71,12 @@ export default {labelWithId: 'Label {labelId}',fontSize: 'Font size',fontColor: 'Font color',+ backgroundColor: 'Background color',textAnchor: 'Text anchor',alignment: 'Alignment',- addMoreLabel: 'Add More Label'+ addMoreLabel: 'Add More Label',+ outlineWidth: 'Outline width',+ outlineColor: 'Outline color'}},sidebar: {@@ -459,7 +462,8 @@ export default {customPalette: 'Custom Palette',steps: 'steps',type: 'type',- reversed: 'reversed'+ reversed: 'reversed',+ opacity: 'Opacity'},scale: {colorScale: 'Color Scale',diff --git a/src/types/layers.d.ts b/src/types/layers.d.tsindex b9c169fe1..10a24d981 100644--- a/src/types/layers.d.ts+++ b/src/types/layers.d.ts@@ -85,10 +85,14 @@ export type FieldPair = {export type LayerTextLabel = {field: Field | null;color: RGBColor;+ background: boolean;size: number;offset: [number, number];anchor: string;alignment: string;+ outlineWidth: number;+ outlineColor: RGBAColor;+ backgroundColor: RGBAColor;};export type ColorUI = {@@ -266,6 +270,7 @@ export type TextConfigNumber = {};export type LayerTextConfig = {fontSize: TextConfigNumber;+ outlineWidth: TextConfigNumber;textAnchor: TextConfigSelect;textAlignment: TextConfigSelect;};diff --git a/test/browser/components/side-panel/color-selector-test.js b/test/browser/components/side-panel/color-selector-test.jsindex a8ce5c267..c90e3ca86 100644--- a/test/browser/components/side-panel/color-selector-test.js+++ b/test/browser/components/side-panel/color-selector-test.js@@ -26,12 +26,13 @@ import sinon from 'sinon';import cloneDeep from 'lodash.clonedeep';import {- ColorSelector,+ appInjector,+ ColorSelectorFactory,ColorSelectorInput,ColorBlock,- LayerColorSelector,- LayerColorRangeSelector,- ArcLayerColorSelector,+ LayerColorSelectorFactory,+ LayerColorRangeSelectorFactory,+ ArcLayerColorSelectorFactory,getLayerConfiguratorProps,getVisConfiguratorProps,SingleColorPalette,@@ -52,6 +53,11 @@ import {StateWFilesFiltersLayerColor, StateWTrips} from 'test/helpers/mock-stateimport {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';import {hexToRgb} from '@kepler.gl/utils';+const ColorSelector = appInjector.get(ColorSelectorFactory);+const LayerColorSelector = appInjector.get(LayerColorSelectorFactory);+const LayerColorRangeSelector = appInjector.get(LayerColorRangeSelectorFactory);+const ArcLayerColorSelector = appInjector.get(ArcLayerColorSelectorFactory);+test('Components -> ColorSelector.render', t => {t.doesNotThrow(() => {mount(<ColorSelector />);@@ -791,3 +797,50 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRangt.end();});++test('Components -> ColorSelector.opacity', t => {+ const setColor = sinon.spy();++ const colorSelectorProps = {+ colorSets: [+ {+ selectedColor: [128, 64, 32, 100],+ setColor: setColor+ }+ ],+ useOpacity: true+ };++ let wrapper;+ t.doesNotThrow(() => {+ wrapper = mountWithTheme(+ <IntlWrapper>+ <ColorSelector {...colorSelectorProps} />+ </IntlWrapper>+ );+ }, 'Mount should not fail');++ // show palette+ wrapper+ .find('.color-selector__selector')+ .at(0)+ .invoke('onMouseDown')({preventDefault() {}, stopPropagation() {}});++ // select color+ wrapper+ .find('.single-color-palette__block')+ .at(100)+ .simulate('click');+ t.ok(setColor.calledOnce, 'should call setColor once');+ t.ok(setColor.calledWith([228, 155, 0, 100]), 'setColor called with correct color and opacity');++ // change opacity via slider+ wrapper+ .find('RangeSlider')+ .at(0)+ .invoke('onChange')([0.5, 0.5]);+ t.ok(setColor.calledTwice, 'should call setColor twice');+ t.ok(setColor.calledWith([128, 64, 32, 128]), 'setColor called with correct color and opacity');++ t.end();+});diff --git a/test/browser/layer-tests/h3-hexagon-layer-specs.js b/test/browser/layer-tests/h3-hexagon-layer-specs.jsindex dd823ab94..a7ce5d662 100644--- a/test/browser/layer-tests/h3-hexagon-layer-specs.js+++ b/test/browser/layer-tests/h3-hexagon-layer-specs.js@@ -335,7 +335,11 @@ test('#H3Layer -> renderLayer', t => {size: 18,offset: [0, 0],anchor: 'middle',- alignment: 'center'+ alignment: 'center',+ outlineWidth: 0,+ outlineColor: [255, 0, 0, 255],+ background: false,+ backgroundColor: [0, 0, 200, 255]}];diff --git a/test/fixtures/state-saved-v1-4.js b/test/fixtures/state-saved-v1-4.jsindex 1c3e8bfd2..2e99148e1 100644--- a/test/fixtures/state-saved-v1-4.js+++ b/test/fixtures/state-saved-v1-4.js@@ -236,7 +236,11 @@ mergedLayer0.config = {size: 27,offset: [-10, 0],anchor: 'end',- alignment: 'center'+ alignment: 'center',+ outlineWidth: 0,+ outlineColor: [255, 0, 0, 255],+ background: false,+ backgroundColor: [0, 0, 200, 255]}],colorUI: {diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.jsindex 5d0ae0b25..9be8859af 100644--- a/test/fixtures/test-hex-id-data.js+++ b/test/fixtures/test-hex-id-data.js@@ -411,7 +411,11 @@ mergedH3Layer.config = {size: 18,offset: [0, 0],anchor: 'start',- alignment: 'center'+ alignment: 'center',+ outlineWidth: 0,+ outlineColor: [255, 0, 0, 255],+ background: false,+ backgroundColor: [0, 0, 200, 255]}],colorUI: {