From 4da37ae2f53c24421b1eacea609c138381560b28 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Fri, 19 Jun 2026 18:20:51 -0700 Subject: [PATCH 1/2] Skip null category coordinates when ordering by value Signed-off-by: Sai Asish Y --- src/plots/plots.js | 4 ++++ test/jasmine/tests/calcdata_test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/plots/plots.js b/src/plots/plots.js index d86c5c7e06b..a28ac57a527 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3188,6 +3188,10 @@ function sortAxisCategoriesByValue(axList, gd) { catIndex = cdi.p; if(catIndex === undefined) catIndex = cdi[axLetter]; + // Skip points whose position is not a valid category + // (e.g. a null/NaN coordinate maps to BADNUM) + if(!(catIndex + 1)) continue; + value = cdi.s; if(value === undefined) value = cdi.v; if(value === undefined) value = isX ? cdi.y : cdi.x; diff --git a/test/jasmine/tests/calcdata_test.js b/test/jasmine/tests/calcdata_test.js index 86ef265c7b4..10ff96e1165 100644 --- a/test/jasmine/tests/calcdata_test.js +++ b/test/jasmine/tests/calcdata_test.js @@ -1215,6 +1215,21 @@ describe('calculated data and points', function() { }) .then(done, done.fail); }); + + it('does not throw when a category coordinate is null and ordering by value', function(done) { + Plotly.newPlot(gd, [{ + type: 'bar', + x: ['a', null, 'b'], + y: [3, 5, 7] + }], { + xaxis: {type: 'category', categoryorder: 'sum descending'} + }) + .then(function() { + // the null point is dropped, remaining categories are ordered by value + expect(gd._fullLayout.xaxis._categories).toEqual(['b', 'a']); + }) + .then(done, done.fail); + }); }); }); From 5fff4b7a618a6c66fb9b4ae43008e5ba8741c8cb Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Fri, 19 Jun 2026 18:21:29 -0700 Subject: [PATCH 2/2] Add draftlog for #7855 Signed-off-by: Sai Asish Y --- draftlogs/7855_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/7855_fix.md diff --git a/draftlogs/7855_fix.md b/draftlogs/7855_fix.md new file mode 100644 index 00000000000..4a2dc7af4b1 --- /dev/null +++ b/draftlogs/7855_fix.md @@ -0,0 +1 @@ +- Fix crash when ordering categories by value (e.g. `sum descending`) with `null` coordinates [[#7855](https://github.com/plotly/plotly.js/pull/7855)]