Skip to content

Commit bf6bdf3

Browse files
committed
sort categories by values: handle asymmetric splom
1 parent 553e193 commit bf6bdf3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/plots/plots.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,10 +2932,10 @@ function sortAxisCategoriesByValue(axList, gd) {
29322932
// Find which dimension the current axis is representing
29332933
var currentDimensionIndex = fullTrace._axesDim[ax._id];
29342934

2935-
// Apply logic to associated x axis
2935+
// Apply logic to associated x axis if it's defined
29362936
if(axLetter === 'y') {
29372937
var associatedXAxisID = fullTrace._diag[currentDimensionIndex][0];
2938-
ax = gd._fullLayout[axisIDs.id2name(associatedXAxisID)];
2938+
if(associatedXAxisID) ax = gd._fullLayout[axisIDs.id2name(associatedXAxisID)];
29392939
}
29402940

29412941
var categories = cdi.trace.dimensions[currentDimensionIndex].values;

test/jasmine/tests/calcdata_test.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ describe('calculated data and points', function() {
10071007
});
10081008
});
10091009

1010-
it('sum values across traces of type ' + trace.type, function(done) {
1010+
it('sums values across traces of type ' + trace.type, function(done) {
10111011
var type = trace.type;
10121012
var data = [7, 2, 3];
10131013
var data2 = [5, 4, 2];
@@ -1064,7 +1064,7 @@ describe('calculated data and points', function() {
10641064
checkAggregatedValue(baseMock, expectedAgg, false, done);
10651065
});
10661066

1067-
it('take the mean of all values per category across traces of type ' + trace.type, function(done) {
1067+
it('takes the mean of all values per category across traces of type ' + trace.type, function(done) {
10681068
var type = trace.type;
10691069
var data = [7, 2, 3];
10701070
var data2 = [5, 4, 2];
@@ -1080,7 +1080,7 @@ describe('calculated data and points', function() {
10801080
checkAggregatedValue(baseMock, expectedAgg, false, done);
10811081
});
10821082

1083-
it('take the median of all values per category across traces of type ' + trace.type, function(done) {
1083+
it('takes the median of all values per category across traces of type ' + trace.type, function(done) {
10841084
var type = trace.type;
10851085
var data = [7, 2, 3];
10861086
var data2 = [5, 4, 2];
@@ -1096,6 +1096,27 @@ describe('calculated data and points', function() {
10961096
});
10971097
});
10981098
});
1099+
1100+
it('works on asymmetric splom', function(done) {
1101+
var mock = require('@mocks/splom_multi-axis-type');
1102+
var mockCopy = Lib.extendDeep(mock, {});
1103+
1104+
var order = ['donald', 'georgeW', 'bill', 'ronald', 'richard', 'jimmy', 'george', 'barack', 'gerald', 'lyndon'];
1105+
1106+
Plotly.newPlot(gd, mockCopy)
1107+
.then(function() {
1108+
return Plotly.relayout(gd, 'yaxis5.categoryorder', 'total descending');
1109+
})
1110+
.then(function() {
1111+
expect(gd._fullLayout.yaxis5._categories).toEqual(order, 'wrong order');
1112+
return Plotly.relayout(gd, 'yaxis5.categoryorder', 'total ascending');
1113+
})
1114+
.then(function() {
1115+
expect(gd._fullLayout.yaxis5._categories).toEqual(order.reverse(), 'wrong order');
1116+
})
1117+
.catch(failTest)
1118+
.then(done);
1119+
});
10991120
});
11001121
});
11011122

0 commit comments

Comments
 (0)