Skip to content

Commit 12303db

Browse files
authored
Merge pull request #4977 from plotly/fix4971-matches-relink
Relink matching axes categories during Plotly.relayout calls
2 parents c925cd4 + 7296fb7 commit 12303db

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/lib/relink_private.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module.exports = function relinkPrivateKeys(toContainer, fromContainer) {
2525
var toVal = toContainer[k];
2626

2727
if(toVal === fromVal) continue;
28-
if(toContainer.matches && k === '_categoriesMap') continue;
2928

3029
if(k.charAt(0) === '_' || typeof fromVal === 'function') {
3130
// if it already exists at this point, it's something

src/plot_api/plot_api.js

+10
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,16 @@ function react(gd, data, layout, config) {
27122712

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

2715+
var allNames = Object.getOwnPropertyNames(oldFullLayout);
2716+
for(var q = 0; q < allNames.length; q++) {
2717+
var name = allNames[q];
2718+
var start = name.substring(0, 5);
2719+
if(start === 'xaxis' || start === 'yaxis') {
2720+
var emptyCategories = oldFullLayout[name]._emptyCategories;
2721+
if(emptyCategories) emptyCategories();
2722+
}
2723+
}
2724+
27152725
// "true" skips updating calcdata and remapping arrays from calcTransforms,
27162726
// which supplyDefaults usually does at the end, but we may need to NOT do
27172727
// if the diff (which we haven't determined yet) says we'll recalc

src/plots/cartesian/set_convert.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,13 @@ module.exports = function setConvert(ax, fullLayout) {
870870
}
871871
};
872872

873+
ax._emptyCategories = function() {
874+
ax._categories = [];
875+
ax._categoriesMap = {};
876+
};
877+
873878
// should skip if not category nor multicategory
874879
ax.clearCalc = function() {
875-
var emptyCategories = function() {
876-
ax._categories = [];
877-
ax._categoriesMap = {};
878-
};
879-
880880
var matchGroups = fullLayout._axisMatchGroups;
881881

882882
if(matchGroups && matchGroups.length) {
@@ -903,14 +903,14 @@ module.exports = function setConvert(ax, fullLayout) {
903903
ax._categories = categories;
904904
ax._categoriesMap = categoriesMap;
905905
} else {
906-
emptyCategories();
906+
ax._emptyCategories();
907907
}
908908
break;
909909
}
910910
}
911-
if(!found) emptyCategories();
911+
if(!found) ax._emptyCategories();
912912
} else {
913-
emptyCategories();
913+
ax._emptyCategories();
914914
}
915915

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

932-
emptyCategories();
928+
ax._emptyCategories();
933929

934930
if(ax._initialCategories) {
935931
for(var j = 0; j < ax._initialCategories.length; j++) {

test/jasmine/tests/axes_test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -5580,7 +5580,7 @@ describe('more react tests', function() {
55805580

55815581
afterEach(destroyGraphDiv);
55825582

5583-
it('should sort catgories on matching axes using react', function(done) {
5583+
it('should sort catgories on matching axes using react and relink using relayout', function(done) {
55845584
var fig = {
55855585
data: [{
55865586
yaxis: 'y',
@@ -5696,6 +5696,16 @@ describe('more react tests', function() {
56965696
expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, 0: 1, A: 2});
56975697
expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, 0: 1, A: 2});
56985698
})
5699+
.then(function() {
5700+
// should get the same order with relayout
5701+
return Plotly.relayout(gd, 'width', 600);
5702+
})
5703+
.then(function() {
5704+
expect(gd._fullLayout.xaxis._categories).toEqual(['Z', '0', 'A']);
5705+
expect(gd._fullLayout.xaxis2._categories).toEqual(['Z', '0', 'A']);
5706+
expect(gd._fullLayout.xaxis._categoriesMap).toEqual({Z: 0, 0: 1, A: 2});
5707+
expect(gd._fullLayout.xaxis2._categoriesMap).toEqual({Z: 0, 0: 1, A: 2});
5708+
})
56995709
.catch(failTest)
57005710
.then(done);
57015711
});

0 commit comments

Comments
 (0)