From fe8b5c45455362f4b5985e6b5a28485f221020bc Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Tue, 29 Aug 2023 15:53:54 +0530 Subject: [PATCH 1/7] Fixed issue - column order changes on hover --- src/plots/plots.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 2feb453c40d..39ae37022b9 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3329,7 +3329,7 @@ function sortAxisCategoriesByValue(axList, gd) { // Sort by aggregated value categoriesAggregatedValue.sort(function(a, b) { - return a[1] - b[1]; + return order === 'descending' ? b[1] - a[1] : a[1] - b[1]; }); ax._categoriesAggregatedValue = categoriesAggregatedValue; @@ -3339,11 +3339,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()); } From 5a79014566e260b11f78cbf892634c9892c63355 Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Thu, 31 Aug 2023 18:36:49 +0530 Subject: [PATCH 2/7] Fixed test case issues --- src/plots/plots.js | 10 ++++++---- test/jasmine/tests/calcdata_test.js | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 39ae37022b9..4b6173852a9 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3327,17 +3327,19 @@ function sortAxisCategoriesByValue(axList, gd) { ]); } - // Sort by aggregated value - categoriesAggregatedValue.sort(function(a, b) { + function sortValues(a, b) { return order === 'descending' ? b[1] - a[1] : a[1] - b[1]; - }); + } + // Sort by aggregated value + categoriesAggregatedValue.sort(sortValues); + ax._categoriesAggregatedValue = categoriesAggregatedValue; // Set new category order ax._initialCategories = categoriesAggregatedValue.map(function(c) { return c[0]; - }); + }); // Sort all matching axes affectedTraces = affectedTraces.concat(ax.sortByInitialCategories()); diff --git a/test/jasmine/tests/calcdata_test.js b/test/jasmine/tests/calcdata_test.js index 57134876b50..2d2c1b60ed7 100644 --- a/test/jasmine/tests/calcdata_test.js +++ b/test/jasmine/tests/calcdata_test.js @@ -1035,28 +1035,28 @@ describe('calculated data and points', function() { }); } - supportedCartesianTraces.forEach(function(trace) { + supportedCartesianTraces.forEach(function(trace) { ['xaxis', 'yaxis'].forEach(function(axName) { if(axName === 'yaxis' && oneOrientationTraces.indexOf(trace.type) !== -1) return; - function checkAggregatedValue(baseMock, expectedAgg, finalOrder, done) { + function checkAggregatedValue(baseMock, expectedAgg, finalOrder, done) { var mock = Lib.extendDeep({}, baseMock); - + if(mock.data[0].type.match(/histogram/)) { for(i = 0; i < mock.data.length; i++) { mock.data[i][axName === 'yaxis' ? 'y' : 'x'].push('a'); - mock.data[i][axName === 'yaxis' ? 'x' : 'y'].push(7); + mock.data[i][axName === 'yaxis' ? 'x' : 'y'].push(7); } } - + Plotly.newPlot(gd, mock) - .then(function(gd) { + .then(function(gd) { var agg = gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axName]._categoriesAggregatedValue.sort(function(a, b) { return a[0] > b[0] ? 1 : -1; }); expect(agg).toEqual(expectedAgg, 'wrong aggregation for ' + axName); - if(finalOrder) { + if(finalOrder) { expect(gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axName]._categories).toEqual(finalOrder, 'wrong order'); } }) @@ -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); }); From 547ef525866916c5c4a91c1c1780b5a091b1bb90 Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Thu, 31 Aug 2023 19:02:35 +0530 Subject: [PATCH 3/7] Resolved ESLnt warnings --- src/plots/plots.js | 14 +++++++------- test/jasmine/tests/calcdata_test.js | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 4b6173852a9..a919f07fdbc 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3207,6 +3207,10 @@ function sortAxisCategoriesByValue(axList, gd) { median: function(values) {return Lib.median(values);} }; + function sortValues(a, b) { + 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; @@ -3327,19 +3331,15 @@ function sortAxisCategoriesByValue(axList, gd) { ]); } - function sortValues(a, b) { - return order === 'descending' ? b[1] - a[1] : a[1] - b[1]; - } - // Sort by aggregated value - categoriesAggregatedValue.sort(sortValues); - + categoriesAggregatedValue.sort(sortValues); + ax._categoriesAggregatedValue = categoriesAggregatedValue; // Set new category order ax._initialCategories = categoriesAggregatedValue.map(function(c) { return c[0]; - }); + }); // Sort all matching axes affectedTraces = affectedTraces.concat(ax.sortByInitialCategories()); diff --git a/test/jasmine/tests/calcdata_test.js b/test/jasmine/tests/calcdata_test.js index 2d2c1b60ed7..2111018242a 100644 --- a/test/jasmine/tests/calcdata_test.js +++ b/test/jasmine/tests/calcdata_test.js @@ -1035,28 +1035,28 @@ describe('calculated data and points', function() { }); } - supportedCartesianTraces.forEach(function(trace) { + supportedCartesianTraces.forEach(function(trace) { ['xaxis', 'yaxis'].forEach(function(axName) { if(axName === 'yaxis' && oneOrientationTraces.indexOf(trace.type) !== -1) return; - function checkAggregatedValue(baseMock, expectedAgg, finalOrder, done) { + function checkAggregatedValue(baseMock, expectedAgg, finalOrder, done) { var mock = Lib.extendDeep({}, baseMock); - + if(mock.data[0].type.match(/histogram/)) { for(i = 0; i < mock.data.length; i++) { mock.data[i][axName === 'yaxis' ? 'y' : 'x'].push('a'); - mock.data[i][axName === 'yaxis' ? 'x' : 'y'].push(7); + mock.data[i][axName === 'yaxis' ? 'x' : 'y'].push(7); } } - + Plotly.newPlot(gd, mock) - .then(function(gd) { + .then(function(gd) { var agg = gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axName]._categoriesAggregatedValue.sort(function(a, b) { return a[0] > b[0] ? 1 : -1; }); expect(agg).toEqual(expectedAgg, 'wrong aggregation for ' + axName); - if(finalOrder) { + if(finalOrder) { expect(gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axName]._categories).toEqual(finalOrder, 'wrong order'); } }) @@ -1074,13 +1074,13 @@ 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'){ + if(trace.type === 'ohlc' || trace.type === 'candlestick') { expectedAgg = [['a', 14], ['b', 4], ['c', 6]]; - if(categoryorder === 'total descending') finalOrder= ['a', 'c', 'b'] + if(categoryorder === 'total descending') finalOrder = ['a', 'c', 'b']; } - if(trace.type.match(/histogram/)){ + if(trace.type.match(/histogram/)) { expectedAgg = [['a', 2], ['b', 1], ['c', 1]]; - if(categoryorder === 'total descending') finalOrder= ['a', 'b', 'c'] + if(categoryorder === 'total descending') finalOrder = ['a', 'b', 'c']; } checkAggregatedValue(baseMock, expectedAgg, finalOrder, done); From 3e9500d460ccadc77f114d3121fa7a9a1254b958 Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Thu, 31 Aug 2023 19:29:34 +0530 Subject: [PATCH 4/7] Fixed one issue --- src/plots/plots.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index a919f07fdbc..b2662abc4af 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3207,7 +3207,7 @@ function sortAxisCategoriesByValue(axList, gd) { median: function(values) {return Lib.median(values);} }; - function sortValues(a, b) { + function sortValues(a, b, order) { return order === 'descending' ? b[1] - a[1] : a[1] - b[1]; } @@ -3332,7 +3332,7 @@ function sortAxisCategoriesByValue(axList, gd) { } // Sort by aggregated value - categoriesAggregatedValue.sort(sortValues); + categoriesAggregatedValue.sort((a,b) => sortValues(a, b, order)); ax._categoriesAggregatedValue = categoriesAggregatedValue; From 586542b7883c00ae524097e730f29c0299310ce9 Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Fri, 1 Sep 2023 09:56:56 +0530 Subject: [PATCH 5/7] Did changes based on suggestion --- src/plots/plots.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index b2662abc4af..fd05acbe6e4 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3207,8 +3207,12 @@ 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]; + 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++) { @@ -3332,7 +3336,7 @@ function sortAxisCategoriesByValue(axList, gd) { } // Sort by aggregated value - categoriesAggregatedValue.sort((a,b) => sortValues(a, b, order)); + categoriesAggregatedValue.sort(order === 'descending' ? sortDescending : sortAscending); ax._categoriesAggregatedValue = categoriesAggregatedValue; From 7530b930f92e5368be775432e04ca2caa6ab089e Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Fri, 1 Sep 2023 10:11:14 +0530 Subject: [PATCH 6/7] Resolved ESLnt warning --- src/plots/plots.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index fd05acbe6e4..5a6b5e0466c 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -3207,11 +3207,11 @@ function sortAxisCategoriesByValue(axList, gd) { median: function(values) {return Lib.median(values);} }; - function sortAscending (a, b) { + function sortAscending(a, b) { return a[1] - b[1]; } - function sortDescending (a, b) { + function sortDescending(a, b) { return b[1] - a[1]; } From 00d46f643247e25c953d8dad2d5881aee1bd34d1 Mon Sep 17 00:00:00 2001 From: bhavinatel1109 Date: Sat, 2 Sep 2023 09:55:58 +0530 Subject: [PATCH 7/7] Added log for bug 6699 --- draftlogs/6718_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/6718_fix.md diff --git a/draftlogs/6718_fix.md b/draftlogs/6718_fix.md new file mode 100644 index 00000000000..45eac127840 --- /dev/null +++ b/draftlogs/6718_fix.md @@ -0,0 +1 @@ +- Column order changes on hover [[#6718](https://github.com/plotly/plotly.js/pull/6718)] \ No newline at end of file