Skip to content

Commit 5a79014

Browse files
committed
Fixed test case issues
1 parent fe8b5c4 commit 5a79014

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/plots/plots.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,17 +3327,19 @@ function sortAxisCategoriesByValue(axList, gd) {
33273327
]);
33283328
}
33293329

3330-
// Sort by aggregated value
3331-
categoriesAggregatedValue.sort(function(a, b) {
3330+
function sortValues(a, b) {
33323331
return order === 'descending' ? b[1] - a[1] : a[1] - b[1];
3333-
});
3332+
}
33343333

3334+
// Sort by aggregated value
3335+
categoriesAggregatedValue.sort(sortValues);
3336+
33353337
ax._categoriesAggregatedValue = categoriesAggregatedValue;
33363338

33373339
// Set new category order
33383340
ax._initialCategories = categoriesAggregatedValue.map(function(c) {
33393341
return c[0];
3340-
});
3342+
});
33413343

33423344
// Sort all matching axes
33433345
affectedTraces = affectedTraces.concat(ax.sortByInitialCategories());

test/jasmine/tests/calcdata_test.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,28 +1035,28 @@ describe('calculated data and points', function() {
10351035
});
10361036
}
10371037

1038-
supportedCartesianTraces.forEach(function(trace) {
1038+
supportedCartesianTraces.forEach(function(trace) {
10391039
['xaxis', 'yaxis'].forEach(function(axName) {
10401040
if(axName === 'yaxis' && oneOrientationTraces.indexOf(trace.type) !== -1) return;
10411041

1042-
function checkAggregatedValue(baseMock, expectedAgg, finalOrder, done) {
1042+
function checkAggregatedValue(baseMock, expectedAgg, finalOrder, done) {
10431043
var mock = Lib.extendDeep({}, baseMock);
1044-
1044+
10451045
if(mock.data[0].type.match(/histogram/)) {
10461046
for(i = 0; i < mock.data.length; i++) {
10471047
mock.data[i][axName === 'yaxis' ? 'y' : 'x'].push('a');
1048-
mock.data[i][axName === 'yaxis' ? 'x' : 'y'].push(7);
1048+
mock.data[i][axName === 'yaxis' ? 'x' : 'y'].push(7);
10491049
}
10501050
}
1051-
1051+
10521052
Plotly.newPlot(gd, mock)
1053-
.then(function(gd) {
1053+
.then(function(gd) {
10541054
var agg = gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axName]._categoriesAggregatedValue.sort(function(a, b) {
10551055
return a[0] > b[0] ? 1 : -1;
10561056
});
10571057
expect(agg).toEqual(expectedAgg, 'wrong aggregation for ' + axName);
10581058

1059-
if(finalOrder) {
1059+
if(finalOrder) {
10601060
expect(gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axName]._categories).toEqual(finalOrder, 'wrong order');
10611061
}
10621062
})
@@ -1074,8 +1074,14 @@ describe('calculated data and points', function() {
10741074
if(categoryorder === 'total descending') finalOrder.reverse();
10751075
var expectedAgg = [['a', 7], ['b', 2], ['c', 3]];
10761076

1077-
if(trace.type === 'ohlc' || trace.type === 'candlestick') expectedAgg = [['a', 14], ['b', 4], ['c', 6]];
1078-
if(trace.type.match(/histogram/)) expectedAgg = [['a', 2], ['b', 1], ['c', 1]];
1077+
if(trace.type === 'ohlc' || trace.type === 'candlestick'){
1078+
expectedAgg = [['a', 14], ['b', 4], ['c', 6]];
1079+
if(categoryorder === 'total descending') finalOrder= ['a', 'c', 'b']
1080+
}
1081+
if(trace.type.match(/histogram/)){
1082+
expectedAgg = [['a', 2], ['b', 1], ['c', 1]];
1083+
if(categoryorder === 'total descending') finalOrder= ['a', 'b', 'c']
1084+
}
10791085

10801086
checkAggregatedValue(baseMock, expectedAgg, finalOrder, done);
10811087
});

0 commit comments

Comments
 (0)