Skip to content

Fix react category order of matching axes #4832

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

Merged
merged 4 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions src/lib/relink_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});