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 4 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
13 changes: 5 additions & 8 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,10 @@ function sortAxisCategoriesByValue(axList, gd) {
median: function(values) {return Lib.median(values);}
};

function sortValues(a, b, order) {
return order === 'descending' ? b[1] - a[1] : a[1] - b[1];
}

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

// Sort by aggregated value
categoriesAggregatedValue.sort(function(a, b) {
return a[1] - b[1];
});
categoriesAggregatedValue.sort((a,b) => sortValues(a, b, order));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, so the issue was a mismatch between ax._categoriesAggregatedValue and ax._initialCategories?

Performance will be better if we make two functions, sortAscending and sortDescending, and pass one or the other to sort rather than a wrapper function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the issue was a mismatch between ax._categoriesAggregatedValue and ax._initialCategories.

I have created two separate functions sortAscending and sortDescending.


ax._categoriesAggregatedValue = categoriesAggregatedValue;

Expand All @@ -3339,11 +3341,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