Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue - column order changes on hover #6718

Merged
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/6718_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Column order changes on hover [[#6718](https://github.com/plotly/plotly.js/pull/6718)]
17 changes: 9 additions & 8 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,14 @@ function sortAxisCategoriesByValue(axList, gd) {
median: function(values) {return Lib.median(values);}
};

function sortAscending(a, b) {
return a[1] - b[1];
}

function sortDescending(a, b) {
return b[1] - a[1];
}

for(i = 0; i < axList.length; i++) {
var ax = axList[i];
if(ax.type !== 'category') continue;
Expand Down Expand Up @@ -3328,9 +3336,7 @@ function sortAxisCategoriesByValue(axList, gd) {
}

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

ax._categoriesAggregatedValue = categoriesAggregatedValue;

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

// Reverse if descending
if(order === 'descending') {
ax._initialCategories.reverse();
}

// Sort all matching axes
affectedTraces = affectedTraces.concat(ax.sortByInitialCategories());
}
Expand Down
10 changes: 8 additions & 2 deletions test/jasmine/tests/calcdata_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,14 @@ describe('calculated data and points', function() {
if(categoryorder === 'total descending') finalOrder.reverse();
var expectedAgg = [['a', 7], ['b', 2], ['c', 3]];

if(trace.type === 'ohlc' || trace.type === 'candlestick') expectedAgg = [['a', 14], ['b', 4], ['c', 6]];
if(trace.type.match(/histogram/)) expectedAgg = [['a', 2], ['b', 1], ['c', 1]];
if(trace.type === 'ohlc' || trace.type === 'candlestick') {
expectedAgg = [['a', 14], ['b', 4], ['c', 6]];
if(categoryorder === 'total descending') finalOrder = ['a', 'c', 'b'];
}
if(trace.type.match(/histogram/)) {
expectedAgg = [['a', 2], ['b', 1], ['c', 1]];
if(categoryorder === 'total descending') finalOrder = ['a', 'b', 'c'];
}

checkAggregatedValue(baseMock, expectedAgg, finalOrder, done);
});
Expand Down