Skip to content

Commit 630b092

Browse files
authored
Merge pull request #6718 from bhavinpatel1109/feature/fix6699-column-order-changes-on-hover
Fixed issue - column order changes on hover
2 parents 7a7b412 + 00d46f6 commit 630b092

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

draftlogs/6718_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Column order changes on hover [[#6718](https://github.com/plotly/plotly.js/pull/6718)]

src/plots/plots.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -3207,6 +3207,14 @@ function sortAxisCategoriesByValue(axList, gd) {
32073207
median: function(values) {return Lib.median(values);}
32083208
};
32093209

3210+
function sortAscending(a, b) {
3211+
return a[1] - b[1];
3212+
}
3213+
3214+
function sortDescending(a, b) {
3215+
return b[1] - a[1];
3216+
}
3217+
32103218
for(i = 0; i < axList.length; i++) {
32113219
var ax = axList[i];
32123220
if(ax.type !== 'category') continue;
@@ -3328,9 +3336,7 @@ function sortAxisCategoriesByValue(axList, gd) {
33283336
}
33293337

33303338
// Sort by aggregated value
3331-
categoriesAggregatedValue.sort(function(a, b) {
3332-
return a[1] - b[1];
3333-
});
3339+
categoriesAggregatedValue.sort(order === 'descending' ? sortDescending : sortAscending);
33343340

33353341
ax._categoriesAggregatedValue = categoriesAggregatedValue;
33363342

@@ -3339,11 +3345,6 @@ function sortAxisCategoriesByValue(axList, gd) {
33393345
return c[0];
33403346
});
33413347

3342-
// Reverse if descending
3343-
if(order === 'descending') {
3344-
ax._initialCategories.reverse();
3345-
}
3346-
33473348
// Sort all matching axes
33483349
affectedTraces = affectedTraces.concat(ax.sortByInitialCategories());
33493350
}

test/jasmine/tests/calcdata_test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -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)