Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7855_fix.md
Original file line number Diff line number Diff line change
@@ -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)]
4 changes: 4 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/jasmine/tests/calcdata_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down