Skip to content

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

fix(tooltip): deduplicate aggregation rows (#3833)

Igor Dykhta31da085ec348
diff --git a/src/components/src/map/layer-hover-info.tsx b/src/components/src/map/layer-hover-info.tsx
index 0fa5a0bcb..6d45d2c5a 100644
--- a/src/components/src/map/layer-hover-info.tsx
+++ b/src/components/src/map/layer-hover-info.tsx
@@ -356,6 +356,11 @@ const CellInfo = ({
const colorMeasure = layer.getVisualChannelDescription('color').measure;
const sizeMeasure = layer.getVisualChannelDescription('size').measure;
+ const isSizeMeasureDuplicate =
+ colorField?.name === sizeField?.name &&
+ colorMeasure === sizeMeasure &&
+ colorValue === elevationValue &&
+ colorDelta === elevationDelta;
return (
<tbody>
<Row
@@ -373,7 +378,7 @@ const CellInfo = ({
isComparing={isComparing}
/>
) : null}
- {sizeField && layer.visualChannels.size && sizeMeasure ? (
+ {sizeField && layer.visualChannels.size && sizeMeasure && !isSizeMeasureDuplicate ? (
<Row
name={sizeMeasure}
key="size"
diff --git a/test/browser/components/map/map-popover-test.js b/test/browser/components/map/map-popover-test.js
index ee6b22b2b..7457ab30b 100644
--- a/test/browser/components/map/map-popover-test.js
+++ b/test/browser/components/map/map-popover-test.js
@@ -266,3 +266,103 @@ test('Map Popover - raster tooltip keeps a delta column in comparison mode', t =
t.equal(rows.at(3).find('.row__name').text(), 'b1');
t.end();
});
+
+test('Map Popover - aggregation tooltip deduplicates identical visual channel rows', t => {
+ const field = {name: 'fare', type: 'real'};
+ const layer = {
+ isAggregated: true,
+ visualChannels: {color: {}, size: {}},
+ config: {
+ label: 'Hexbin',
+ colorField: field,
+ sizeField: field
+ },
+ getVisualChannelDescription: () => ({measure: 'Average of fare'})
+ };
+ const aggregationHoverProp = {
+ data: {points: [], colorValue: 42, elevationValue: 42},
+ fields: [field],
+ fieldsToShow: [{name: field.name}],
+ layer
+ };
+
+ const wrapper = mountWithTheme(
+ <IntlWrapper>
+ <LayerHoverInfo {...aggregationHoverProp} />
+ </IntlWrapper>
+ );
+ const rows = wrapper.find('.layer-hover-info__row');
+
+ t.equal(rows.length, 2, 'should render total points and one shared aggregation row');
+ t.equal(rows.at(1).find('.row__name').text(), 'Average of fare');
+ t.equal(rows.at(1).find('.row__value').text(), '42');
+ t.end();
+});
+
+test('Map Popover - aggregation tooltip retains rows with different comparison deltas', t => {
+ const field = {name: 'fare', type: 'real'};
+ const layer = {
+ isAggregated: true,
+ visualChannels: {color: {}, size: {}},
+ config: {
+ label: 'Hexbin',
+ colorField: field,
+ sizeField: field
+ },
+ getVisualChannelDescription: () => ({measure: 'Average of fare'})
+ };
+ const aggregationHoverProp = {
+ data: {points: [], colorValue: 42, elevationValue: 42},
+ fields: [field],
+ fieldsToShow: [{name: field.name}],
+ layer,
+ primaryData: {points: [], colorValue: 10, elevationValue: 20},
+ compareType: COMPARE_TYPES.ABSOLUTE
+ };
+
+ const wrapper = mountWithTheme(
+ <IntlWrapper>
+ <LayerHoverInfo {...aggregationHoverProp} />
+ </IntlWrapper>
+ );
+ const rows = wrapper.find('.layer-hover-info__row');
+
+ t.equal(rows.length, 3, 'should render both aggregation rows');
+ t.equal(rows.at(1).find('.row__delta-value').text(), '+32');
+ t.equal(rows.at(2).find('.row__delta-value').text(), '+22');
+ t.end();
+});
+
+test('Map Popover - aggregation tooltip retains rows with different aggregations', t => {
+ const field = {name: 'fare', type: 'real'};
+ const layer = {
+ isAggregated: true,
+ visualChannels: {color: {}, size: {}},
+ config: {
+ label: 'Hexbin',
+ colorField: field,
+ sizeField: field
+ },
+ getVisualChannelDescription: channel => ({
+ measure: channel === 'color' ? 'Average of fare' : 'Sum of fare'
+ })
+ };
+ const aggregationHoverProp = {
+ data: {points: [], colorValue: 42, elevationValue: 42},
+ fields: [field],
+ fieldsToShow: [{name: field.name}],
+ layer
+ };
+
+ const wrapper = mountWithTheme(
+ <IntlWrapper>
+ <LayerHoverInfo {...aggregationHoverProp} />
+ </IntlWrapper>
+ );
+ const rows = wrapper.find('.layer-hover-info__row');
+
+ t.equal(rows.length, 3, 'should render both aggregation rows');
+ t.equal(rows.at(1).find('.row__name').text(), 'Average of fare');
+ t.equal(rows.at(2).find('.row__name').text(), 'Sum of fare');
+ t.end();
+});