Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] allow tooltip format to apply to aggregation layer hover #1872

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 35 additions & 7 deletions src/components/map/layer-hover-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import React from 'react';
import React, {useMemo} from 'react';
import styled from 'styled-components';
import {TooltipField} from 'reducers/vis-state-updaters';
import {CenterFlexbox} from 'components/common/styled-components';
import {Layers} from 'components/common/icons';
import PropTypes from 'prop-types';
import {notNullorUndefined} from 'utils/data-utils';
import {getTooltipDisplayValue, getTooltipDisplayDeltaValue} from 'utils/interaction-utils';
import {AggregationLayerHoverData} from 'utils/layer-utils';
import {Layer} from 'layers';

export const StyledLayerName = styled(CenterFlexbox)`
color: ${props => props.theme.textColorHl};
Expand Down Expand Up @@ -114,7 +117,8 @@ const EntryInfoRow = ({item, fields, data, primaryData, compareType}) => {
return null;
}
const field = fields[fieldIdx];
const displayValue = getTooltipDisplayValue({item, field, data, fieldIdx});
const value = data.valueAt(fieldIdx);
const displayValue = getTooltipDisplayValue({item, field, value});

const displayDeltaValue = getTooltipDisplayDeltaValue({
item,
Expand All @@ -135,24 +139,48 @@ const EntryInfoRow = ({item, fields, data, primaryData, compareType}) => {
};

// TODO: supporting comparative value for aggregated cells as well
const CellInfo = ({data, layer}) => {
const {colorField, sizeField} = layer.config;
const CellInfo = ({
fieldsToShow,
data,
layer
}: {
data: AggregationLayerHoverData;
fieldsToShow: TooltipField[];
layer: Layer;
}) => {
const {colorField, sizeField} = layer.config as any;

const colorValue = useMemo(() => {
if (colorField && layer.visualChannels.color) {
const item = fieldsToShow.find(field => field.name === colorField.name);
return getTooltipDisplayValue({item, field: colorField, value: data.colorValue});
}
return null;
}, [fieldsToShow, colorField, layer, data.colorValue]);

const elevationValue = useMemo(() => {
if (sizeField && layer.visualChannels.size) {
const item = fieldsToShow.find(field => field.name === sizeField.name);
return getTooltipDisplayValue({item, field: sizeField, value: data.elevationValue});
}
return null;
}, [fieldsToShow, sizeField, layer, data.elevationValue]);

return (
<tbody>
<Row name={'total points'} key="count" value={data.points && data.points.length} />
<Row name={'total points'} key="count" value={String(data.points && data.points.length)} />
{colorField && layer.visualChannels.color ? (
<Row
name={layer.getVisualChannelDescription('color').measure}
key="color"
value={data.colorValue || 'N/A'}
value={colorValue || 'N/A'}
/>
) : null}
{sizeField && layer.visualChannels.size ? (
<Row
name={layer.getVisualChannelDescription('size').measure}
key="size"
value={data.elevationValue || 'N/A'}
value={elevationValue || 'N/A'}
/>
) : null}
</tbody>
Expand Down
17 changes: 7 additions & 10 deletions src/utils/interaction-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,17 @@ export function getTooltipDisplayDeltaValue({
export function getTooltipDisplayValue({
item,
field,
data,
fieldIdx
value
}: {
item: TooltipField;
item: TooltipField | undefined;
field: Field;
data: DataRow;
fieldIdx: number;
value: any;
}): string {
const dataValue = data.valueAt(fieldIdx);
if (!notNullorUndefined(dataValue)) {
if (!notNullorUndefined(value)) {
return '';
}

return item.format
? getFormatter(item.format, field)(dataValue)
: parseFieldValue(dataValue, field.type);
return item?.format
? getFormatter(item.format, field)(value)
: parseFieldValue(value, field.type);
}
6 changes: 4 additions & 2 deletions src/utils/layer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export type LayersToRender = {
[layerId: string]: boolean;
};

export type AggregationLayerHoverData = {points: any[]; colorValue?: any; elevationValue?: any};

export type LayerHoverProp = {
data: any[];
data: any[] | AggregationLayerHoverData;
fields: Field[];
fieldsToShow: TooltipField[];
layer: Layer;
primaryData?: any[];
primaryData?: any[] | AggregationLayerHoverData;
compareType?: CompareType;
};

Expand Down
3 changes: 1 addition & 2 deletions test/node/utils/interaction-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ test('interactionUtil -> getTooltipDisplayValue', t => {
dataset.dataContainer.map(data =>
getTooltipDisplayValue({
field,
data,
fieldIdx,
value: data.valueAt(fieldIdx),
item: tc.input
})
),
Expand Down