Skip to content

Commit 488c35f

Browse files
committed
copy axis type into missing axes
... so that their references are valid during handleConstraintDefaults
1 parent 22b34c0 commit 488c35f

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/plots/cartesian/layout_defaults.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,19 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
189189
var counterAxes = {x: getCounterAxes('x'), y: getCounterAxes('y')};
190190
// list of all x AND y axis ids
191191
var allAxisIds = counterAxes.x.concat(counterAxes.y);
192-
// list of axis ids that axes in axNames have a reference to,
192+
// lookup and list of axis ids that axes in axNames have a reference to,
193193
// even though they are missing from allAxisIds
194+
var missingMatchedAxisIdsLookup = {};
194195
var missingMatchedAxisIds = [];
195196

196-
// fill in 'missing' axis list when an axis is set to match an axis
197-
// not part of the allAxisIds list
198-
function addMissingMatchedAxis(matchesIn) {
197+
// fill in 'missing' axis lookup when an axis is set to match an axis
198+
// not part of the allAxisIds list, save axis type so that we can propagate
199+
// it to the missing axes
200+
function addMissingMatchedAxis() {
201+
var matchesIn = axLayoutIn.matches;
199202
if(AX_ID_PATTERN.test(matchesIn) && allAxisIds.indexOf(matchesIn) === -1) {
200-
Lib.pushUnique(missingMatchedAxisIds, matchesIn);
203+
missingMatchedAxisIdsLookup[matchesIn] = axLayoutIn.type;
204+
missingMatchedAxisIds = Object.keys(missingMatchedAxisIdsLookup);
201205
}
202206
}
203207

@@ -269,7 +273,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
269273

270274
coerce('title.standoff');
271275

272-
addMissingMatchedAxis(axLayoutIn.matches);
276+
addMissingMatchedAxis();
273277

274278
axLayoutOut._input = axLayoutIn;
275279
}
@@ -305,7 +309,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
305309

306310
coerce('uirevision', layoutOut.uirevision);
307311

308-
handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions2);
312+
axLayoutOut.type = missingMatchedAxisIdsLookup[axId] || 'linear';
313+
309314
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions2, layoutOut);
310315

311316
handlePositionDefaults(axLayoutIn, axLayoutOut, coerce, {
@@ -317,7 +322,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
317322

318323
coerce('fixedrange');
319324

320-
addMissingMatchedAxis(axLayoutIn.matches);
325+
addMissingMatchedAxis();
321326

322327
axLayoutOut._input = axLayoutIn;
323328
}

test/jasmine/tests/axes_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,27 @@ describe('Test axes', function() {
978978
expect(layoutOut.xaxis4.range).withContext('xaxis4.range').toEqual([0, 1]);
979979
});
980980

981+
it('should propagate axis type into *missing* axes', function() {
982+
layoutIn = {
983+
xaxis2: {type: 'date', matches: 'x'},
984+
yaxis: {type: 'category', matches: 'y2'}
985+
};
986+
layoutOut._subplots.cartesian = ['x2y'];
987+
layoutOut._subplots.xaxis = ['x2'];
988+
layoutOut._subplots.yaxis = ['y'];
989+
990+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
991+
992+
expect(layoutOut._axisMatchGroups.length).toBe(2);
993+
expect(layoutOut._axisMatchGroups).toContain({x: 1, x2: 1});
994+
expect(layoutOut._axisMatchGroups).toContain({y: 1, y2: 1});
995+
996+
expect(layoutOut.xaxis.type).withContext('xaxis.type').toBe('date');
997+
expect(layoutOut.xaxis2.type).withContext('xaxis2.type').toBe('date');
998+
expect(layoutOut.yaxis.type).withContext('yaxis.type').toBe('category');
999+
expect(layoutOut.yaxis2.type).withContext('yaxis2.type').toBe('category');
1000+
});
1001+
9811002
it('should adapt default axis ranges to *rangemode*', function() {
9821003
layoutIn = {
9831004
xaxis: {rangemode: 'tozero'},

0 commit comments

Comments
 (0)