Skip to content

Fix crash when ordering categories by value with null coordinates#7855

Open
SAY-5 wants to merge 2 commits into
plotly:masterfrom
SAY-5:fix-categoryorder-null-crash
Open

Fix crash when ordering categories by value with null coordinates#7855
SAY-5 wants to merge 2 commits into
plotly:masterfrom
SAY-5:fix-categoryorder-null-crash

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 20, 2026

Copy link
Copy Markdown

Fixes #7840.

When categoryorder is set to a value-based order (e.g. sum descending, total ascending), sortAxisCategoriesByValue collects per-category values by indexing categoriesValue[catIndex]. A data point with a null/NaN category coordinate maps to BADNUM, so catIndex is undefined and categoriesValue[catIndex][1] throws TypeError: Cannot read properties of undefined (reading '1'), leaving the chart blank.

This skips points whose position is not a valid category, using the same catIndex + 1 guard already applied in the 2dMap branch above. Such points carry no category to order anyway. Added a regression test for a bar chart with a null x and sum descending.

SAY-5 added 2 commits June 19, 2026 18:20
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@camdecoster camdecoster self-assigned this Jun 24, 2026
@camdecoster

Copy link
Copy Markdown
Contributor

Thanks for the PR! I'll review this and follow up with you.

@camdecoster camdecoster 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.

This is a good fix. I left you one comment.

Comment thread src/plots/plots.js

// Skip points whose position is not a valid category
// (e.g. a null/NaN coordinate maps to BADNUM)
if(!(catIndex + 1)) continue;

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.

This works and I know it shows up elsewhere in the repo, but it's a bit confusing. What do you think of changing to this?

Suggested change
if(!(catIndex + 1)) continue;
if (catIndex == null || catIndex < 0) continue;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: X-Axis NULL values lead to typeError when using categoryorder sumdescending in barcharts

2 participants