Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feat] More control over point label (#515)
Shan He729c5714125a
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.jsindex 50e096c14..41c629915 100644--- a/src/actions/vis-state-actions.js+++ b/src/actions/vis-state-actions.js@@ -37,6 +37,26 @@ export function layerConfigChange(oldLayer, newConfig) {};}+/**+ * Update layer text label+ * @memberof visStateActions+ * @param {Object} oldLayer - layer to be updated+ * @param {Number} idx -`idx` of text label to be updated+ * @param {string} prop - `prop` of text label, e,g, `anchor`, `alignment`, `color`, `size`, `field`+ * @param {*} value - new value+ * @returns {{type: ActionTypes.LAYER_TEXT_LABEL_CHANGE, oldLayer: oldLayer, idx: idx, prop: prop, value:}}+ * @public+ */+export function layerTextLabelChange(oldLayer, idx, prop, value) {+ return {+ type: ActionTypes.LAYER_TEXT_LABEL_CHANGE,+ oldLayer,+ idx,+ prop,+ value+ };+}+/*** Update layer type. Previews layer config will be copied if applicable.* @memberof visStateActionsdiff --git a/src/components/common/item-selector/chickleted-input.js b/src/components/common/item-selector/chickleted-input.jsindex 41cfe92f2..4b1aaf1b2 100644--- a/src/components/common/item-selector/chickleted-input.js+++ b/src/components/common/item-selector/chickleted-input.js@@ -35,7 +35,8 @@ const propTypes = {displayOption: PropTypes.func,focus: PropTypes.bool,error: PropTypes.bool,- placeholder: PropTypes.string+ placeholder: PropTypes.string,+ inputTheme: PropTypes.string};const ChickletButton = styled.div`@@ -44,8 +45,8 @@ const ChickletButton = styled.div`color: ${props => props.theme.textColor};font-size: 11px;line-height: 20px;- margin: 3px 10px 3px 3px;- padding: 4px 6px;+ margin: 4px 10px 4px 3px;+ padding: 2px 6px;display: flex;align-items: center;max-width: calc(100% - 8px);@@ -74,7 +75,14 @@ const Chicklet = ({disabled, name, remove}) => ();const ChickletedInputContainer = styled.div`- ${props => props.theme.chickletedInput}+ ${props => props.inputTheme === 'secondary' ?+ props.theme.secondaryChickletedInput : props.theme.chickletedInput}++ color: ${props =>+ props.hasPlaceholder+ ? props.theme.selectColorPlaceHolder+ : props.theme.selectColor};+ overflow: hidden;`;const ChickletedInput = ({@@ -86,7 +94,8 @@ const ChickletedInput = ({selectedItems = [],placeholder = '',removeItem,- displayOption = d => d+ displayOption = d => d,+ inputTheme}) => (<ChickletedInputContainerclassName={`${className} chickleted-input`}@@ -94,6 +103,8 @@ const ChickletedInput = ({disabled={disabled}error={error}onClick={onClick}+ inputTheme={inputTheme}+ hasPlaceholder={!selectedItems || !selectedItems.length}>{selectedItems.length > 0? selectedItems.map((item, i) => (@@ -104,7 +115,7 @@ const ChickletedInput = ({remove={e => removeItem(item, e)}/>))- : placeholder}+ : <span className={`${className} chickleted-input__placeholder`}>{placeholder}</span>}</ChickletedInputContainer>);diff --git a/src/components/common/styled-components.js b/src/components/common/styled-components.jsindex f1a805c4e..d6ed42ebf 100644--- a/src/components/common/styled-components.js+++ b/src/components/common/styled-components.js@@ -60,6 +60,16 @@ export const CenterFlexbox = styled.div`align-items: center;`;+export const SpaceBetweenFlexbox = styled.div`+ display: flex;+ align-items: space-between;+ margin-left: -16px;+`+export const SBFlexboxItem = styled.div`+ flex-grow: 1;+ margin-left: 16px;+`+export const PanelLabel = styled.label.attrs({className: 'side-panel-panel__label'})`diff --git a/src/components/side-panel.js b/src/components/side-panel.jsindex 5d3ca9bae..fde9bd1ca 100644--- a/src/components/side-panel.js+++ b/src/components/side-panel.js@@ -95,7 +95,6 @@ export default function SidePanelFactory(visStateActions: PropTypes.object.isRequired,mapStyleActions: PropTypes.object.isRequired};-/* component private functions */_onOpenOrClose = () => {this.props.uiStateActions.toggleSidePanel(@@ -151,6 +150,7 @@ export default function SidePanelFactory(const layerManagerActions = {addLayer: visStateActions.addLayer,layerConfigChange: visStateActions.layerConfigChange,+ layerTextLabelChange: visStateActions.layerTextLabelChange,layerVisualChannelConfigChange:visStateActions.layerVisualChannelConfigChange,layerTypeChange: visStateActions.layerTypeChange,diff --git a/src/components/side-panel/interaction-panel/tooltip-config.js b/src/components/side-panel/interaction-panel/tooltip-config.jsindex e80b4956b..84bb7e469 100644--- a/src/components/side-panel/interaction-panel/tooltip-config.js+++ b/src/components/side-panel/interaction-panel/tooltip-config.js@@ -45,6 +45,7 @@ function TooltipConfigFactory() {}}closeOnSelect={false}multiSelect+ inputTheme="secondary"/></SidePanelSection>))}diff --git a/src/components/side-panel/layer-manager.js b/src/components/side-panel/layer-manager.jsindex e68d18307..68d418a73 100644--- a/src/components/side-panel/layer-manager.js+++ b/src/components/side-panel/layer-manager.js@@ -140,6 +140,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {layerClasses: PropTypes.object.isRequired,layers: PropTypes.arrayOf(PropTypes.any).isRequired,layerConfigChange: PropTypes.func.isRequired,+ layerTextLabelChange: PropTypes.func.isRequired,layerVisualChannelConfigChange: PropTypes.func.isRequired,layerTypeChange: PropTypes.func.isRequired,layerVisConfigChange: PropTypes.func.isRequired,@@ -181,6 +182,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {layerVisualChannelConfigChange: this.props.layerVisualChannelConfigChange,layerTypeChange: this.props.layerTypeChange,layerVisConfigChange: this.props.layerVisConfigChange,+ layerTextLabelChange: this.props.layerTextLabelChange,removeLayer: this.props.removeLayer};diff --git a/src/components/side-panel/layer-panel/layer-config-group.js b/src/components/side-panel/layer-panel/layer-config-group.jsindex e1bcfb87f..c9de933b5 100644--- a/src/components/side-panel/layer-panel/layer-config-group.js+++ b/src/components/side-panel/layer-panel/layer-config-group.js@@ -51,16 +51,26 @@ export const ConfigGroupCollapsibleContent = styled.div.attrs({max-height: 600px;`;+export const ConfigGroupCollapsibleHeader = styled.div.attrs({+ className: 'layer-config-group__header__collapsible'+})`+ overflow: visible;+ overflow: hidden;+ max-height: 0;+`+export const StyledLayerConfigGroup = styled.div`padding-left: 18px;margin-bottom: 12px;&.collapsed {+ .layer-config-group__header__collapsible {+ overflow: visible;+ max-height: 600px;+ }.layer-config-group__content {.layer-config-group__content__collapsible {- /* display: none; */- /* flex: 0; */overflow: hidden;max-height: 0;}diff --git a/src/components/side-panel/layer-panel/layer-configurator.js b/src/components/side-panel/layer-panel/layer-configurator.jsindex c9cb6366d..13a1f660e 100644--- a/src/components/side-panel/layer-panel/layer-configurator.js+++ b/src/components/side-panel/layer-panel/layer-configurator.js@@ -185,8 +185,8 @@ export default class LayerConfigurator extends Component {{/* text label */}<TextLabelPanel- visConfiguratorProps={visConfiguratorProps}- layerConfiguratorProps={layerConfiguratorProps}+ fields={visConfiguratorProps.fields}+ updateLayerTextLabel={this.props.updateLayerTextLabel}textLabel={layer.config.textLabel}/></StyledLayerVisualConfigurator>diff --git a/src/components/side-panel/layer-panel/layer-panel.js b/src/components/side-panel/layer-panel/layer-panel.jsindex 3a277cc18..5e5705b4a 100644--- a/src/components/side-panel/layer-panel/layer-panel.js+++ b/src/components/side-panel/layer-panel/layer-panel.js@@ -66,6 +66,10 @@ function LayerPanelFactory() {this.props.layerVisConfigChange(this.props.layer, newVisConfig);};+ updateLayerTextLabel = (...args) => {+ this.props.layerTextLabelChange(this.props.layer, ...args);+ };+updateLayerVisualChannelConfig = (newConfig, channel, scaleKey) => {this.props.layerVisualChannelConfigChange(this.props.layer,@@ -95,6 +99,7 @@ function LayerPanelFactory() {e.stopPropagation();this.props.removeLayer(this.props.idx);};+render() {const {layer, idx, datasets, layerTypeOptions} = this.props;const {config} = layer;@@ -130,6 +135,7 @@ function LayerPanelFactory() {updateLayerConfig={this.updateLayerConfig}updateLayerVisualChannelConfig={this.updateLayerVisualChannelConfig}updateLayerType={this.updateLayerType}+ updateLayerTextLabel={this.updateLayerTextLabel}updateLayerVisConfig={this.updateLayerVisConfig}/>)}diff --git a/src/components/side-panel/layer-panel/text-label-panel.js b/src/components/side-panel/layer-panel/text-label-panel.jsindex ff356d182..a46e703fc 100644--- a/src/components/side-panel/layer-panel/text-label-panel.js+++ b/src/components/side-panel/layer-panel/text-label-panel.js@@ -21,92 +21,107 @@import React, {Component} from 'react';import PropTypes from 'prop-types';-import {PanelLabel, SidePanelSection} from 'components/common/styled-components';+import {+ PanelLabel,+ SidePanelSection,+ SpaceBetweenFlexbox,+ SBFlexboxItem,+ Button+} from 'components/common/styled-components';+import {Add} from 'components/common/icons';import ColorSelector from './color-selector';import FieldSelector from 'components/common/field-selector';import ItemSelector from 'components/common/item-selector/item-selector';-import LayerConfigGroup, {ConfigGroupCollapsibleContent} from './layer-config-group';+import LayerConfigGroup, {+ ConfigGroupCollapsibleContent,+ ConfigGroupCollapsibleHeader+} from './layer-config-group';import RangeSlider from 'components/common/range-slider';import {LAYER_TEXT_CONFIGS} from 'layers/layer-factory';-export default class LayerConfigurator extends Component {+export default class TextLabelPanel extends Component {static propTypes = {- layerConfiguratorProps: PropTypes.object.isRequired,- textLabel: PropTypes.object.isRequired,- visConfiguratorProps: PropTypes.object.isRequired- };-- onAttributeChange = attribute => {- const {layerConfiguratorProps, textLabel} = this.props;- return v => layerConfiguratorProps.onChange({- textLabel: {- ...textLabel,- [attribute]: v- }- });- };-- onChangeTextAnchor = anchor => {- const {layerConfiguratorProps, textLabel} = this.props;- // TODO: we can be smarter on determining the offset of the text- layerConfiguratorProps.onChange({- textLabel: {- ...textLabel,- anchor,- offset: [- anchor === 'start' ? 10 : anchor === 'end' ? -10 : 0,- anchor === 'middle' ? 10 : 0- ]- }- });+ fields: PropTypes.arrayOf(PropTypes.object),+ textLabel: PropTypes.arrayOf(PropTypes.object),+ updateLayerTextLabel: PropTypes.func.isRequired};render() {- const {- visConfiguratorProps,- textLabel- } = this.props;+ const {updateLayerTextLabel, textLabel, fields} = this.props;+ const currentFields = textLabel.map(tl => tl.field && tl.field.name).filter(d => d);return (<LayerConfigGroup label={'label'} collapsible>+ <ConfigGroupCollapsibleHeader>+ <FieldSelector+ fields={fields}+ value={currentFields}+ onSelect={selected => updateLayerTextLabel('all', 'fields', selected)}+ multiSelect+ />+ </ConfigGroupCollapsibleHeader>+ <ConfigGroupCollapsibleContent>+ {textLabel.map((tl, idx) => (+ <div key={tl.field ? tl.field.name : 'null'}>+ <PanelLabel>{`Label ${idx + 1}`}</PanelLabel>+ <SidePanelSection>+ <FieldSelector+ fields={fields}+ value={(tl.field && tl.field.name) || 'Select a field'}+ placeholder={'empty'}+ onSelect={v => updateLayerTextLabel(idx, 'field', v)}+ erasable+ />+ </SidePanelSection>+ <SidePanelSection>+ <PanelLabel>{`Font size`}</PanelLabel>+ <RangeSlider+ {...LAYER_TEXT_CONFIGS.fontSize}+ value1={tl.size}+ isRange={false}+ onChange={v => updateLayerTextLabel(idx, 'size', v[1])}+ />+ </SidePanelSection>+ <SidePanelSection>+ <PanelLabel>{`Font color`}</PanelLabel>+ <ColorSelector+ colorSets={[+ {+ selectedColor: tl.color,+ setColor: v => updateLayerTextLabel(idx, 'color', v)+ }+ ]}+ />+ </SidePanelSection>+ <SidePanelSection>+ <SpaceBetweenFlexbox>+ <SBFlexboxItem>+ <PanelLabel>{`Text anchor`}</PanelLabel>+ <ItemSelector+ {...LAYER_TEXT_CONFIGS.textAnchor}+ selectedItems={tl.anchor}+ onChange={val => updateLayerTextLabel(idx, 'anchor', val)}+ />+ </SBFlexboxItem>+ <SBFlexboxItem>+ <PanelLabel>{`Alignment`}</PanelLabel>+ <ItemSelector+ {...LAYER_TEXT_CONFIGS.textAlignment}+ selectedItems={tl.alignment}+ onChange={val => updateLayerTextLabel(idx, 'alignment', val)}+ />+ </SBFlexboxItem>+ </SpaceBetweenFlexbox>+ </SidePanelSection>+ </div>+ ))}<SidePanelSection>- <FieldSelector- fields={visConfiguratorProps.fields}- value={textLabel.field && textLabel.field.name || 'select a field'}- placeholder={'empty'}- onSelect={this.onAttributeChange('field')}- erasable- />+ <Button link onClick={val => updateLayerTextLabel(textLabel.length)}>+ <Add height="12px" />+ Add More Label+ </Button></SidePanelSection>- <ConfigGroupCollapsibleContent>- <SidePanelSection>- <PanelLabel>{`Font size`}</PanelLabel>- <RangeSlider- {...LAYER_TEXT_CONFIGS.fontSize}- value1={textLabel.size}- onChange={v => this.onAttributeChange('size')(v[1])}- />- </SidePanelSection>- <SidePanelSection>- <PanelLabel>{`Font color`}</PanelLabel>- <ColorSelector- colorSets={[- {- selectedColor: textLabel.color,- setColor: this.onAttributeChange('color')- }- ]}- />- </SidePanelSection>- <SidePanelSection>- <PanelLabel>{`Text anchor`}</PanelLabel>- <ItemSelector- {...LAYER_TEXT_CONFIGS.textAnchor}- selectedItems={textLabel.anchor}- onChange={this.onChangeTextAnchor}- />- </SidePanelSection>- </ConfigGroupCollapsibleContent>+ </ConfigGroupCollapsibleContent></LayerConfigGroup>);}diff --git a/src/constants/action-types.js b/src/constants/action-types.jsindex d676b4044..c7f774b1f 100644--- a/src/constants/action-types.js+++ b/src/constants/action-types.js@@ -66,6 +66,7 @@ const ActionTypes = keyMirror({LAYER_VISUAL_CHANNEL_CHANGE: null,LAYER_TYPE_CHANGE: null,LAYER_VIS_CONFIG_CHANGE: null,+ LAYER_TEXT_LABEL_CHANGE: null,LAYER_HOVER: null,LAYER_CLICK: null,MAP_CLICK: null,diff --git a/src/layers/base-layer.js b/src/layers/base-layer.jsindex f82ce7162..26d66bf5a 100644--- a/src/layers/base-layer.js+++ b/src/layers/base-layer.js@@ -34,7 +34,7 @@ import {CHANNEL_SCALE_SUPPORTED_FIELDS} from 'constants/default-settings';import {DataVizColors} from 'constants/custom-color-ranges';-import {LAYER_VIS_CONFIGS} from './layer-factory';+import {LAYER_VIS_CONFIGS, DEFAULT_TEXT_LABEL} from './layer-factory';import {generateHashId, notNullorUndefined, isPlainObject} from 'utils/utils';@@ -299,13 +299,7 @@ export default class Layer {visConfig: {},- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- }+ textLabel: [DEFAULT_TEXT_LABEL]};}diff --git a/src/layers/layer-factory.js b/src/layers/layer-factory.jsindex 1a63288e7..5a0b8353d 100644--- a/src/layers/layer-factory.js+++ b/src/layers/layer-factory.js@@ -349,5 +349,20 @@ export const LAYER_TEXT_CONFIGS = {options: ['start', 'middle', 'end'],multiSelect: false,searchable: false+ },+ textAlignment: {+ type: 'select',+ options: ['top', 'center', 'bottom'],+ multiSelect: false,+ searchable: false}};++export const DEFAULT_TEXT_LABEL = {+ field: null,+ color: [255, 255, 255],+ size: 18,+ offset: [0, 0],+ anchor: 'start',+ alignment: 'center'+};diff --git a/src/layers/point-layer/point-layer.js b/src/layers/point-layer/point-layer.jsindex f8c68ea53..344b67a82 100644--- a/src/layers/point-layer/point-layer.js+++ b/src/layers/point-layer/point-layer.js@@ -27,6 +27,7 @@ import ScatterplotBrushingLayer from 'deckgl-layers/scatterplot-brushing-layer/simport {hexToRgb} from 'utils/color-utils';import PointLayerIcon from './point-layer-icon';import {DEFAULT_LAYER_COLOR, CHANNEL_SCALES} from 'constants/default-settings';+import {getDistanceScales} from 'viewport-mercator-project';export const pointPosAccessor = ({lat, lng, altitude}) => d => [// lng@@ -72,7 +73,7 @@ export default class PointLayer extends Layer {this.registerVisConfig(pointVisConfigs);this.getPosition = memoize(pointPosAccessor, pointPosResolver);- this.getText = memoize(pointLabelAccessor, pointLabelResolver);+ this.getText = [memoize(pointLabelAccessor, pointLabelResolver)];}get type() {@@ -254,20 +255,6 @@ export default class PointLayer extends Layer {}// get all distinct characters in the text labels- const getText = this.getText(textLabel);- let labelCharacterSet;- if (- oldLayerData &&- oldLayerData.labelCharacterSet &&- opt.sameData &&- oldLayerData.getText === getText- ) {- labelCharacterSet = oldLayerData.labelCharacterSet;- } else {- const textLabels = textLabel.field ? data.map(getText) : [];- labelCharacterSet = uniq(textLabels.join(''));- }-const getRadius = rScale? d => this.getEncodedChannelValue(rScale, d.data, sizeField): 1;@@ -279,14 +266,49 @@ export default class PointLayer extends Layer {const getLineColor = scScale? d => this.getEncodedChannelValue(scScale, d.data, strokeColorField): strokeColor || color;++ // TODO: this should be cleaned up in the gpu-data-filter branch+ const textLabels = textLabel.map((tl, i) => {+ if (!tl.field) {+ // if no field selected,+ return {+ getText: null,+ characterSet: []+ };+ }+ if (!this.getText[i]) {+ this.getText[i] = memoize(pointLabelAccessor, pointLabelResolver);+ }++ const getText = this.getText[i](tl);+ let characterSet;++ if (+ oldLayerData &&+ Array.isArray(oldLayerData.textLabels) &&+ oldLayerData.textLabels[i] &&+ opt.sameData &&+ oldLayerData.textLabels[i].getText === getText+ ) {+ characterSet = oldLayerData.textLabels[i].characterSet;+ } else {+ const allLabels = tl.field ? data.map(getText) : [];+ characterSet = uniq(allLabels.join(''));+ }++ return {+ characterSet,+ getText+ };+ });+return {data,- labelCharacterSet,getPosition,getFillColor,getLineColor,getRadius,- getText+ textLabels};}/* eslint-enable complexity */@@ -297,6 +319,38 @@ export default class PointLayer extends Layer {this.updateMeta({bounds});}+ getTextOffset(config, radiusScale, getRadius, mapState) {+ const distanceScale = getDistanceScales(mapState);+ const xMult =+ config.anchor === 'middle' ? 0 : config.anchor === 'start' ? 1 : -1;+ const yMult =+ config.alignment === 'center'+ ? 0+ : config.alignment === 'bottom'+ ? 1+ : -1;++ const sizeOffset =+ config.alignment === 'center'+ ? 0+ : config.alignment === 'bottom'+ ? config.size+ : config.size;++ const pixelRadius = radiusScale * distanceScale.pixelsPerMeter[0];+ const padding = 20;++ return typeof getRadius === 'function'+ ? d => [+ xMult * (getRadius(d) * pixelRadius + padding),+ yMult * (getRadius(d) * pixelRadius + padding + sizeOffset)+ ]+ : [+ xMult * (getRadius * pixelRadius + padding),+ yMult * (getRadius * pixelRadius + padding + sizeOffset)+ ];+ }+renderLayer({data,idx,@@ -306,6 +360,7 @@ export default class PointLayer extends Layer {interactionConfig}) {const enableBrushing = interactionConfig.brush.enabled;+ const radiusScale = this.getRadiusScaleByZoom(mapState);const layerProps = {// TODO: support setting stroke and fill simultaneously@@ -313,7 +368,7 @@ export default class PointLayer extends Layer {filled: this.config.visConfig.filled,radiusMinPixels: 1,lineWidthMinPixels: this.config.visConfig.thickness,- radiusScale: this.getRadiusScaleByZoom(mapState),+ radiusScale,...(this.config.visConfig.fixedRadius ? {} : {radiusMaxPixels: 500})};@@ -324,13 +379,37 @@ export default class PointLayer extends Layer {highlightColor: this.config.highlightColor};+ const {textLabel} = this.config;+ const updateTriggers = {+ getPosition: {+ columns: this.config.columns+ },+ getRadius: {+ sizeField: this.config.sizeField,+ radiusRange: this.config.visConfig.radiusRange,+ fixedRadius: this.config.visConfig.fixedRadius,+ sizeScale: this.config.sizeScale+ },+ getFillColor: {+ color: this.config.color,+ colorField: this.config.colorField,+ colorRange: this.config.visConfig.colorRange,+ colorScale: this.config.colorScale+ },+ getLineColor: {+ color: this.config.visConfig.strokeColor,+ colorField: this.config.strokeColorField,+ colorRange: this.config.visConfig.strokeColorRange,+ colorScale: this.config.strokeColorScale+ }+ };+return [new ScatterplotBrushingLayer({...layerProps,...layerInteraction,...data,...interaction,-idx,id: this.id,opacity: this.config.visConfig.opacity,@@ -339,33 +418,7 @@ export default class PointLayer extends Layer {// circles will be flat on the map when the altitude column is not useddepthTest: this.config.columns.altitude.fieldIdx > -1},-- updateTriggers: {- getPosition: {- columns: this.config.columns- },- getRadius: {- sizeField: this.config.sizeField,- radiusRange: this.config.visConfig.radiusRange,- fixedRadius: this.config.visConfig.fixedRadius,- sizeScale: this.config.sizeScale- },- getFillColor: {- color: this.config.color,- colorField: this.config.colorField,- colorRange: this.config.visConfig.colorRange,- colorScale: this.config.colorScale- },- getLineColor: {- color: this.config.visConfig.strokeColor,- colorField: this.config.strokeColorField,- colorRange: this.config.visConfig.strokeColorRange,- colorScale: this.config.strokeColorScale- },- getText: {- textLabel: this.config.textLabel- }- }+ updateTriggers}),// hover layer...(this.isLayerHovered(objectHovered)@@ -383,34 +436,49 @@ export default class PointLayer extends Layer {]: []),// text label layer- ...(this.config.textLabel.field- ? [+ ...data.textLabels.reduce((accu, d, i) => {+ if (d.getText) {+ accu.push(new TextLayer({...layerInteraction,- id: `${this.id}-label`,+ id: `${this.id}-label-${textLabel[i].field.name}`,data: data.data,getPosition: data.getPosition,- getPixelOffset: this.config.textLabel.offset,- getSize: this.config.textLabel.size,- getTextAnchor: this.config.textLabel.anchor,- getText: data.getText,- getColor: d => this.config.textLabel.color,+ getText: d.getText,+ characterSet: d.characterSet,+ getPixelOffset: this.getTextOffset(+ textLabel[i],+ radiusScale,+ data.getRadius,+ mapState+ ),+ getSize: 1,+ sizeScale: textLabel[i].size,+ getTextAnchor: textLabel[i].anchor,+ getAlignmentBaseline: textLabel[i].alignment,+ getColor: textLabel[i].color,parameters: {// text will always show on top of all layersdepthTest: false},- characterSet: data.labelCharacterSet,updateTriggers: {- getPosition: data.getPosition,- getPixelOffset: this.config.textLabel.offset,- getText: this.config.textLabel.field,- getTextAnchor: this.config.textLabel.anchor,- getSize: this.config.textLabel.size,- getColor: this.config.textLabel.color+ getPosition: this.config.columns,+ getText: textLabel[i].field.name,+ getPixelOffset: {+ ...updateTriggers.getRadius,+ mapState,+ anchor: textLabel[i].anchor,+ alignment: textLabel[i].alignment+ },+ getTextAnchor: textLabel[i].anchor,+ getAlignmentBaseline: textLabel[i].alignment,+ getColor: textLabel[i].color}})- ]- : [])+ );+ }+ return accu;+ }, [])];}}diff --git a/src/reducers/vis-state-merger.js b/src/reducers/vis-state-merger.jsindex e6a193e2e..2a4c9fc5e 100644--- a/src/reducers/vis-state-merger.js+++ b/src/reducers/vis-state-merger.js@@ -299,19 +299,23 @@ export function validateSavedLayerColumns(fields, savedCols, emptyCols) {* @param {Object} savedTextLabel* @return {Object} - validated textlabel*/-export function validateSavedTextLabel(fields, layerTextLabel, savedTextLabel) {+export function validateSavedTextLabel(fields, [layerTextLabel], savedTextLabel) {+ const savedTextLabels = Array.isArray(savedTextLabel) ?+ savedTextLabel : [savedTextLabel];// validate field- const field = savedTextLabel.field ? fields.find(fd =>- Object.keys(savedTextLabel.field).every(- key => savedTextLabel.field[key] === fd[key]- )- ) : null;-- return Object.keys(layerTextLabel).reduce((accu, key) => ({- ...accu,- [key]: key === 'field' ? field : (savedTextLabel[key] || layerTextLabel[key])- }), {});+ return savedTextLabels.map(textLabel => {+ const field = textLabel.field ? fields.find(fd =>+ Object.keys(textLabel.field).every(+ key => textLabel.field[key] === fd[key]+ )+ ) : null;++ return Object.keys(layerTextLabel).reduce((accu, key) => ({+ ...accu,+ [key]: key === 'field' ? field : (textLabel[key] || layerTextLabel[key])+ }), {});+ });}/**diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.jsindex 4742e4f14..375307cad 100644--- a/src/reducers/vis-state-updaters.js+++ b/src/reducers/vis-state-updaters.js@@ -56,6 +56,7 @@ import {import {Layer, LayerClasses} from 'layers';import {processFileToLoad} from '/utils/file-utils';+import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';// react-palm// disable capture exception for react-palm call to withTask@@ -193,7 +194,6 @@ export function layerConfigChangeUpdater(state, action) {const {oldLayer} = action;const idx = state.layers.findIndex(l => l.id === oldLayer.id);const props = Object.keys(action.newConfig);-const newLayer = oldLayer.updateLayerConfig(action.newConfig);if (newLayer.shouldCalculateLayerData(props)) {const oldLayerData = state.layerData[idx];@@ -217,6 +217,70 @@ export function layerConfigChangeUpdater(state, action) {return updateStateWithLayerAndData(newState, {layer: newLayer, idx});}+function addOrRemoveTextLabels(newFields, textLabel) {+ let newTextLabel = textLabel.slice();++ const currentFields = textLabel.map(tl => tl.field && tl.field.name).filter(d => d);++ const addFields = newFields.filter(f => !currentFields.includes(f.name));+ const deleteFields = currentFields+ .filter(f => !newFields.find(fd => fd.name === f));++ // delete+ newTextLabel = newTextLabel.filter(tl => tl.field && !deleteFields.includes(tl.field.name));+ newTextLabel = !newTextLabel.length ? [DEFAULT_TEXT_LABEL] : newTextLabel;++ // add+ newTextLabel = [+ ...(newTextLabel.filter(tl => tl.field)),+ ...addFields.map(af => ({+ ...DEFAULT_TEXT_LABEL,+ field: af+ }))+ ];++ return newTextLabel;+}++function updateTextLabelPropAndValue(idx, prop, value, textLabel) {+ let newTextLabel = textLabel.slice();++ if (prop && (value || textLabel.length === 1)) {+ newTextLabel = textLabel.map((tl, i) =>+ i === idx ? {...tl, [prop]: value} : tl);+ } else if (prop === 'field' && value === null && textLabel.length > 1) {++ // remove label when field value is set to null+ newTextLabel.splice(idx, 1);+ }++ return newTextLabel;+}++export function layerTextLabelChangeUpdater(state, action) {+ const {oldLayer, idx, prop, value} = action;+ const {textLabel} = oldLayer.config;++ let newTextLabel = textLabel.slice();++ if (idx === 'all' && prop === 'fields') {+ newTextLabel = addOrRemoveTextLabels(value, textLabel);+ }++ // if idx is set to length, add empty text label+ if (!textLabel[idx] && idx === textLabel.length) {+ newTextLabel = [+ ...textLabel,+ DEFAULT_TEXT_LABEL+ ];+ }++ // update text label prop and value+ newTextLabel = updateTextLabelPropAndValue(idx, prop, value, newTextLabel);++ return layerConfigChangeUpdater(state, {oldLayer, newConfig: {textLabel: newTextLabel}});+}+/*** Update layer type. Previews layer config will be copied if applicable.* @memberof visStateUpdatersdiff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.jsindex 713339855..f10bd6e25 100644--- a/src/reducers/vis-state.js+++ b/src/reducers/vis-state.js@@ -45,6 +45,8 @@ const actionHandler = {[ActionTypes.LAYER_VIS_CONFIG_CHANGE]: visStateUpdaters.layerVisConfigChangeUpdater,+ [ActionTypes.LAYER_TEXT_LABEL_CHANGE]: visStateUpdaters.layerTextLabelChangeUpdater,+[ActionTypes.LAYER_VISUAL_CHANNEL_CHANGE]: visStateUpdaters.layerVisualChannelChangeUpdater,[ActionTypes.LOAD_FILES]: visStateUpdaters.loadFilesUpdater,diff --git a/src/schemas/vis-state-schema.js b/src/schemas/vis-state-schema.jsindex 0d846aab2..caa9e5dd0 100644--- a/src/schemas/vis-state-schema.js+++ b/src/schemas/vis-state-schema.js@@ -297,15 +297,15 @@ class ColumnSchemaV1 extends Schema {class TextLabelSchemaV1 extends Schema {save(textLabel) {return {- [this.key]: {- ...textLabel,- field: textLabel.field ? pick(textLabel.field, ['name', 'type']) : null- }+ [this.key]: textLabel.map(tl => ({+ ...tl,+ field: tl.field ? pick(tl.field, ['name', 'type']) : null+ }))};}load(textLabel) {- return {textLabel};+ return {textLabel: Array.isArray(textLabel) ? textLabel : [textLabel]};}}diff --git a/src/styles/base.js b/src/styles/base.jsindex 6634e7cf9..6b3ddc827 100644--- a/src/styles/base.js+++ b/src/styles/base.js@@ -359,15 +359,29 @@ const secondaryInput = css`}`;-const chickletedInput = css`- ${props => props.theme.secondaryInput}+const chickletedInputContainer = css`cursor: pointer;flex-wrap: wrap;height: auto;justify-content: start;margin-bottom: 2px;- padding: 4px 7px 4px 4px;+ padding: 0px 7px 0px 4px;white-space: normal;++ .chickleted-input__placeholder {+ line-height: 24px;+ margin: 4px;+ }+`;++const chickletedInput = css`+ ${props => props.theme.input}+ ${props => props.theme.chickletedInputContainer}+`;++const secondaryChickletedInput = css`+ ${props => props.theme.secondaryInput}+ ${props => props.theme.chickletedInputContainer}`;const inlineInput = css`@@ -722,6 +736,9 @@ export const theme = {inputLT,inlineInput,chickletedInput,+ chickletedInputContainer,+ secondaryChickletedInput,+secondaryInput,dropdownScrollBar,dropdownList,diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.jsindex 6759e67e9..61aaac7f2 100644--- a/test/fixtures/state-saved-v0.js+++ b/test/fixtures/state-saved-v0.js@@ -22,6 +22,7 @@ import {KeplerGlLayers} from 'layers';const {PointLayer, ArcLayer, HexagonLayer, GeojsonLayer} = KeplerGlLayers;import {Messages, Crosshairs} from 'components/common/icons';+import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';export const savedStateV0 = {config: {@@ -1036,13 +1037,7 @@ mergedLayer0.config = {sizeField: null,sizeScale: 'linear',sizeDomain: [0, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],visConfig: {radius: 270.4,opacity: 0.8,@@ -1120,13 +1115,7 @@ mergedLayer1.config = {sizeField: null,sizeScale: 'linear',sizeDomain: [0, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],visConfig: {opacity: 0.41,thickness: 2,@@ -1188,13 +1177,7 @@ mergedLayer2.config = {},sizeDomain: [78, 694],sizeScale: 'linear',- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],visConfig: {radius: 10,opacity: 0.8,@@ -1273,13 +1256,7 @@ mergedLayer3.config = {sizeField: null,sizeScale: 'linear',sizeDomain: [0, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],visConfig: {colorAggregation: 'maximum',sizeAggregation: 'average',@@ -1350,13 +1327,7 @@ mergedLayer4.config = {sizeField: null,sizeScale: 'linear',sizeDomain: [0, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],heightField: null,heightDomain: [0, 1],heightScale: 'linear',diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.jsindex 422f66c3b..80e59f98e 100644--- a/test/fixtures/state-saved-v1-1.js+++ b/test/fixtures/state-saved-v1-1.js@@ -20,6 +20,7 @@import GeojsonLayer from 'layers/geojson-layer/geojson-layer';import {Messages, Crosshairs} from 'components/common/icons';+import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';export const savedStateV1 = {datasets: [@@ -896,13 +897,7 @@ mergedLayer0.config = {sizeField: null,sizeScale: 'linear',sizeDomain: [0, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],heightField: {name: 'c_a_v',type: 'real',@@ -2714,13 +2709,7 @@ mergedLayer1.config = {},sizeScale: 'linear',sizeDomain: [0.970877074, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],heightField: null,heightScale: 'linear',heightDomain: [0, 1],diff --git a/test/fixtures/state-saved-v1-3.js b/test/fixtures/state-saved-v1-3.jsindex 48a043e37..2f1299950 100644--- a/test/fixtures/state-saved-v1-3.js+++ b/test/fixtures/state-saved-v1-3.js@@ -20,6 +20,8 @@import {KeplerGlLayers} from 'layers';const {PointLayer, HexagonLayer} = KeplerGlLayers;+import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';+// saved state v1 with split mapsexport const savedStateV1 = {datasets: [@@ -396,13 +398,7 @@ mergedLayer0.config = {},sizeScale: 'sqrt',sizeDomain: [1000, 3000],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],visConfig: {radius: 10,fixedRadius: true,@@ -470,13 +466,7 @@ mergedLayer1.config = {sizeField: null,sizeScale: 'linear',sizeDomain: [0, 1],- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- },+ textLabel: [DEFAULT_TEXT_LABEL],visConfig: {opacity: 0.8,worldUnitSize: 2.73,diff --git a/test/fixtures/state-saved-v1-4.js b/test/fixtures/state-saved-v1-4.jsindex 279f25833..5991d7bf4 100644--- a/test/fixtures/state-saved-v1-4.js+++ b/test/fixtures/state-saved-v1-4.js@@ -231,7 +231,7 @@ mergedLayer0.config = {sizeField: null,sizeDomain: [0, 1],sizeScale: 'linear',- textLabel: {+ textLabel: [{field: {name: 'name',type: 'string',@@ -242,8 +242,9 @@ mergedLayer0.config = {color: [184, 15, 135, 255],size: 27,offset: [-10, 0],- anchor: 'end'- },+ anchor: 'end',+ alignment: 'center'+ }],visConfig: {radius: 12.5,fixedRadius: false,diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.jsindex 4e8a2cf10..0e0e679d0 100644--- a/test/helpers/mock-state.js+++ b/test/helpers/mock-state.js@@ -25,6 +25,7 @@ import {getInitialInputStyle} from 'reducers/map-style-updaters';import keplerGlReducer from 'reducers/core';import * as VisStateActions from 'actions/vis-state-actions';import * as MapStyleActions from 'actions/map-style-actions';+import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';// fixturesimport {testFields, testAllData} from 'test/fixtures/test-csv-data';@@ -153,17 +154,17 @@ function mockStateWithLayerDimensions(state) {f => f.name === 'date');- const textLabelPayload = [+ const textLabelPayload1 = [layer0,- {- textLabel: {- field: textLabelField,- color: [255, 0, 0],- size: 100,- offset: [10, 0],- anchor: 'start'- }- }+ 0,+ 'field',+ textLabelField+ ];+ const textLabelPayload2 = [+ layer0,+ 0,+ 'color',+ [255, 0, 0]];// layers = [ 'point', 'geojson', 'hexagon' ]@@ -180,7 +181,8 @@ function mockStateWithLayerDimensions(state) {{action: VisStateActions.layerVisConfigChange, payload: colorRangePayload},// change textLabel- {action: VisStateActions.layerConfigChange, payload: textLabelPayload},+ {action: VisStateActions.layerTextLabelChange, payload: textLabelPayload1},+ {action: VisStateActions.layerTextLabelChange, payload: textLabelPayload2},// add layer{@@ -309,13 +311,7 @@ export const expectedSavedLayer0 = {sizeAggregation: 'count',enable3d: false},- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- }+ textLabel: [DEFAULT_TEXT_LABEL]},visualChannels: {colorField: null,@@ -367,13 +363,7 @@ export const expectedLoadedLayer0 = {colorScale: 'quantile',sizeField: null,sizeScale: 'linear',- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- }+ textLabel: [DEFAULT_TEXT_LABEL]}};@@ -389,16 +379,14 @@ export const expectedSavedLayer1 = {lng: 'gps_data.lng',altitude: null},- textLabel: {+ textLabel: [{+ ...DEFAULT_TEXT_LABEL,field: {name: 'date',type: 'date'},- color: [255, 0, 0],- size: 100,- offset: [10, 0],- anchor: 'start'- },+ color: [255, 0, 0]+ }],isVisible: true,visConfig: {radius: 10,@@ -480,16 +468,14 @@ export const expectedLoadedLayer1 = {strokeColorScale: 'quantile',sizeField: null,sizeScale: 'linear',- textLabel: {+ textLabel: [{+ ...DEFAULT_TEXT_LABEL,field: {name: 'date',type: 'date'},- color: [255, 0, 0],- size: 100,- offset: [10, 0],- anchor: 'start'- }+ color: [255, 0, 0]+ }]}};@@ -537,13 +523,7 @@ export const expectedSavedLayer2 = {enable3d: false,wireframe: false},- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- }+ textLabel: [DEFAULT_TEXT_LABEL]},visualChannels: {colorField: null,@@ -613,12 +593,6 @@ export const expectedLoadedLayer2 = {heightScale: 'linear',radiusField: null,radiusScale: 'linear',- textLabel: {- field: null,- color: [255, 255, 255],- size: 50,- offset: [0, 0],- anchor: 'middle'- }+ textLabel: [DEFAULT_TEXT_LABEL]}};diff --git a/test/node/layer-tests/point-layer-specs.js b/test/node/layer-tests/point-layer-specs.jsindex 1a33ba507..c4f0667e7 100644--- a/test/node/layer-tests/point-layer-specs.js+++ b/test/node/layer-tests/point-layer-specs.js@@ -93,7 +93,10 @@ test('#PointLayer -> formatLayerData', t => {test: result => {const {layerData, layer} = result;const expectedLayerData = {- labelCharacterSet: [],+ textLabels: {+ characterSet: [],+ getText: () => {}+ },data: [{data: rows[0]@@ -108,8 +111,7 @@ test('#PointLayer -> formatLayerData', t => {getPosition: () => {},getFillColor: () => {},getLineColor: () => {},- getRadius: () => {},- getText: () => {}+ getRadius: () => {}};t.deepEqual(diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.jsindex 56775563e..035d1db0a 100644--- a/test/node/reducers/vis-state-merger-test.js+++ b/test/node/reducers/vis-state-merger-test.js@@ -292,12 +292,13 @@ test('VisStateMerger.current -> mergeLayers -> toEmptyState', t => {// load data into reducerconst stateWData = visStateReducer(mergedState, updateVisData(parsedData));+ // console.log(stateWData.layers[1].config.textLabel)// test parsed layersconst genericLayersByOrder = stateToSave.visState.layerOrder.map(idx => stateToSave.visState.layers[idx]);-+ console.log(genericLayersByOrder[1].config.textLabel)cmpLayers(t, genericLayersByOrder, stateWData.layers, {id: true});t.end();});