Skip to content

fix(heatmap): y-axis sorts in order - #36302

Merged
rusackas merged 10 commits into
apache:masterfrom
sfirke:heatmap_y_axis_sort
Dec 4, 2025
Merged

fix(heatmap): y-axis sorts in order#36302
rusackas merged 10 commits into
apache:masterfrom
sfirke:heatmap_y_axis_sort

Conversation

@sfirke

@sfirke sfirke commented Nov 27, 2025

Copy link
Copy Markdown
Member

SUMMARY

Fixes #33245. Replaces the attempt in #34547.

Note: I leaned heavily on AI coding assistance for this PR since I'm still new to TypeScript. The logic makes sense to me and I verified the desired behaviors in my test environment, but someone familiar with TypeScript should review with care.

I left the addition to .gitignore in, it seems like a developer pattern that might help others.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

BEFORE - 6.0.0rc3

The y-axis is out of order:

image

AFTER

Y-axis order is correct:

image

TESTING INSTRUCTIONS

Tests included. I deployed to my test environment and checked ascending and descending for y- and x-axes of numeric and categorical variables.

ADDITIONAL INFORMATION

ECharts automatically creates axis categories from data in order of first
appearance, ignoring SQL ORDER BY. This causes axes to display in incorrect
order when some data combinations are missing.

Fix by:
- Extracting unique axis values from the dataset
- Sorting them according to user's sort configuration (sortXAxis/sortYAxis)
- Explicitly providing sorted arrays to ECharts via xAxis.data and yAxis.data

Supports all sort options:
- alpha_asc/alpha_desc: Lexicographic sorting
- value_asc/value_desc: Sort by aggregated metric values

Fixes apache#33245
Fixes two critical issues with heatmap axis sorting:

1. Series data now uses axis indices instead of raw values
   - ECharts requires [xIndex, yIndex, value] format when explicit axis data is provided
   - Previously used [xValue, yValue, value] causing blank rows

2. Numeric values now sort numerically instead of alphabetically
   - Detects numeric values and sorts them as numbers (1, 2, 10)
   - Previously sorted as strings resulting in wrong order (1, 10, 2)
   - Falls back to locale-aware string sorting for non-numeric values

Added tests for:
- Numeric sorting validation
- Axis index conversion
- Mixed numeric/string value handling

Related to apache#33245
- Import and use DataRecordValue type for better type safety
- Add comprehensive JSDoc comments to helper functions
- Add explicit Map<DataRecordValue, number> typing
- Remove unnecessary type assertions with proper Map typing
- Improve code comments for clarity
- Remove superset.code-workspace (should not be committed)
- Add *.code-workspace pattern to .gitignore
- Consolidate 16 tests down to 8 focused tests:
  - Merged 4 alphabetical sorting tests into 1 comprehensive test
  - Removed redundant 'preserve axis data structure' test
  - Kept all critical tests for bug fixes (numeric sorting, indices)
  - All 8 tests passing
@bito-code-review

bito-code-review Bot commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Code Review Agent Run #439ea5

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: eb98140..d5a5438
    • superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts
  • Files skipped - 1
    • .gitignore - Reason: Filter setting
  • 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 Default Agent 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

@dosubot dosubot Bot added the viz:charts:heatmap Related to the Heatmap chart label Nov 27, 2025

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

This PR fixes the heatmap y-axis sorting issue (#33245) by implementing proper sorting logic for both x and y axes. The implementation introduces two new helper functions to extract unique axis values and sort them based on user-specified options (alphabetical or by metric value), with special handling for numeric values to ensure they sort numerically rather than lexicographically.

Key Changes:

  • Added extractUniqueValues() and sortAxisValues() functions to handle axis sorting with support for alphabetical (numeric-aware) and value-based sorting
  • Modified series data to use axis indices instead of raw values, enabling proper sorted axis display in ECharts
  • Added comprehensive test coverage with 8 test cases covering various sorting scenarios and edge cases

Reviewed changes

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

File Description
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Core implementation of axis sorting logic and index-based data transformation
superset-frontend/plugins/plugin-chart-echarts/test/Heatmap/transformProps.test.ts Comprehensive test suite covering sorting scenarios, null handling, and numeric vs alphabetical sorting
.gitignore Added VS Code workspace files to gitignore

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Outdated
Comment thread superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Outdated
Comment thread superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Outdated
@rusackas
rusackas requested a review from sadpandajoe December 1, 2025 18:33
Comment thread superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Outdated
Comment thread superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Outdated
@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt AI is reviewing your PR.

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt AI finished reviewing your PR.

Comment thread superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts Outdated
@rusackas
rusackas merged commit 3345eb3 into apache:master Dec 4, 2025
63 checks passed
@sadpandajoe sadpandajoe added the v6.0 Label added by the release manager to track PRs to be included in the 6.0 branch label Dec 4, 2025
@sfirke
sfirke deleted the heatmap_y_axis_sort branch December 4, 2025 21:29
sadpandajoe pushed a commit that referenced this pull request Dec 8, 2025
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit 3345eb3)
sadpandajoe pushed a commit that referenced this pull request Dec 9, 2025
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit 3345eb3)
Facyla pushed a commit to Facyla/superset-contrib that referenced this pull request Dec 16, 2025
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugins size/L v6.0 Label added by the release manager to track PRs to be included in the 6.0 branch viz:charts:heatmap Related to the Heatmap chart

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Order of secondary heatmap axis varies based on data (started in 4.1)

4 participants