Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] enable tooltip formatting in interaction config (#1102)

Valentine Panchin4c51da453e5a
diff --git a/src/components/common/field-selector.js b/src/components/common/field-selector.js
index 91f4df1db..0ffc9624a 100644
--- a/src/components/common/field-selector.js
+++ b/src/components/common/field-selector.js
@@ -26,6 +26,8 @@ import {createSelector} from 'reselect';
import ItemSelector from './item-selector/item-selector';
import FieldToken from '../common/field-token';
import {classList} from './item-selector/dropdown-list';
+import {toArray} from 'utils/utils';
+import {notNullorUndefined} from 'utils/data-utils';
const defaultDisplayOption = d => d.name;
@@ -33,6 +35,7 @@ const StyledToken = styled.div`
display: inline-block;
margin: 0 4px 0 0;
`;
+
// custom list Item
export const FieldListItemFactory = (showToken = true) => {
const FieldListItem = ({value, displayOption = defaultDisplayOption}) => (
@@ -52,8 +55,14 @@ export const FieldListItemFactory = (showToken = true) => {
const SuggestedFieldHeader = () => <div>Suggested Field</div>;
const FieldType = PropTypes.oneOfType([
- PropTypes.arrayOf(PropTypes.string),
PropTypes.string,
+ PropTypes.arrayOf(PropTypes.string),
+ PropTypes.arrayOf(
+ PropTypes.shape({
+ name: PropTypes.string,
+ format: PropTypes.string
+ })
+ ),
PropTypes.shape({
format: PropTypes.string,
id: PropTypes.string,
@@ -77,7 +86,8 @@ class FieldSelector extends Component {
multiSelect: PropTypes.bool,
closeOnSelect: PropTypes.bool,
showToken: PropTypes.bool,
- suggested: PropTypes.arrayOf(PropTypes.any)
+ suggested: PropTypes.arrayOf(PropTypes.any),
+ CustomChickletComponent: PropTypes.func
};
static defaultProps = {
@@ -94,16 +104,29 @@ class FieldSelector extends Component {
};
fieldsSelector = props => props.fields;
+ filteredFieldsSelector = props =>
+ props.fields.filter(
+ field => !toArray(props.value).find(d => (d.name ? d.name === field.name : d === field.name))
+ );
valueSelector = props => props.value;
filterFieldTypesSelector = props => props.filterFieldTypes;
showTokenSelector = props => props.showToken;
selectedItemsSelector = createSelector(this.fieldsSelector, this.valueSelector, (fields, value) =>
- fields.filter(f => (Array.isArray(value) ? value : [value]).includes(defaultDisplayOption(f)))
+ fields.filter(f =>
+ Boolean(
+ toArray(value).find(d => {
+ if (!notNullorUndefined(d)) {
+ return false;
+ }
+ return d.name ? d.name === defaultDisplayOption(f) : d === defaultDisplayOption(f);
+ })
+ )
+ )
);
fieldOptionsSelector = createSelector(
- this.fieldsSelector,
+ this.filteredFieldsSelector,
this.filterFieldTypesSelector,
(fields, filterFieldTypes) => {
if (!filterFieldTypes) {
@@ -136,6 +159,7 @@ class FieldSelector extends Component {
onChange={this.props.onSelect}
DropDownLineItemRenderComponent={this.fieldListItemSelector(this.props)}
DropdownHeaderComponent={this.props.suggested ? SuggestedFieldHeader : null}
+ CustomChickletComponent={this.props.CustomChickletComponent}
/>
</div>
);
diff --git a/src/components/common/icons/hash.js b/src/components/common/icons/hash.js
new file mode 100644
index 000000000..345811d53
--- /dev/null
+++ b/src/components/common/icons/hash.js
@@ -0,0 +1,43 @@
+// Copyright (c) 2020 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, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base from './base';
+
+export default class Hash extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string
+ };
+
+ static defaultProps = {
+ height: '16px',
+ predefinedClassName: 'data-ex-icons-hash'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <path d="M33.3763 45.978H24.1434L20.3011 64H8.88889L12.7312 45.978H0V37.9341H14.4516L16.9749 26.3297H4.30108V18.2857H18.6953L22.6523 0H34.0072L30.1075 18.2857H39.3405L43.2975 0H54.7097L50.7527 18.2857H64V26.3297H49.0323L46.509 37.9341H59.6416V45.978H44.7885L40.9462 64H29.5341L33.3763 45.978ZM25.8638 37.9341H35.0968L37.6201 26.3297H28.3871L25.8638 37.9341Z" />
+ </Base>
+ );
+ }
+}
diff --git a/src/components/common/icons/index.js b/src/components/common/icons/index.js
index 1ddd9d995..016408a4d 100644
--- a/src/components/common/icons/index.js
+++ b/src/components/common/icons/index.js
@@ -51,6 +51,7 @@ export {default as Files} from './files';
export {default as FileType} from './file-type';
export {default as FilterFunnel} from './filter-funnel';
export {default as Gear} from './gear';
+export {default as Hash} from './hash';
export {default as Histogram} from './histogram';
export {default as Info} from './info';
export {default as Layers} from './layers';
diff --git a/src/components/common/item-selector/chickleted-input.js b/src/components/common/item-selector/chickleted-input.js
index 17b3e47fe..563cb79b2 100644
--- a/src/components/common/item-selector/chickleted-input.js
+++ b/src/components/common/item-selector/chickleted-input.js
@@ -40,7 +40,7 @@ const propTypes = {
inputTheme: PropTypes.string
};
-const ChickletButton = styled.div`
+export const ChickletButton = styled.div`
background: ${props => props.theme.panelActiveBg};
border-radius: 1px;
color: ${props => props.theme.textColor};
@@ -57,7 +57,7 @@ const ChickletButton = styled.div`
}
`;
-const ChickletTag = styled.span`
+export const ChickletTag = styled.span`
margin-right: 10px;
text-overflow: ellipsis;
width: 100%;
@@ -71,7 +71,7 @@ const ChickletTag = styled.span`
const Chicklet = ({disabled, name, remove}) => (
<ChickletButton>
<ChickletTag>{name}</ChickletTag>
- <Delete height="10px" onClick={disabled ? null : remove} />
+ <Delete onClick={disabled ? null : remove} />
</ChickletButton>
);
@@ -96,7 +96,8 @@ const ChickletedInput = ({
placeholder = '',
removeItem,
displayOption = d => d,
- inputTheme
+ inputTheme,
+ CustomChickletComponent
}) => (
<ChickletedInputContainer
className={`${className} chickleted-input`}
@@ -108,14 +109,23 @@ const ChickletedInput = ({
hasPlaceholder={!selectedItems || !selectedItems.length}
>
{selectedItems.length > 0 ? (
- selectedItems.map((item, i) => (
- <Chicklet
- disabled={disabled}
- key={`${displayOption(item)}_${i}`}
- name={displayOption(item)}
- remove={e => removeItem(item, e)}
- />
- ))
+ selectedItems.map((item, i) =>
+ CustomChickletComponent ? (
+ <CustomChickletComponent
+ disabled={disabled}
+ key={`${displayOption(item)}_${i}`}
+ name={displayOption(item)}
+ remove={e => removeItem(item, e)}
+ />
+ ) : (
+ <Chicklet
+ disabled={disabled}
+ key={`${displayOption(item)}_${i}`}
+ name={displayOption(item)}
+ remove={e => removeItem(item, e)}
+ />
+ )
+ )
) : (
<span className={`${className} chickleted-input__placeholder`}>
<FormattedMessage id={placeholder} />
diff --git a/src/components/common/item-selector/item-selector.js b/src/components/common/item-selector/item-selector.js
index 17b2a16b1..dc098a643 100644
--- a/src/components/common/item-selector/item-selector.js
+++ b/src/components/common/item-selector/item-selector.js
@@ -95,7 +95,8 @@ class ItemSelector extends Component {
closeOnSelect: PropTypes.bool,
DropdownHeaderComponent: PropTypes.func,
DropDownRenderComponent: PropTypes.func,
- DropDownLineItemRenderComponent: PropTypes.func
+ DropDownLineItemRenderComponent: PropTypes.func,
+ CustomChickletComponent: PropTypes.func
};
static defaultProps = {
@@ -250,6 +251,7 @@ class ItemSelector extends Component {
placeholder={this.props.placeholder}
displayOption={displayOption}
removeItem={this._removeItem}
+ CustomChickletComponent={this.props.CustomChickletComponent}
/>
) : (
<StyledDropdownSelect {...dropdownSelectProps}>
diff --git a/src/components/common/styled-components.js b/src/components/common/styled-components.js
index 3dbb89215..60211c608 100644
--- a/src/components/common/styled-components.js
+++ b/src/components/common/styled-components.js
@@ -78,6 +78,11 @@ export const SBFlexboxItem = styled.div`
margin-left: 16px;
`;
+export const SBFlexboxNoMargin = styled.div`
+ display: flex;
+ justify-content: space-between;
+`;
+
export const PanelLabel = styled.label.attrs({
className: 'side-panel-panel__label'
})`
diff --git a/src/components/map/layer-hover-info.js b/src/components/map/layer-hover-info.js
index 6275d5c0a..1b6198643 100644
--- a/src/components/map/layer-hover-info.js
+++ b/src/components/map/layer-hover-info.js
@@ -23,7 +23,7 @@ import styled from 'styled-components';
import {CenterFlexbox} from 'components/common/styled-components';
import {Layers} from 'components/common/icons';
import PropTypes from 'prop-types';
-import {parseFieldValue} from 'utils/data-utils';
+import {parseFieldValue, getFormatter} from 'utils/data-utils';
export const StyledLayerName = styled(CenterFlexbox)`
color: ${props => props.theme.textColorHl};
@@ -65,22 +65,23 @@ const Row = ({name, value, url}) => {
const EntryInfo = ({fieldsToShow, fields, data}) => (
<tbody>
- {fieldsToShow.map(name => (
- <EntryInfoRow key={name} name={name} fields={fields} data={data} />
+ {fieldsToShow.map(item => (
+ <EntryInfoRow key={item.name} item={item} fields={fields} data={data} />
))}
</tbody>
);
-const EntryInfoRow = ({name, fields, data}) => {
- const field = fields.find(f => f.name === name);
+const EntryInfoRow = ({item, fields, data}) => {
+ const field = fields.find(f => f.name === item.name);
if (!field) {
return null;
}
const valueIdx = field.tableFieldIndex - 1;
- const displayValue = parseFieldValue(data[valueIdx], field.type);
-
- return <Row name={name} value={displayValue} />;
+ const displayValue = item.format
+ ? getFormatter(item.format, field)(data[valueIdx])
+ : parseFieldValue(data[valueIdx], field.type);
+ return <Row name={item.name} value={displayValue} />;
};
const CellInfo = ({data, layer}) => {
diff --git a/src/components/side-panel/common/dataset-tag.js b/src/components/side-panel/common/dataset-tag.js
index 2abb3e7e4..d783ae5a9 100644
--- a/src/components/side-panel/common/dataset-tag.js
+++ b/src/components/side-panel/common/dataset-tag.js
@@ -45,7 +45,9 @@ export default function DatasetTagFactory() {
const DatasetTag = ({onClick, dataset}) => (
<DatasetTagWrapper className="source-data-tag" onClick={onClick}>
<DatasetSquare className="dataset-color" color={dataset.color} />
- <div className="dataset-name">{dataset.label}</div>
+ <div className="dataset-name" title={dataset.label}>
+ {dataset.label}
+ </div>
</DatasetTagWrapper>
);
diff --git a/src/components/side-panel/interaction-panel/tooltip-config.js b/src/components/side-panel/interaction-panel/tooltip-config.js
index e9147547f..a28f08a7b 100644
--- a/src/components/side-panel/interaction-panel/tooltip-config.js
+++ b/src/components/side-panel/interaction-panel/tooltip-config.js
@@ -18,40 +18,99 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React from 'react';
-import {SidePanelSection} from 'components/common/styled-components';
+import React, {Component} from 'react';
+import styled from 'styled-components';
+import {FormattedMessage} from 'react-intl';
+import {SidePanelSection, SBFlexboxNoMargin, Button} from 'components/common/styled-components';
import FieldSelector from 'components/common/field-selector';
import DatasetTagFactory from 'components/side-panel/common/dataset-tag';
+import TooltipChickletFactory from './tooltip-config/tooltip-chicklet';
TooltipConfigFactory.deps = [DatasetTagFactory];
+const TooltipConfigWrapper = styled.div`
+ .item-selector > div > div {
+ overflow: visible;
+ }
+`;
+
+const ButtonWrapper = styled.div`
+ display: inherit;
+ padding: 0;
+
+ .button.clear-all {
+ background: transparent;
+ color: ${props => props.theme.subtextColor};
+ margin: 0 0 0 8px;
+ padding: 0;
+
+ &:hover {
+ color: ${props => props.theme.textColor};
+ }
+ }
+`;
+
function TooltipConfigFactory(DatasetTag) {
- const TooltipConfig = ({config, datasets, onChange}) => (
- <div>
- {Object.keys(config.fieldsToShow).map(dataId => (
- <SidePanelSection key={dataId}>
- <DatasetTag dataset={datasets[dataId]} />
- <FieldSelector
- fields={datasets[dataId].fields}
- value={config.fieldsToShow[dataId]}
- onSelect={fieldsToShow => {
- const newConfig = {
- ...config,
- fieldsToShow: {
- ...config.fieldsToShow,
- [dataId]: fieldsToShow.map(d => d.name)
- }
- };
- onChange(newConfig);
- }}
- closeOnSelect={false}
- multiSelect
- inputTheme="secondary"
- />
- </SidePanelSection>
- ))}
- </div>
- );
+ class TooltipConfig extends Component {
+ render() {
+ const {config, datasets, onChange} = this.props;
+ return (
+ <TooltipConfigWrapper>
+ {Object.keys(config.fieldsToShow).map(dataId => (
+ <SidePanelSection key={dataId}>
+ <SBFlexboxNoMargin>
+ <DatasetTag dataset={datasets[dataId]} />
+ {Boolean(config.fieldsToShow[dataId].length) && (
+ <ButtonWrapper>
+ <Button
+ className="clear-all"
+ onClick={() => {
+ const newConfig = {
+ ...config,
+ fieldsToShow: {
+ ...config.fieldsToShow,
+ [dataId]: []
+ }
+ };
+ onChange(newConfig);
+ }}
+ width="48px"
+ secondary
+ >
+ <FormattedMessage id="fieldSelector.clearAll" />
+ </Button>
+ </ButtonWrapper>
+ )}
+ </SBFlexboxNoMargin>
+ <FieldSelector
+ fields={datasets[dataId].fields}
+ value={config.fieldsToShow[dataId]}
+ onSelect={fieldsToShow => {
+ const newConfig = {
+ ...config,
+ fieldsToShow: {
+ ...config.fieldsToShow,
+ [dataId]: fieldsToShow
+ }
+ };
+ onChange(newConfig);
+ }}
+ closeOnSelect={false}
+ multiSelect
+ inputTheme="secondary"
+ CustomChickletComponent={TooltipChickletFactory(
+ dataId,
+ config,
+ onChange,
+ datasets[dataId].fields
+ )}
+ />
+ </SidePanelSection>
+ ))}
+ </TooltipConfigWrapper>
+ );
+ }
+ }
return TooltipConfig;
}
diff --git a/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.js b/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.js
new file mode 100644
index 000000000..9c41e9df5
--- /dev/null
+++ b/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.js
@@ -0,0 +1,178 @@
+// Copyright (c) 2020 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, {Component} from 'react';
+import styled from 'styled-components';
+import {ChickletButton, ChickletTag} from 'components/common/item-selector/chickleted-input';
+import {Hash, Delete} from 'components/common/icons';
+import DropdownList from 'components/common/item-selector/dropdown-list';
+import {Tooltip} from 'components/common/styled-components';
+import {FormattedMessage} from 'react-intl';
+import onClickOutside from 'react-onclickoutside';
+import {FIELD_OPTS} from 'constants/default-settings';
+import {TOOLTIP_FORMATS, TOOLTIP_FORMAT_TYPES, TOOLTIP_KEY} from 'constants/tooltip';
+import {getFormatter} from 'utils/data-utils';
+
+const TIME_DISPLAY = '2020-05-11 14:00';
+const getValue = fmt => fmt[TOOLTIP_KEY];
+
+const addDTimeLabel = formats =>
+ formats.map(f => ({
+ ...f,
+ label:
+ f.type === TOOLTIP_FORMAT_TYPES.DATE_TIME || f.type === TOOLTIP_FORMAT_TYPES.DATE
+ ? getFormatter(getValue(f))(TIME_DISPLAY)
+ : f.label
+ }));
+
+function getFormatLabels(fields, fieldName) {
+ const fieldType = fields.find(f => f.name === fieldName).type;
+ const tooltipTypes = (fieldType && FIELD_OPTS[fieldType].format.tooltip) || [];
+ const formatLabels = Object.values(TOOLTIP_FORMATS).filter(t => tooltipTypes.includes(t.type));
+
+ return addDTimeLabel(formatLabels);
+}
+
+const ChickletAddonWrapper = styled.div`
+ position: relative;
+`;
+
+const ChickletAddon = styled.div`
+ margin-right: 4px;
+`;
+
+const StyledPopover = styled.div`
+ margin-left: -64px;
+ position: absolute;
+ top: 20px;
+ width: 140px;
+ z-index: 101;
+`;
+
+const hashStyles = {
+ SHOW: 'SHOW',
+ ACTIVE: 'ACTIVE'
+};
+
+const IconDiv = styled.div`
+ color: ${props =>
+ props.status === hashStyles.SHOW
+ ? props.theme.subtextColorActive
+ : props.status === hashStyles.ACTIVE
+ ? props.theme.activeColor
+ : props.theme.textColor};
+`;
+function TooltipChickletFactory(dataId, config, onChange, fields) {
+ class TooltipChicklet extends Component {
+ state = {
+ show: false
+ };
+
+ componentDidMount() {
+ document.addEventListener('mousedown', this.handleClickOutside, false);
+ }
+
+ componentWillUnmount() {
+ document.removeEventListener('mousedown', this.handleClickOutside, false);
+ }
+
+ handleClickOutside = e => {
+ if (this.node.contains(e.target)) {
+ return;
+ }
+ this.setState({show: false});
+ };
+
+ render() {
+ const {disabled, name, remove} = this.props;
+ const {show} = this.state;
+ const field = config.fieldsToShow[dataId].find(fieldToShow => fieldToShow.name === name);
+ const formatLabels = getFormatLabels(fields, field.name);
+ let selectionIndex = formatLabels.findIndex(fl => getValue(fl) === field.format);
+ if (selectionIndex < 0) selectionIndex = 0;
+ const hashStyle = show ? hashStyles.SHOW : selectionIndex ? hashStyles.ACTIVE : null;
+
+ return (
+ <ChickletButton ref={node => (this.node = node)}>
+ <ChickletTag>{name}</ChickletTag>
+ {formatLabels.length > 1 && (
+ <ChickletAddonWrapper>
+ <ChickletAddon data-tip data-for={`addon-${name}`}>
+ <IconDiv status={hashStyle}>
+ <Hash
+ height="8px"
+ onClick={e => {
+ e.stopPropagation();
+ this.setState({show: Boolean(!show)});
+ }}
+ />
+ </IconDiv>
+ <Tooltip id={`addon-${name}`} effect="solid">
+ <span>
+ {(selectionIndex && formatLabels[selectionIndex]).label || (
+ <FormattedMessage id={'fieldSelector.formatting'} />
+ )}
+ </span>
+ </Tooltip>
+ </ChickletAddon>
+ {show && (
+ <StyledPopover>
+ <DropdownList
+ options={formatLabels}
+ selectionIndex={selectionIndex}
+ displayOption={item => item.label}
+ onOptionSelected={(result, e) => {
+ e.stopPropagation();
+ this.setState({
+ show: false
+ });
+
+ const oldFieldsToShow = config.fieldsToShow[dataId];
+ const fieldsToShow = oldFieldsToShow.map(fieldToShow => {
+ return fieldToShow.name === name
+ ? {
+ name,
+ format: getValue(result)
+ }
+ : fieldToShow;
+ });
+ const newConfig = {
+ ...config,
+ fieldsToShow: {
+ ...config.fieldsToShow,
+ [dataId]: fieldsToShow
+ }
+ };
+ onChange(newConfig);
+ }}
+ />
+ </StyledPopover>
+ )}
+ </ChickletAddonWrapper>
+ )}
+ <Delete onClick={disabled ? null : remove} />
+ </ChickletButton>
+ );
+ }
+ }
+ return onClickOutside(TooltipChicklet);
+}
+
+export default TooltipChickletFactory;
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index ddb5cf374..58353546c 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -42,6 +42,7 @@ import {
Cancel
} from 'components/common/icons';
import {getHTMLMapModeTileUrl} from 'utils/utils';
+import {TOOLTIP_FORMAT_TYPES} from './tooltip';
export const ACTION_PREFIX = '@@kepler.gl/';
export const CLOUDFRONT = 'https://d1a3f4spazzrp4.cloudfront.net/kepler.gl';
@@ -522,7 +523,8 @@ export const FIELD_OPTS = {
...ordinalFieldAggrScaleFunctions
},
format: {
- legend: d => d
+ legend: d => d,
+ tooltip: []
}
},
real: {
@@ -532,7 +534,8 @@ export const FIELD_OPTS = {
...linearFieldAggrScaleFunctions
},
format: {
- legend: d => d
+ legend: d => d,
+ tooltip: [TOOLTIP_FORMAT_TYPES.DECIMAL, TOOLTIP_FORMAT_TYPES.PERCENTAGE]
}
},
timestamp: {
@@ -542,7 +545,8 @@ export const FIELD_OPTS = {
...notSupportAggrOpts
},
format: {
- legend: d => d
+ legend: d => d,
+ tooltip: [TOOLTIP_FORMAT_TYPES.DATE, TOOLTIP_FORMAT_TYPES.DATE_TIME]
}
},
integer: {
@@ -552,7 +556,8 @@ export const FIELD_OPTS = {
...linearFieldAggrScaleFunctions
},
format: {
- legend: d => d
+ legend: d => d,
+ tooltip: [TOOLTIP_FORMAT_TYPES.DECIMAL, TOOLTIP_FORMAT_TYPES.PERCENTAGE]
}
},
boolean: {
@@ -562,7 +567,8 @@ export const FIELD_OPTS = {
...ordinalFieldAggrScaleFunctions
},
format: {
- legend: d => d
+ legend: d => d,
+ tooltip: []
}
},
date: {
@@ -571,7 +577,8 @@ export const FIELD_OPTS = {
...ordinalFieldAggrScaleFunctions
},
format: {
- legend: d => d
+ legend: d => d,
+ tooltip: [TOOLTIP_FORMAT_TYPES.DATE]
}
},
geojson: {
@@ -581,7 +588,8 @@ export const FIELD_OPTS = {
...notSupportAggrOpts
},
format: {
- legend: d => '...'
+ legend: d => '...',
+ tooltip: []
}
}
};
diff --git a/src/constants/tooltip.js b/src/constants/tooltip.js
new file mode 100644
index 000000000..a08867bf0
--- /dev/null
+++ b/src/constants/tooltip.js
@@ -0,0 +1,171 @@
+// Copyright (c) 2020 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.
+
+export const TOOLTIP_FORMAT_TYPES = {
+ DATE: 'date',
+ DATE_TIME: 'date_time',
+ DECIMAL: 'decimal',
+ PERCENTAGE: 'percentage'
+};
+
+export const TOOLTIP_KEY = 'format';
+
+export const TOOLTIP_FORMATS = {
+ NONE: {
+ id: 'NONE',
+ label: 'None'
+ },
+ DECIMAL_SHORT: {
+ id: 'DECIMAL_SHORT',
+ label: '10k',
+ format: '.1s',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_SHORT_COMMA: {
+ id: 'DECIMAL_SHORT_COMMA',
+ label: '12.3k',
+ format: '.3s',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_PERCENT_FULL_1: {
+ id: 'DECIMAL_PERCENT_FULL_1',
+ label: '.01 → 1.0%',
+ format: '.1%',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_PERCENT_FULL_2: {
+ id: 'DECIMAL_PERCENT_FULL_2',
+ label: '.01 → 1.00%',
+ format: '.2%',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_PRECENT_REGULAR: {
+ id: 'DECIMAL_PRECENT_REGULAR',
+ label: '12.345 → 12.35%',
+ format: '.2f',
+ type: TOOLTIP_FORMAT_TYPES.PERCENTAGE
+ },
+ DECIMAL_DECIMAL_FIXED_2: {
+ id: 'DECIMAL_DECIMAL_FIXED_2',
+ label: '1.23',
+ format: '.2f',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_DECIMAL_FIXED_3: {
+ id: 'DECIMAL_DECIMAL_FIXED_3',
+ label: '1.234',
+ format: '.3f',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_INT: {
+ id: 'DECIMAL_INT',
+ label: '12350',
+ format: '.4r',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_THREE: {
+ id: 'DECIMAL_THREE',
+ label: '12,345.432',
+ format: ',.3f',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_DELTA: {
+ id: 'DECIMAL_DELTA',
+ label: '+12,345.432',
+ format: '+,',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DECIMAL_CURRENCY: {
+ id: 'DECIMAL_CURRENCY',
+ label: '$12,345.43',
+ format: '$,.2f',
+ type: TOOLTIP_FORMAT_TYPES.DECIMAL
+ },
+ DATE_L: {
+ // 05/29/2020
+ id: 'DATE_L',
+ label: '',
+ format: 'L',
+ type: TOOLTIP_FORMAT_TYPES.DATE
+ },
+ DATE_LL: {
+ // September 5 2016
+ id: 'DATE_LL',
+ label: '',
+ format: 'LL',
+ type: TOOLTIP_FORMAT_TYPES.DATE
+ },
+ DATE_dddd_LL: {
+ // Monday September 5, 2016
+ id: 'DATE_dddd_LL',
+ label: '',
+ format: 'dddd LL',
+ type: TOOLTIP_FORMAT_TYPES.DATE
+ },
+ DATE_ddd_LL: {
+ // Mon September 5, 2016
+ id: 'DATE_ddd_LL',
+ label: '',
+ format: 'ddd LL',
+ type: TOOLTIP_FORMAT_TYPES.DATE
+ },
+ DATE_TIME_L_LT: {
+ // 09/05/2016 12:00 AM
+ id: 'DATE_TIME_L_LT',
+ label: '',
+ format: 'L LT',
+ type: TOOLTIP_FORMAT_TYPES.DATE_TIME
+ },
+ DATE_TIME_L_LTS: {
+ // 09/05/2016 12:00:00 AM
+ id: 'DATE_TIME_L_LTS',
+ label: '',
+ format: 'L LTS',
+ type: TOOLTIP_FORMAT_TYPES.DATE_TIME
+ },
+ DATE_TIME_LLL: {
+ // September 5, 2016 12:00 AM
+ id: 'DATE_TIME_LLL',
+ label: '',
+ format: 'LLL',
+ type: TOOLTIP_FORMAT_TYPES.DATE_TIME
+ },
+ DATE_TIME_LL_LTS: {
+ // September 5, 2016 12:00:00 AM
+ id: 'DATE_TIME_LL_LTS',
+ label: '',
+ format: 'LL LTS',
+ type: TOOLTIP_FORMAT_TYPES.DATE_TIME
+ },
+ DATE_TIME_ddd_LLL: {
+ // Mon September 5, 2016 12:00 AM
+ id: 'DATE_TIME_ddd_LLL',
+ label: '',
+ format: 'ddd LLL',
+ type: TOOLTIP_FORMAT_TYPES.DATE_TIME
+ },
+ DATE_TIME_LTS: {
+ // 12:00:00 AM
+ id: 'DATE_TIME',
+ label: '',
+ format: 'LTS',
+ type: TOOLTIP_FORMAT_TYPES.DATE_TIME
+ }
+};
diff --git a/src/localization/en.js b/src/localization/en.js
index bd0b367f1..498025520 100644
--- a/src/localization/en.js
+++ b/src/localization/en.js
@@ -437,6 +437,10 @@ export default {
geocoder: {
title: 'Geocoder'
},
+ fieldSelector: {
+ clearAll: 'Clear All',
+ formatting: 'Formatting'
+ },
density: 'density',
'Bug Report': 'Bug Report',
'User Guide': 'User Guide',
diff --git a/src/reducers/vis-state-merger.js b/src/reducers/vis-state-merger.js
index 170e31439..4bc685581 100644
--- a/src/reducers/vis-state-merger.js
+++ b/src/reducers/vis-state-merger.js
@@ -301,8 +301,8 @@ export function mergeInteractionTooltipConfig(state, tooltipConfig = {}) {
} else {
// if dataset is loaded
const allFields = state.datasets[dataId].fields.map(d => d.name);
- const foundFieldsToShow = tooltipConfig.fieldsToShow[dataId].filter(name =>
- allFields.includes(name)
+ const foundFieldsToShow = tooltipConfig.fieldsToShow[dataId].filter(field =>
+ allFields.includes(field.name)
);
mergedTooltip[dataId] = foundFieldsToShow;
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
index f8a7af925..82a391f1c 100644
--- a/src/reducers/vis-state-updaters.d.ts
+++ b/src/reducers/vis-state-updaters.d.ts
@@ -228,10 +228,14 @@ type BaseInteraction = {
enabled: boolean;
iconComponent: any;
};
+type TooltipField = {
+ name: string;
+ format: string | null;
+}
export type Tooltip = BaseInteraction & {
config: {
fieldsToShow: {
- [key: string]: string[];
+ [key: string]: TooltipField[];
};
};
};
diff --git a/src/schemas/vis-state-schema.js b/src/schemas/vis-state-schema.js
index 3442d2767..2c7dda08b 100644
--- a/src/schemas/vis-state-schema.js
+++ b/src/schemas/vis-state-schema.js
@@ -24,6 +24,7 @@ import {isValidFilterValue} from 'utils/filter-utils';
import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';
import Schema from './schema';
import cloneDeep from 'lodash.clonedeep';
+import {notNullorUndefined} from 'utils/data-utils';
/**
* V0 Schema
@@ -579,7 +580,28 @@ class InteractionSchemaV1 extends Schema {
: {};
}
load(interactionConfig) {
- return {[this.key]: interactionConfig};
+ const modifiedConfig = interactionConfig;
+ Object.keys(interactionConfig).forEach(configType => {
+ if (configType === 'tooltip') {
+ const fieldsToShow = modifiedConfig[configType].fieldsToShow;
+ if (!notNullorUndefined(fieldsToShow)) {
+ return {[this.key]: modifiedConfig};
+ }
+ Object.keys(fieldsToShow).forEach(key => {
+ fieldsToShow[key] = fieldsToShow[key].map(fieldData => {
+ if (!fieldData.name) {
+ return {
+ name: fieldData,
+ format: null
+ };
+ }
+ return fieldData;
+ });
+ });
+ }
+ return;
+ });
+ return {[this.key]: modifiedConfig};
}
}
diff --git a/src/utils/data-utils.js b/src/utils/data-utils.js
index 367ca95ab..38eebb16c 100644
--- a/src/utils/data-utils.js
+++ b/src/utils/data-utils.js
@@ -21,6 +21,8 @@
import moment from 'moment';
import assert from 'assert';
import {ALL_FIELD_TYPES} from 'constants/default-settings';
+import {TOOLTIP_FORMATS, TOOLTIP_FORMAT_TYPES, TOOLTIP_KEY} from 'constants/tooltip';
+import {format as d3Format} from 'd3-format';
const MAX_LATITUDE = 90;
const MIN_LATITUDE = -90;
@@ -289,3 +291,51 @@ export function findFirstNoneEmpty(data, count = 1, getValue = identity) {
}
return found;
}
+
+export function getFormatter(format, field) {
+ const defaultFormatter = v => v;
+ if (!format) {
+ return defaultFormatter;
+ }
+ const tooltipFormat = Object.values(TOOLTIP_FORMATS).find(f => f[TOOLTIP_KEY] === format);
+
+ if (tooltipFormat) {
+ return applyDefaultFormat(tooltipFormat);
+ } else if (typeof format === 'string' && field) {
+ return applyCustomFormat(format, field);
+ }
+
+ return defaultFormatter;
+}
+
+export function applyDefaultFormat(tooltipFormat) {
+ if (!tooltipFormat || !tooltipFormat.format) {
+ return v => v;
+ }
+
+ switch (tooltipFormat.type) {
+ case TOOLTIP_FORMAT_TYPES.DECIMAL:
+ return d3Format(tooltipFormat.format);
+ case TOOLTIP_FORMAT_TYPES.DATE:
+ case TOOLTIP_FORMAT_TYPES.DATE_TIME:
+ return v => moment.utc(v).format(tooltipFormat.format);
+ case TOOLTIP_FORMAT_TYPES.PERCENTAGE:
+ return v => `${d3Format(tooltipFormat.format)(v)}%`;
+ default:
+ return v => v;
+ }
+}
+
+// Allow user to specify custom tooltip format via config
+export function applyCustomFormat(format, field) {
+ switch (field.type) {
+ case ALL_FIELD_TYPES.real:
+ case ALL_FIELD_TYPES.integer:
+ return d3Format(format);
+ case ALL_FIELD_TYPES.date:
+ case ALL_FIELD_TYPES.timestamp:
+ return v => moment.utc(v).format(format);
+ default:
+ return v => v;
+ }
+}
diff --git a/src/utils/interaction-utils.js b/src/utils/interaction-utils.js
index 217007141..512f61d30 100644
--- a/src/utils/interaction-utils.js
+++ b/src/utils/interaction-utils.js
@@ -77,7 +77,7 @@ export const BRUSH_CONFIG = {
export function findFieldsToShow({fields, id}) {
// first find default tooltip fields for trips
const fieldsToShow = DEFAULT_TOOLTIP_FIELDS.reduce((prev, curr) => {
- if (fields.find(({name}) => curr === name)) {
+ if (fields.find(({name}) => curr.name === name)) {
prev.push(curr);
}
return prev;
@@ -102,7 +102,12 @@ function autoFindTooltipFields(fields) {
type !== 'object'
);
- return fieldsToShow.slice(0, MAX_DEFAULT_TOOLTIPS).map(d => d.name);
+ return fieldsToShow.slice(0, MAX_DEFAULT_TOOLTIPS).map(({name}) => {
+ return {
+ name,
+ format: null
+ };
+ });
}
function _mergeFieldPairs(pairs) {
diff --git a/test/browser/components/index.js b/test/browser/components/index.js
index 720537e2e..61c6d0d25 100644
--- a/test/browser/components/index.js
+++ b/test/browser/components/index.js
@@ -36,3 +36,4 @@ import './common';
import './editor';
import './map-container-test';
import './geocoder-panel-test';
+import './tooltip-config-test';
diff --git a/test/browser/components/tooltip-config-test.js b/test/browser/components/tooltip-config-test.js
new file mode 100644
index 000000000..e23a3b0b9
--- /dev/null
+++ b/test/browser/components/tooltip-config-test.js
@@ -0,0 +1,64 @@
+// Copyright (c) 2020 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 from 'react';
+import sinon from 'sinon';
+import test from 'tape';
+import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
+import TooltipConfigFactory from 'components/side-panel/interaction-panel/tooltip-config';
+import {StateWTrips} from 'test/helpers/mock-state';
+
+test('TooltipConfig - render', t => {
+ const DataSetTag = () => <div className="dataset-tag" />;
+ const TooltipConfig = TooltipConfigFactory(DataSetTag);
+ const datasets = StateWTrips.visState.datasets;
+ const config = {
+ fieldsToShow: {
+ test_trip_data: [
+ {
+ name: 'tpep_pickup_datetime',
+ format: null
+ },
+ {
+ name: 'tpep_dropoff_datetime',
+ format: null
+ },
+ {
+ name: 'fare_amount',
+ format: null
+ }
+ ]
+ },
+ enabled: true
+ };
+ const onChange = sinon.spy();
+ let wrapper;
+
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <IntlWrapper>
+ <TooltipConfig onChange={onChange} config={config} datasets={datasets} />
+ </IntlWrapper>
+ );
+ }, 'Should render');
+
+ t.equal(wrapper.find(TooltipConfig).length, 1, 'Should display 1 TooltipConfig');
+ t.end();
+});
diff --git a/test/fixtures/config_v0_arc_cluster_point.js b/test/fixtures/config_v0_arc_cluster_point.js
index ff1670b4d..9aa9510f3 100644
--- a/test/fixtures/config_v0_arc_cluster_point.js
+++ b/test/fixtures/config_v0_arc_cluster_point.js
@@ -476,7 +476,16 @@ export const parsedConfigV0 = {
tooltip: {
enabled: true,
fieldsToShow: {
- something: ['begintrip_timestamp_local', 'dropoff_timestamp_local']
+ something: [
+ {
+ name: 'begintrip_timestamp_local',
+ format: null
+ },
+ {
+ name: 'dropoff_timestamp_local',
+ format: null
+ }
+ ]
}
},
brush: {
diff --git a/test/fixtures/config_v0_geojson_point.js b/test/fixtures/config_v0_geojson_point.js
index 7d66ceae1..40795bf11 100644
--- a/test/fixtures/config_v0_geojson_point.js
+++ b/test/fixtures/config_v0_geojson_point.js
@@ -163,7 +163,24 @@ export const parsedConfigV0 = {
tooltip: {
enabled: true,
fieldsToShow: {
- '9sayb4m9r': ['fillColor', 'hi-precision', 'addresses', 'id']
+ '9sayb4m9r': [
+ {
+ name: 'fillColor',
+ format: null
+ },
+ {
+ name: 'hi-precision',
+ format: null
+ },
+ {
+ name: 'addresses',
+ format: null
+ },
+ {
+ name: 'id',
+ format: null
+ }
+ ]
}
},
brush: {
diff --git a/test/fixtures/config_v0_geojson_poly_fill_ele.js b/test/fixtures/config_v0_geojson_poly_fill_ele.js
index 0deacb855..f8c5b0479 100644
--- a/test/fixtures/config_v0_geojson_poly_fill_ele.js
+++ b/test/fixtures/config_v0_geojson_poly_fill_ele.js
@@ -142,7 +142,16 @@ export const parsedConfigV0 = {
tooltip: {
enabled: true,
fieldsToShow: {
- c0pd4bocg: ['ZIP_CODE', 'ID']
+ c0pd4bocg: [
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ }
+ ]
}
},
brush: {
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index 012347e2c..8921f1df5 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -1469,8 +1469,30 @@ export const mergedInteractions = {
enabled: true,
config: {
fieldsToShow: {
- '9h10t7fyb': ['int_range', 'detail', 'type_boolean'],
- v79816te8: ['ID', 'ZIP_CODE']
+ '9h10t7fyb': [
+ {
+ name: 'int_range',
+ format: null
+ },
+ {
+ name: 'detail',
+ format: null
+ },
+ {
+ name: 'type_boolean',
+ format: null
+ }
+ ],
+ v79816te8: [
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ }
+ ]
}
}
}
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index 6c29aff25..0971fc624 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -2774,7 +2774,20 @@ export const mergedInteraction = {
enabled: false,
config: {
fieldsToShow: {
- a5ybmwl2d: ['a_zip', 'str_type', 'int_type']
+ a5ybmwl2d: [
+ {
+ name: 'a_zip',
+ format: null
+ },
+ {
+ name: 'str_type',
+ format: null
+ },
+ {
+ name: 'int_type',
+ format: null
+ }
+ ]
}
}
},
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index 37448e3c7..a31046d40 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -374,6 +374,28 @@ function mockStateWithSplitMaps(state) {
return prepareState;
}
+function mockStateWithTooltipFormat() {
+ const initialState = mockStateWithFileUpload();
+
+ const oldConfig = initialState.visState.interactionConfig.tooltip;
+ const newConfig = {
+ ...oldConfig,
+ config: {
+ ...oldConfig.config,
+ fieldsToShow: {
+ ...oldConfig.config.fieldsToShow,
+ [testCsvDataId]: [{name: 'gps_data.utc_timestamp', format: 'LL'}]
+ }
+ }
+ };
+
+ const prepareState = applyActions(keplerGlReducer, initialState, [
+ {action: VisStateActions.interactionConfigChange, payload: [newConfig]}
+ ]);
+
+ return prepareState;
+}
+
// saved hexagon layer
export const expectedSavedLayer0 = {
id: 'hexagon-2',
@@ -652,6 +674,7 @@ export const StateWCustomMapStyle = mockStateWithCustomMapStyle();
export const StateWSplitMaps = mockStateWithSplitMaps();
export const StateWTrips = mockStateWithTripData();
export const StateWTripGeojson = mockStateWithTripGeojson();
+export const StateWTooltipFormat = mockStateWithTooltipFormat();
export const expectedSavedTripLayer = {
id: 'trip-0',
diff --git a/test/node/reducers/composer-state-test.js b/test/node/reducers/composer-state-test.js
index a39965730..ef98dd8d2 100644
--- a/test/node/reducers/composer-state-test.js
+++ b/test/node/reducers/composer-state-test.js
@@ -232,7 +232,16 @@ test('#composerStateReducer - addDataToMapUpdater: keepExistingConfig', t => {
config: {
fieldsToShow: {
...oldInteractionConfig.tooltip.config.fieldsToShow,
- [hexDataId]: ['hex_id', 'value']
+ [hexDataId]: [
+ {
+ name: 'hex_id',
+ format: null
+ },
+ {
+ name: 'value',
+ format: null
+ }
+ ]
}
}
}
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index 562629d78..053ae091f 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -504,8 +504,30 @@ test('VisStateMerger.v0 -> mergeInteractions -> toEmptyState', t => {
{
tooltip: {
fieldsToShow: {
- '9h10t7fyb': ['int_range', 'detail', 'type_boolean'],
- v79816te8: ['ID', 'ZIP_CODE']
+ '9h10t7fyb': [
+ {
+ name: 'int_range',
+ format: null
+ },
+ {
+ name: 'detail',
+ format: null
+ },
+ {
+ name: 'type_boolean',
+ format: null
+ }
+ ],
+ v79816te8: [
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ }
+ ]
},
enabled: true
}
@@ -545,7 +567,24 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {
...oldVisState.interactionToBeMerged,
tooltip: {
fieldsToShow: {
- milkshake: ['have', 'a', 'good', 'day']
+ milkshake: [
+ {
+ name: 'have',
+ format: null
+ },
+ {
+ name: 'a',
+ format: null
+ },
+ {
+ name: 'good',
+ format: null
+ },
+ {
+ name: 'day',
+ format: null
+ }
+ ]
}
}
};
@@ -560,8 +599,30 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {
const expectedInteractionToBeMerged = {
tooltip: {
fieldsToShow: {
- '9h10t7fyb': ['int_range', 'detail', 'type_boolean'],
- v79816te8: ['ID', 'ZIP_CODE']
+ '9h10t7fyb': [
+ {
+ name: 'int_range',
+ format: null
+ },
+ {
+ name: 'detail',
+ format: null
+ },
+ {
+ name: 'type_boolean',
+ format: null
+ }
+ ],
+ v79816te8: [
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ }
+ ]
},
enabled: true
}
@@ -593,15 +654,73 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {
config: {
fieldsToShow: {
[testCsvDataId]: [
- 'gps_data.utc_timestamp',
- 'gps_data.types',
- 'epoch',
- 'has_result',
- 'id'
+ {
+ name: 'gps_data.utc_timestamp',
+ format: null
+ },
+ {
+ name: 'gps_data.types',
+ format: null
+ },
+ {
+ name: 'epoch',
+ format: null
+ },
+ {
+ name: 'has_result',
+ format: null
+ },
+ {
+ name: 'id',
+ format: null
+ }
],
- [testGeoJsonDataId]: ['OBJECTID', 'ZIP_CODE', 'ID', 'TRIPS', 'RATE'],
- '9h10t7fyb': ['int_range', 'detail', 'type_boolean'],
- v79816te8: ['ID', 'ZIP_CODE']
+ [testGeoJsonDataId]: [
+ {
+ name: 'OBJECTID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'TRIPS',
+ format: null
+ },
+ {
+ name: 'RATE',
+ format: null
+ }
+ ],
+ '9h10t7fyb': [
+ {
+ name: 'int_range',
+ format: null
+ },
+ {
+ name: 'detail',
+ format: null
+ },
+ {
+ name: 'type_boolean',
+ format: null
+ }
+ ],
+ v79816te8: [
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ }
+ ]
}
}
}
@@ -633,7 +752,20 @@ test('VisStateMerger.v1 -> mergeInteractions -> toEmptyState', t => {
{
tooltip: {
fieldsToShow: {
- a5ybmwl2d: ['a_zip', 'str_type', 'int_type']
+ a5ybmwl2d: [
+ {
+ name: 'a_zip',
+ format: null
+ },
+ {
+ name: 'str_type',
+ format: null
+ },
+ {
+ name: 'int_type',
+ format: null
+ }
+ ]
},
enabled: false
}
@@ -689,7 +821,24 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
...oldVisState.interactionToBeMerged,
tooltip: {
fieldsToShow: {
- milkshake: ['have', 'a', 'good', 'day']
+ milkshake: [
+ {
+ name: 'have',
+ format: null
+ },
+ {
+ name: 'a',
+ format: null
+ },
+ {
+ name: 'good',
+ format: null
+ },
+ {
+ name: 'day',
+ format: null
+ }
+ ]
}
}
};
@@ -705,7 +854,20 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
const expectedInteractionToBeMerged = {
tooltip: {
fieldsToShow: {
- a5ybmwl2d: ['a_zip', 'str_type', 'int_type']
+ a5ybmwl2d: [
+ {
+ name: 'a_zip',
+ format: null
+ },
+ {
+ name: 'str_type',
+ format: null
+ },
+ {
+ name: 'int_type',
+ format: null
+ }
+ ]
},
enabled: false
}
@@ -729,13 +891,49 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
config: {
fieldsToShow: {
[testCsvDataId]: [
- 'gps_data.utc_timestamp',
- 'gps_data.types',
- 'epoch',
- 'has_result',
- 'id'
+ {
+ name: 'gps_data.utc_timestamp',
+ format: null
+ },
+ {
+ name: 'gps_data.types',
+ format: null
+ },
+ {
+ name: 'epoch',
+ format: null
+ },
+ {
+ name: 'has_result',
+ format: null
+ },
+ {
+ name: 'id',
+ format: null
+ }
],
- [testGeoJsonDataId]: ['OBJECTID', 'ZIP_CODE', 'ID', 'TRIPS', 'RATE']
+ [testGeoJsonDataId]: [
+ {
+ name: 'OBJECTID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'TRIPS',
+ format: null
+ },
+ {
+ name: 'RATE',
+ format: null
+ }
+ ]
}
}
},
@@ -773,14 +971,63 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
config: {
fieldsToShow: {
[testCsvDataId]: [
- 'gps_data.utc_timestamp',
- 'gps_data.types',
- 'epoch',
- 'has_result',
- 'id'
+ {
+ name: 'gps_data.utc_timestamp',
+ format: null
+ },
+ {
+ name: 'gps_data.types',
+ format: null
+ },
+ {
+ name: 'epoch',
+ format: null
+ },
+ {
+ name: 'has_result',
+ format: null
+ },
+ {
+ name: 'id',
+ format: null
+ }
],
- [testGeoJsonDataId]: ['OBJECTID', 'ZIP_CODE', 'ID', 'TRIPS', 'RATE'],
- a5ybmwl2d: ['a_zip', 'str_type', 'int_type']
+ [testGeoJsonDataId]: [
+ {
+ name: 'OBJECTID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'TRIPS',
+ format: null
+ },
+ {
+ name: 'RATE',
+ format: null
+ }
+ ],
+ a5ybmwl2d: [
+ {
+ name: 'a_zip',
+ format: null
+ },
+ {
+ name: 'str_type',
+ format: null
+ },
+ {
+ name: 'int_type',
+ format: null
+ }
+ ]
}
}
},
@@ -862,7 +1109,28 @@ test('VisStateMerger.v1 -> mergeInteractions -> coordinate', t => {
enabled: false,
config: {
fieldsToShow: {
- a5ybmwl2d: ['a_zip', 'zip_area', 'avg_number', 'str_type', 'int_type']
+ a5ybmwl2d: [
+ {
+ name: 'a_zip',
+ format: null
+ },
+ {
+ name: 'zip_area',
+ format: null
+ },
+ {
+ name: 'avg_number',
+ format: null
+ },
+ {
+ name: 'str_type',
+ format: null
+ },
+ {
+ name: 'int_type',
+ format: null
+ }
+ ]
}
}
},
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index b315011cc..4270716cb 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -2417,7 +2417,28 @@ test('#visStateReducer -> REMOVE_DATASET w filter and layer', t => {
iconComponent: oldState.interactionConfig.tooltip.iconComponent,
config: {
fieldsToShow: {
- [testGeoJsonDataId]: ['OBJECTID', 'ZIP_CODE', 'ID', 'TRIPS', 'RATE']
+ [testGeoJsonDataId]: [
+ {
+ name: 'OBJECTID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'TRIPS',
+ format: null
+ },
+ {
+ name: 'RATE',
+ format: null
+ }
+ ]
}
}
},
@@ -2630,11 +2651,26 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
config: {
fieldsToShow: {
[testCsvDataId]: [
- 'gps_data.utc_timestamp',
- 'gps_data.types',
- 'epoch',
- 'has_result',
- 'id'
+ {
+ name: 'gps_data.utc_timestamp',
+ format: null
+ },
+ {
+ name: 'gps_data.types',
+ format: null
+ },
+ {
+ name: 'epoch',
+ format: null
+ },
+ {
+ name: 'has_result',
+ format: null
+ },
+ {
+ name: 'id',
+ format: null
+ }
]
}
}
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index b15ffc566..3d1f7d03d 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -25,6 +25,7 @@ import SchemaManager from 'schemas';
import {
StateWFilesFiltersLayerColor,
+ StateWTooltipFormat,
expectedSavedLayer0,
expectedLoadedLayer0,
expectedSavedLayer1,
@@ -131,8 +132,105 @@ test('#visStateSchema -> v1 -> save load interaction', t => {
tooltip: {
enabled: true,
fieldsToShow: {
- [testCsvDataId]: ['gps_data.utc_timestamp', 'gps_data.types', 'epoch', 'has_result', 'id'],
- [testGeoJsonDataId]: ['OBJECTID', 'ZIP_CODE', 'ID', 'TRIPS', 'RATE']
+ [testCsvDataId]: [
+ {
+ name: 'gps_data.utc_timestamp',
+ format: null
+ },
+ {
+ name: 'gps_data.types',
+ format: null
+ },
+ {
+ name: 'epoch',
+ format: null
+ },
+ {
+ name: 'has_result',
+ format: null
+ },
+ {
+ name: 'id',
+ format: null
+ }
+ ],
+ [testGeoJsonDataId]: [
+ {
+ name: 'OBJECTID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'TRIPS',
+ format: null
+ },
+ {
+ name: 'RATE',
+ format: null
+ }
+ ]
+ }
+ },
+ brush: {
+ enabled: false,
+ size: 0.5
+ },
+ coordinate: {
+ enabled: false
+ },
+ geocoder: {
+ enabled: false
+ }
+ };
+
+ t.deepEqual(interactionToSave, expectedSaved);
+ t.deepEqual(interactionLoaded, expectedSaved);
+
+ t.end();
+});
+
+test('#visStateSchema -> v1 -> save load interaction -> tooltip format', t => {
+ const initialState = cloneDeep(StateWTooltipFormat);
+ const savedState = SchemaManager.getConfigToSave(initialState);
+
+ // save state
+ const interactionToSave = savedState.config.visState.interactionConfig;
+ const interactionLoaded = SchemaManager.parseSavedConfig(savedState).visState.interactionConfig;
+
+ const expectedSaved = {
+ tooltip: {
+ enabled: true,
+ fieldsToShow: {
+ [testCsvDataId]: [{name: 'gps_data.utc_timestamp', format: 'LL'}],
+ [testGeoJsonDataId]: [
+ {
+ name: 'OBJECTID',
+ format: null
+ },
+ {
+ name: 'ZIP_CODE',
+ format: null
+ },
+ {
+ name: 'ID',
+ format: null
+ },
+ {
+ name: 'TRIPS',
+ format: null
+ },
+ {
+ name: 'RATE',
+ format: null
+ }
+ ]
}
},
brush: {
diff --git a/test/node/utils/interaction-utils-test.js b/test/node/utils/interaction-utils-test.js
index f2d3400d4..7c038e280 100644
--- a/test/node/utils/interaction-utils-test.js
+++ b/test/node/utils/interaction-utils-test.js
@@ -77,7 +77,16 @@ test('interactionUtil -> findFieldsToShow', t => {
]
];
- const expectedFields = ['random', 'something_else'];
+ const expectedFields = [
+ {
+ name: 'random',
+ format: null
+ },
+ {
+ name: 'something_else',
+ format: null
+ }
+ ];
t.deepEqual(
findFieldsToShow({fields: someFields, id: dataId}),
@@ -89,7 +98,30 @@ test('interactionUtil -> findFieldsToShow', t => {
});
test('interactionUtil -> autoFindTooltipFields', t => {
- const expectedFields = {test: ['hex_id', 'a', 'b', 'c', 'd']};
+ const expectedFields = {
+ test: [
+ {
+ name: 'hex_id',
+ format: null
+ },
+ {
+ name: 'a',
+ format: null
+ },
+ {
+ name: 'b',
+ format: null
+ },
+ {
+ name: 'c',
+ format: null
+ },
+ {
+ name: 'd',
+ format: null
+ }
+ ]
+ };
t.deepEqual(
findFieldsToShow({fields, id: 'test'}),