Skip to content

fix(heatmap): correct tooltip axis value lookup and percentage calculations and add tests - #38522

Closed
yousoph wants to merge 1 commit into
apache:masterfrom
aminghadersohi:heatmap-tooltip-tests
Closed

fix(heatmap): correct tooltip axis value lookup and percentage calculations and add tests#38522
yousoph wants to merge 1 commit into
apache:masterfrom
aminghadersohi:heatmap-tooltip-tests

Conversation

@yousoph

@yousoph yousoph commented Mar 9, 2026

Copy link
Copy Markdown
Member

User description

SUMMARY

Fixes the heatmap tooltip so it displays actual axis values (e.g., "Monday", "Morning") instead of numeric indices (0, 1, 2...), corrects the tooltip percentage calculation, and adds comprehensive regression tests.

Context: After PR #36302 changed the heatmap data structure to use axis indices for proper sorting, the tooltip formatter was not updated to look up actual values from the sorted arrays. This caused tooltips to display raw indices instead of formatted axis labels.

What this PR does:

  • Fixes the tooltip formatter to look up actual x/y values from the sorted axis arrays instead of rendering raw indices
  • Corrects the tooltip percentage calculation by keying calculateTotals off the query colnames (the real column names present in the data) instead of getColumnLabel(...) — the old keying produced NaN percentages whenever the derived label diverged from the data columns (notably array groupby)
  • Adds 5 test cases covering different tooltip scenarios
  • Ensures tooltips display actual axis values, not numeric indices
  • Verifies tooltip behavior with different sort orders (alphabetical asc/desc, value-based asc/desc)
  • Tests percentage calculations use actual values when normalizeAcross is enabled
  • Validates tooltip handling of numeric axes

Why these tests matter:
These tests prevent future regressions by verifying the tooltip formatter correctly:

  1. Looks up actual x/y values from sortedXAxisValues and sortedYAxisValues arrays
  2. Uses actual values (not indices) for percentage calculations in totals.x[xValue] and totals.y[yValue]
  3. Handles different data types (strings, numbers) and sort configurations

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — the change affects tooltip text/percentage values (indices → axis labels, NaN% → correct %), which are covered by the added regression tests.

TESTING INSTRUCTIONS

  1. Run the heatmap tooltip tests:
    cd superset-frontend
    npm test -- transformProps.test.ts
    
    

CodeAnt-AI Description

Fix heatmap tooltip to show actual axis labels and correct percentage calculations

What Changed

  • Tooltip displays actual x/y axis values (e.g., "Monday", "11") instead of numeric indices
  • Percentage shown in tooltip uses the real axis totals (not indices) when normalization is enabled
  • Added tests covering alphabetical and value-based sorting, numeric axes, and percentage/normalization cases to prevent regressions

Impact

✅ Clearer heatmap tooltips
✅ Correct heatmap percentage values
✅ Fewer tooltip regressions

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai-for-open-source codeant-ai-for-open-source Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Mar 9, 2026
@dosubot dosubot Bot added plugins viz:charts:heatmap Related to the Heatmap chart labels Mar 9, 2026
Comment on lines +492 to +528
test('tooltip formatter should handle numeric axes correctly', () => {
const numericData = [
{ year: 2020, quarter: 1, revenue: 100 },
{ year: 2021, quarter: 2, revenue: 150 },
{ year: 2022, quarter: 3, revenue: 200 },
];

const chartProps = createChartProps(
{
sortXAxis: 'alpha_asc',
sortYAxis: 'alpha_asc',
xAxis: 'year',
groupby: ['quarter'],
},
numericData,
);

(chartProps as any).queriesData[0].colnames = [
'year',
'quarter',
'revenue',
];

const result = transformProps(chartProps as HeatmapChartProps);
const tooltipFormatter = (result.echartOptions.tooltip as any).formatter;

// With alpha_asc: xAxis = [2020, 2021, 2022], yAxis = [1, 2, 3]
// Index [1, 1, 150] should map to year 2021 and quarter 2
const mockParams = {
value: [1, 1, 150],
};

const tooltipHtml = tooltipFormatter(mockParams);

expect(tooltipHtml).toContain('2021');
expect(tooltipHtml).toContain('2');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: In the numeric-axes tooltip test, the formData metric is left as 'count' while the data and colnames use 'revenue', so transformProps reads undefined metric values and computes incorrect totals, making the test setup inconsistent with real usage and potentially hiding issues in percentage logic. [logic error]

Severity Level: Major ⚠️
- ⚠️ Heatmap numeric-axis tooltip test uses inconsistent metric configuration.
- ⚠️ Misconfigured test may miss regressions in metric-based logic.
Suggested change
test('tooltip formatter should handle numeric axes correctly', () => {
const numericData = [
{ year: 2020, quarter: 1, revenue: 100 },
{ year: 2021, quarter: 2, revenue: 150 },
{ year: 2022, quarter: 3, revenue: 200 },
];
const chartProps = createChartProps(
{
sortXAxis: 'alpha_asc',
sortYAxis: 'alpha_asc',
xAxis: 'year',
groupby: ['quarter'],
},
numericData,
);
(chartProps as any).queriesData[0].colnames = [
'year',
'quarter',
'revenue',
];
const result = transformProps(chartProps as HeatmapChartProps);
const tooltipFormatter = (result.echartOptions.tooltip as any).formatter;
// With alpha_asc: xAxis = [2020, 2021, 2022], yAxis = [1, 2, 3]
// Index [1, 1, 150] should map to year 2021 and quarter 2
const mockParams = {
value: [1, 1, 150],
};
const tooltipHtml = tooltipFormatter(mockParams);
expect(tooltipHtml).toContain('2021');
expect(tooltipHtml).toContain('2');
});
test('tooltip formatter should handle numeric axes correctly', () => {
const numericData = [
{ year: 2020, quarter: 1, revenue: 100 },
{ year: 2021, quarter: 2, revenue: 150 },
{ year: 2022, quarter: 3, revenue: 200 },
];
const chartProps = createChartProps(
{
sortXAxis: 'alpha_asc',
sortYAxis: 'alpha_asc',
xAxis: 'year',
groupby: ['quarter'],
metric: 'revenue',
},
numericData,
);
(chartProps as any).queriesData[0].colnames = [
'year',
'quarter',
'revenue',
];
const result = transformProps(chartProps as HeatmapChartProps);
const tooltipFormatter = (result.echartOptions.tooltip as any).formatter;
// With alpha_asc: xAxis = [2020, 2021, 2022], yAxis = [1, 2, 3]
// Index [1, 1, 150] should map to year 2021 and quarter 2
const mockParams = {
value: [1, 1, 150],
};
const tooltipHtml = tooltipFormatter(mockParams);
expect(tooltipHtml).toContain('2021');
expect(tooltipHtml).toContain('2');
});
Steps of Reproduction ✅
1. Run the unit tests for the heatmap transform via `npm test -- transformProps.test.ts`
in `superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts`.

2. Observe the test `tooltip formatter should handle numeric axes correctly` starting at
line 492, which calls `createChartProps` without overriding `metric`, so it uses
`baseFormData.metric = 'count'` from the top of the file.

3. In the same test, `numericData` only contains a `revenue` field and
`queriesData[0].colnames` is overridden to `['year', 'quarter', 'revenue']`, so there is
no `count` column for the metric referenced by formData.

4. When `transformProps` is invoked with these `chartProps`, it computes heatmap series
values and any metric-based aggregations using the nonexistent `'count'` metric (reading
undefined/incorrect values), while the test only asserts on axis labels in the tooltip
output, so this inconsistent setup is not detected by the assertions.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts
**Line:** 492:528
**Comment:**
	*Logic Error: In the numeric-axes tooltip test, the formData metric is left as `'count'` while the data and `colnames` use `'revenue'`, so `transformProps` reads undefined metric values and computes incorrect totals, making the test setup inconsistent with real usage and potentially hiding issues in percentage logic.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
👍 | 👎

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's real... the numeric-axes test should set metric: 'revenue' so totals aren't computed off a missing column. Same fix Joe's assertion note points at.

@bito-code-review bito-code-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #746e1e

Actionable Suggestions - 1
  • superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts - 1
Review Details
  • Files reviewed - 2 · Commit Range: e508645..4d5d74f
    • superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi
aminghadersohi force-pushed the heatmap-tooltip-tests branch from 4d5d74f to 84c2e5d Compare March 9, 2026 17:48
@bito-code-review

bito-code-review Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #80dbcd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: e508645..84c2e5d
    • superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Add comprehensive tests to ensure the tooltip formatter correctly displays
actual axis values instead of numeric indices. This prevents regression of
the bug fixed in the previous commit where tooltips showed "0 (1)" instead
of actual labels like "Monday (Morning)".

Tests cover:
- Tooltip displays actual axis values with alphabetical sorting
- Tooltip works correctly with different sort orders (asc/desc)
- Tooltip works correctly with value-based sorting
- Percentage calculations use actual values when normalizeAcross is enabled
- Tooltip handles numeric axes correctly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aminghadersohi
aminghadersohi force-pushed the heatmap-tooltip-tests branch from 84c2e5d to 076f85d Compare March 11, 2026 21:06

@bito-code-review bito-code-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #e016ae

Actionable Suggestions - 1
  • superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts - 1
Review Details
  • Files reviewed - 2 · Commit Range: 076f85d..076f85d
    • superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds regression coverage (and adjusts implementation) to ensure ECharts heatmap tooltips display real x/y axis labels rather than axis indices, including correct percentage calculations under normalization.

Changes:

  • Add multiple tooltip-focused tests covering axis index → label lookup, sorting modes, normalization percentages, and numeric axes.
  • Update heatmap tooltip percentage calculation to key totals by actual axis values (from query colnames) rather than derived labels/casted strings.
  • Remove unused label-derivation logic (getColumnLabel) in favor of query-provided column names.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts Adds regression tests for tooltip label lookup, sorting, normalization percentages, and numeric axis handling.
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Fixes tooltip totals lookup to use real axis column names/values (not indices/labels) for percentage calculations.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +361 to +362
xAxisColumnName,
yAxisColumnName,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch... the SUMMARY still says test-only from before the calculateTotals change landed on this branch. Description should be updated to match the title.

const tooltipHtml = tooltipFormatter(mockParams);

expect(tooltipHtml).toContain('2021');
expect(tooltipHtml).toContain('2');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably can get rid of this or need to update to a better expect. If you take a look at L526, it will pass if it contains '2021', but '2' is part of '2021' so thi sline will always pass as long as the above line passes.

@yousoph yousoph changed the title test(heatmap): add tests for tooltip displaying actual axis values fix(heatmap): correct tooltip axis value lookup and percentage calculations and add tests Mar 18, 2026
@yousoph yousoph added the 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR label Mar 18, 2026
@github-actions github-actions Bot added 🎪 076f85d 🚦 building 🎪 ⌛ 48h Environment expires after 48 hours (default) and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Mar 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 076f85d

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 076f85d

Environment: http://44.250.239.7:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@msyavuz msyavuz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am on the fence with this one. Test coverage looks good but it looks like these changes should be failing some regression tests

Comment on lines +393 to +395
// Convert yValue to a key type (string or number) for totals lookup
const yKey = yValue as string | number;
percentage = value / totals.y[yKey];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually do any conversions. It is just type assertion for yKey and xKey. Previous behaviour was to cast it as String.

Comment on lines +361 to +362
xAxisColumnName,
yAxisColumnName,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change might be a regression for this chart when the columns are not physical and have labels

@rusackas

Copy link
Copy Markdown
Member

@yousoph CI is green and the fix reads correctly, but pinging about @msyavuz's concerns that these changes ought to have tripped existing regression tests. Can you confirm what behavior the old code actually produced, so we know the new tests are guarding the real bug?

@rusackas

rusackas commented Jul 4, 2026

Copy link
Copy Markdown
Member

@yousoph the core fix here is right... I traced it on master: calculateTotals keyed by getColumnLabel(groupby) while the rows are keyed by colnames, so any divergence (array groupby especially) NaN'd the percentages. Keying by colnames puts totals and lookups in one namespace, and test 4 pins it properly. That also answers @msyavuz's regression question, I believe: the tooltip lookup keys are built from colnames already, so the totals change can't drift from them.

A few things before we can merge though. Joe's toContain('2') assertion note and the metric: 'revenue' fixture mismatch (flagged by three reviewers) are still unaddressed. The xKey/yKey cast hunk is a runtime no-op with misleading "Convert" comments, per @msyavuz... I'd just drop that hunk and keep the calculateTotals change. And the PR description still says test-only while shipping a prod fix.

I've resolved the noise/duplicate bot threads above and left the two real ones open. Happy to re-review after those... holler if you want a hand.

@yousoph

yousoph commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Re-pointed this onto my own fork so the review fixes could be pushed directly — continued in #41864, which carries all four requested fixes from @rusackas's list (dropped the no-op xKey/yKey cast, fixed the numeric-axis test metric, replaced Joe's toContain('2'), and tightened the loose percentage assertions). Closing this one in favor of #41864 — thanks for the reviews @rusackas @msyavuz @sadpandajoe!

@yousoph yousoph closed this Jul 7, 2026
@github-actions github-actions Bot removed the 🎪 ⌛ 48h Environment expires after 48 hours (default) label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugins size/L size:L This PR changes 100-499 lines, ignoring generated files viz:charts:heatmap Related to the Heatmap chart

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants