From 061cf9ac8f1b3b59c90acb28eda6aa6f3c4f2469 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 13 May 2020 19:09:53 -0400 Subject: [PATCH 1/4] do not relink _categories --- src/lib/relink_private.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/relink_private.js b/src/lib/relink_private.js index 76614ec7b15..395c5ec4a39 100644 --- a/src/lib/relink_private.js +++ b/src/lib/relink_private.js @@ -24,9 +24,9 @@ module.exports = function relinkPrivateKeys(toContainer, fromContainer) { var fromVal = fromContainer[k]; var toVal = toContainer[k]; - if(toVal === fromVal) { - continue; - } + if(toVal === fromVal) continue; + if(k !== '_categories' && toContainer.matches) continue; + if(k.charAt(0) === '_' || typeof fromVal === 'function') { // if it already exists at this point, it's something // that we recreate each time around, so ignore it From aa3527ff700a592362c0a545d638bf0ad787406f Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 13 May 2020 20:15:13 -0400 Subject: [PATCH 2/4] add test to lock issue 4718 --- test/jasmine/tests/axes_test.js | 74 +++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index ed36147de3e..f3f2974cfab 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -5431,3 +5431,77 @@ describe('Test template:', function() { .then(done); }); }); + +describe('more react tests', function() { + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(destroyGraphDiv); + + it('should sort catgories on matching axes using react', function(done) { + var fig = { + data: [{ + yaxis: 'y', + xaxis: 'x', + y: [0, 0], + x: ['A', 'Z'] + }, { + yaxis: 'y2', + xaxis: 'x2', + y: [0, 0], + x: ['A', 'Z'] + }], + layout: { + width: 400, + height: 300, + showlegend: false, + xaxis: { + matches: 'x2', + domain: [ 0, 1] + }, + yaxis: { + domain: [0.6, 1], + anchor: 'x' + }, + xaxis2: { + domain: [0, 1], + anchor: 'y2' + }, + yaxis2: { + domain: [0, 0.4], + anchor: 'x2' + } + } + }; + + Plotly.newPlot(gd, fig) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['A', 'Z']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['A', 'Z']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({A: 0, Z: 1}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({A: 0, Z: 1}); + }) + .then(function() { + var newFig = JSON.parse(JSON.stringify(fig)); + + // flip order + newFig.data[0].x.reverse(); + newFig.data[0].y.reverse(); + newFig.data[1].x.reverse(); + newFig.data[1].y.reverse(); + + return Plotly.react(gd, newFig); + }) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['Z', 'A']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', 'A']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, A: 1}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, A: 1}); + }) + .catch(failTest) + .then(done); + }); +}); From 2295e505b7b8f52b31e23d0e4c7bdcd3f27db4e2 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 14 May 2020 11:46:54 -0400 Subject: [PATCH 3/4] do not relink _categoryMap on matching axes --- src/lib/relink_private.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/relink_private.js b/src/lib/relink_private.js index 395c5ec4a39..e1e46d0f27b 100644 --- a/src/lib/relink_private.js +++ b/src/lib/relink_private.js @@ -25,7 +25,7 @@ module.exports = function relinkPrivateKeys(toContainer, fromContainer) { var toVal = toContainer[k]; if(toVal === fromVal) continue; - if(k !== '_categories' && toContainer.matches) continue; + if(toContainer.matches && k === '_categoriesMap') continue; if(k.charAt(0) === '_' || typeof fromVal === 'function') { // if it already exists at this point, it's something From c2dc252d4c3ea64a30ee13fdb03b12499ebc2e3c Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 14 May 2020 14:06:01 -0400 Subject: [PATCH 4/4] expand the test to cover few more cases --- test/jasmine/tests/axes_test.js | 70 +++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index f3f2974cfab..45b1bff36bd 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -5485,15 +5485,21 @@ describe('more react tests', function() { expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({A: 0, Z: 1}); }) .then(function() { - var newFig = JSON.parse(JSON.stringify(fig)); - // flip order - newFig.data[0].x.reverse(); - newFig.data[0].y.reverse(); - newFig.data[1].x.reverse(); - newFig.data[1].y.reverse(); + fig.data[0].x = ['Z', 'A']; + fig.data[1].x = ['Z', 'A']; - return Plotly.react(gd, newFig); + return Plotly.react(gd, fig); + }) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['Z', 'A']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', 'A']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, A: 1}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, A: 1}); + }) + .then(function() { + // should get the same order with newPlot + return Plotly.newPlot(gd, fig); }) .then(function() { expect(gd._fullLayout.xaxis._categories).toEqual(['Z', 'A']); @@ -5501,6 +5507,56 @@ describe('more react tests', function() { expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, A: 1}); expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, A: 1}); }) + .then(function() { + // add new category + fig.data[0].x = ['Z', 0, 'A']; + fig.data[1].x = ['Z', 0, 'A']; + fig.data[0].y = [1, 2, 3]; + fig.data[1].y = [2, 4, 6]; + + return Plotly.react(gd, fig); + }) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + }) + .then(function() { + // should get the same order with newPlot + return Plotly.newPlot(gd, fig); + }) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + }) + .then(function() { + // change data + fig.data[0].x = ['Z', 0, 'A']; + fig.data[1].x = ['A', 'Z']; + fig.data[0].y = [3, 2, 1]; + fig.data[1].y = [-1, 0]; + + return Plotly.react(gd, fig); + }) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + }) + .then(function() { + // should get the same order with newPlot + return Plotly.newPlot(gd, fig); + }) + .then(function() { + expect(gd._fullLayout.xaxis._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', '0', 'A']); + expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, 0: 1, A: 2}); + }) .catch(failTest) .then(done); });