Skip to content

Commit 0506f88

Browse files
committed
use _subplots in Axes.list/listIds
1 parent 6e62b35 commit 0506f88

File tree

7 files changed

+51
-56
lines changed

7 files changed

+51
-56
lines changed

src/plots/cartesian/axes.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ axes.getFromTrace = axisIds.getFromTrace;
5757
* Only required if it's different from `dflt`
5858
*/
5959
axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption) {
60-
var axLetter = attr.charAt(attr.length - 1),
61-
axlist = axes.listIds(gd, axLetter),
62-
refAttr = attr + 'ref',
63-
attrDef = {};
60+
var axLetter = attr.charAt(attr.length - 1);
61+
var axlist = gd._fullLayout._subplots[axLetter + 'axis'];
62+
var refAttr = attr + 'ref';
63+
var attrDef = {};
6464

6565
if(!dflt) dflt = axlist[0] || extraOption;
6666
if(!extraOption) extraOption = dflt;

src/plots/cartesian/axis_ids.js

+24-35
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
'use strict';
1010

1111
var Registry = require('../../registry');
12-
var Lib = require('../../lib');
1312

1413
var constants = require('./constants');
1514

@@ -40,53 +39,43 @@ exports.cleanId = function cleanId(id, axLetter) {
4039
return id.charAt(0) + axNum;
4140
};
4241

43-
// get all axis object names
44-
// optionally restricted to only x or y or z by string axLetter
45-
// and optionally 2D axes only, not those inside 3D scenes
46-
function listNames(gd, axLetter, only2d) {
42+
// get all axis objects, as restricted in listNames
43+
exports.list = function(gd, axLetter, only2d) {
4744
var fullLayout = gd._fullLayout;
4845
if(!fullLayout) return [];
4946

50-
function filterAxis(obj, extra) {
51-
var keys = Object.keys(obj),
52-
axMatch = /^[xyz]axis[0-9]*/,
53-
out = [];
54-
55-
for(var i = 0; i < keys.length; i++) {
56-
var k = keys[i];
57-
if(axLetter && k.charAt(0) !== axLetter) continue;
58-
if(axMatch.test(k)) out.push(extra + k);
59-
}
47+
var idList = exports.listIds(gd, axLetter);
48+
var out = new Array(idList.length);
49+
var i;
6050

61-
return out.sort();
51+
for(i = 0; i < idList.length; i++) {
52+
var idi = idList[i];
53+
out[i] = fullLayout[idi.charAt(0) + 'axis' + idi.substr(1)];
6254
}
6355

64-
var names = filterAxis(fullLayout, '');
65-
if(only2d) return names;
56+
if(!only2d) {
57+
var sceneIds3D = fullLayout._subplots.gl3d || [];
6658

67-
var sceneIds3D = fullLayout._subplots.gl3d || [];
68-
for(var i = 0; i < sceneIds3D.length; i++) {
69-
var sceneId = sceneIds3D[i];
70-
names = names.concat(
71-
filterAxis(fullLayout[sceneId], sceneId + '.')
72-
);
73-
}
59+
for(i = 0; i < sceneIds3D.length; i++) {
60+
var scene = fullLayout[sceneIds3D[i]];
7461

75-
return names;
76-
}
62+
if(axLetter) out.push(scene[axLetter + 'axis']);
63+
else out.push(scene.xaxis, scene.yaxis, scene.zaxis);
64+
}
65+
}
7766

78-
// get all axis objects, as restricted in listNames
79-
exports.list = function(gd, axletter, only2d) {
80-
return listNames(gd, axletter, only2d)
81-
.map(function(axName) {
82-
return Lib.nestedProperty(gd._fullLayout, axName).get();
83-
});
67+
return out;
8468
};
8569

8670
// get all axis ids, optionally restricted by letter
8771
// this only makes sense for 2d axes
88-
exports.listIds = function(gd, axletter) {
89-
return listNames(gd, axletter, true).map(exports.name2id);
72+
exports.listIds = function(gd, axLetter) {
73+
var fullLayout = gd._fullLayout;
74+
if(!fullLayout) return [];
75+
76+
var subplotLists = fullLayout._subplots;
77+
if(axLetter) return subplotLists[axLetter + 'axis'];
78+
return subplotLists.xaxis.concat(subplotLists.yaxis);
9079
};
9180

9281
// get an axis object from its id 'x','x2' etc

test/jasmine/tests/annotations_test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ describe('Test annotations', function() {
2525
function _supply(layoutIn, layoutOut) {
2626
layoutOut = layoutOut || {};
2727
layoutOut._has = Plots._hasPlotType.bind(layoutOut);
28+
layoutOut._subplots = {xaxis: ['x', 'x2'], yaxis: ['y', 'y2']};
29+
['xaxis', 'yaxis', 'xaxis2', 'yaxis2'].forEach(function(axName) {
30+
if(!layoutOut[axName]) layoutOut[axName] = {type: 'linear', range: [0, 1]};
31+
Axes.setConvert(layoutOut[axName]);
32+
});
2833

2934
Annotations.supplyLayoutDefaults(layoutIn, layoutOut);
3035

@@ -89,7 +94,6 @@ describe('Test annotations', function() {
8994
var layoutOut = {
9095
xaxis: { type: 'date', range: ['2000-01-01', '2016-01-01'] }
9196
};
92-
Axes.setConvert(layoutOut.xaxis);
9397

9498
_supply(layoutIn, layoutOut);
9599

@@ -132,10 +136,6 @@ describe('Test annotations', function() {
132136
yaxis2: {type: 'category', range: [0, 1]}
133137
};
134138

135-
['xaxis', 'xaxis2', 'yaxis', 'yaxis2'].forEach(function(k) {
136-
Axes.setConvert(layoutOut[k]);
137-
});
138-
139139
_supply(layoutIn, layoutOut);
140140

141141
expect(layoutOut.annotations[0]._xclick).toBe(10, 'paper x');

test/jasmine/tests/axes_test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,8 @@ describe('Test axes', function() {
12421242
xaxis: { range: [0, 0.5] },
12431243
yaxis: { range: [0, 0.5] },
12441244
xaxis2: { range: [0.5, 1] },
1245-
yaxis2: { range: [0.5, 1] }
1245+
yaxis2: { range: [0.5, 1] },
1246+
_subplots: {xaxis: ['x', 'x2'], yaxis: ['y', 'y2'], cartesian: ['xy', 'x2y2']}
12461247
}
12471248
};
12481249
});
@@ -1318,7 +1319,7 @@ describe('Test axes', function() {
13181319
it('returns array of axes, including the ones in scenes', function() {
13191320
gd = {
13201321
_fullLayout: {
1321-
_subplots: {gl3d: ['scene', 'scene2']},
1322+
_subplots: {xaxis: [], yaxis: [], gl3d: ['scene', 'scene2']},
13221323
scene: {
13231324
xaxis: { _id: 'x' },
13241325
yaxis: { _id: 'y' },

test/jasmine/tests/layout_images_test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ describe('Layout images', function() {
2121

2222
beforeEach(function() {
2323
layoutIn = { images: [] };
24-
layoutOut = { _has: Plots._hasPlotType };
24+
layoutOut = {
25+
_has: Plots._hasPlotType,
26+
_subplots: {xaxis: [], yaxis: []}
27+
};
2528
});
2629

2730
it('should reject when there is no `source`', function() {

test/jasmine/tests/modebar_test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ describe('ModeBar', function() {
2525
return parent;
2626
}
2727

28-
function getMockGraphInfo() {
28+
function getMockGraphInfo(xaxes, yaxes) {
2929
return {
3030
_fullLayout: {
3131
dragmode: 'zoom',
3232
_paperdiv: d3.select(getMockContainerTree()),
33-
_has: Plots._hasPlotType
33+
_has: Plots._hasPlotType,
34+
_subplots: {xaxis: xaxes || [], yaxis: yaxes || []}
3435
},
3536
_fullData: [],
3637
_context: {
@@ -188,7 +189,7 @@ describe('ModeBar', function() {
188189
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
189190
]);
190191

191-
var gd = getMockGraphInfo();
192+
var gd = getMockGraphInfo(['x'], ['y']);
192193
gd._fullLayout._basePlotModules = [{ name: 'cartesian' }];
193194
gd._fullLayout.xaxis = {fixedrange: false};
194195

@@ -206,7 +207,7 @@ describe('ModeBar', function() {
206207
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
207208
]);
208209

209-
var gd = getMockGraphInfo();
210+
var gd = getMockGraphInfo(['x'], ['y']);
210211
gd._fullLayout._basePlotModules = [{ name: 'cartesian' }];
211212
gd._fullLayout.xaxis = {fixedrange: false};
212213
gd._fullData = [{
@@ -230,7 +231,7 @@ describe('ModeBar', function() {
230231
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
231232
]);
232233

233-
var gd = getMockGraphInfo();
234+
var gd = getMockGraphInfo(['x'], ['y']);
234235
gd._fullLayout._basePlotModules = [{ name: 'cartesian' }];
235236
gd._fullLayout.xaxis = {fixedrange: false};
236237
gd._fullData = [{
@@ -364,7 +365,7 @@ describe('ModeBar', function() {
364365
['hoverClosestGl2d']
365366
]);
366367

367-
var gd = getMockGraphInfo();
368+
var gd = getMockGraphInfo(['x'], ['y']);
368369
gd._fullLayout._basePlotModules = [{ name: 'gl2d' }];
369370
gd._fullLayout.xaxis = {fixedrange: false};
370371

@@ -427,7 +428,7 @@ describe('ModeBar', function() {
427428
['toggleHover']
428429
]);
429430

430-
var gd = getMockGraphInfo();
431+
var gd = getMockGraphInfo(['x'], ['y']);
431432
gd._fullData = [{
432433
type: 'scatter',
433434
visible: true,
@@ -569,7 +570,7 @@ describe('ModeBar', function() {
569570

570571
// gives 11 buttons in 5 groups by default
571572
function setupGraphInfo() {
572-
var gd = getMockGraphInfo();
573+
var gd = getMockGraphInfo(['x'], ['y']);
573574
gd._fullLayout._basePlotModules = [{ name: 'cartesian' }];
574575
gd._fullLayout.xaxis = {fixedrange: false};
575576
return gd;

test/jasmine/tests/shapes_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ describe('Test shapes defaults:', function() {
6060
xaxis: {type: 'linear', range: [0, 20]},
6161
yaxis: {type: 'log', range: [1, 5]},
6262
xaxis2: {type: 'date', range: ['2006-06-05', '2006-06-09']},
63-
yaxis2: {type: 'category', range: [-0.5, 7.5]}
63+
yaxis2: {type: 'category', range: [-0.5, 7.5]},
64+
_subplots: {xaxis: ['x', 'x2'], yaxis: ['y', 'y2']}
6465
};
6566

6667
Axes.setConvert(fullLayout.xaxis);

0 commit comments

Comments
 (0)