Skip to content

Relink matching axes categories during Plotly.relayout calls #4977

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 2 commits into from
Jul 2, 2020
Merged
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: 0 additions & 1 deletion src/lib/relink_private.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ module.exports = function relinkPrivateKeys(toContainer, fromContainer) {
var toVal = toContainer[k];

if(toVal === fromVal) continue;
if(toContainer.matches && k === '_categoriesMap') continue;

if(k.charAt(0) === '_' || typeof fromVal === 'function') {
// if it already exists at this point, it's something
10 changes: 10 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
@@ -2712,6 +2712,16 @@ function react(gd, data, layout, config) {

applyUIRevisions(gd.data, gd.layout, oldFullData, oldFullLayout);

var allNames = Object.getOwnPropertyNames(oldFullLayout);
for(var q = 0; q < allNames.length; q++) {
var name = allNames[q];
var start = name.substring(0, 5);
if(start === 'xaxis' || start === 'yaxis') {
var emptyCategories = oldFullLayout[name]._emptyCategories;
if(emptyCategories) emptyCategories();
}
}

// "true" skips updating calcdata and remapping arrays from calcTransforms,
// which supplyDefaults usually does at the end, but we may need to NOT do
// if the diff (which we haven't determined yet) says we'll recalc
22 changes: 9 additions & 13 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
@@ -870,13 +870,13 @@ module.exports = function setConvert(ax, fullLayout) {
}
};

ax._emptyCategories = function() {
ax._categories = [];
ax._categoriesMap = {};
};

// should skip if not category nor multicategory
ax.clearCalc = function() {
var emptyCategories = function() {
ax._categories = [];
ax._categoriesMap = {};
};

var matchGroups = fullLayout._axisMatchGroups;

if(matchGroups && matchGroups.length) {
@@ -903,14 +903,14 @@ module.exports = function setConvert(ax, fullLayout) {
ax._categories = categories;
ax._categoriesMap = categoriesMap;
} else {
emptyCategories();
ax._emptyCategories();
}
break;
}
}
if(!found) emptyCategories();
if(!found) ax._emptyCategories();
} else {
emptyCategories();
ax._emptyCategories();
}

if(ax._initialCategories) {
@@ -924,12 +924,8 @@ module.exports = function setConvert(ax, fullLayout) {
// returns the indices of the traces affected by the reordering
ax.sortByInitialCategories = function() {
var affectedTraces = [];
var emptyCategories = function() {
ax._categories = [];
ax._categoriesMap = {};
};

emptyCategories();
ax._emptyCategories();

if(ax._initialCategories) {
for(var j = 0; j < ax._initialCategories.length; j++) {
12 changes: 11 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
@@ -5580,7 +5580,7 @@ describe('more react tests', function() {

afterEach(destroyGraphDiv);

it('should sort catgories on matching axes using react', function(done) {
it('should sort catgories on matching axes using react and relink using relayout', function(done) {
var fig = {
data: [{
yaxis: 'y',
@@ -5696,6 +5696,16 @@ describe('more react tests', function() {
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 relayout
return Plotly.relayout(gd, 'width', 600);
})
.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);
});