|
9 | 9 | 'use strict'; |
10 | 10 |
|
11 | 11 | var Registry = require('../../registry'); |
12 | | -var Lib = require('../../lib'); |
13 | 12 |
|
14 | 13 | var constants = require('./constants'); |
15 | 14 |
|
@@ -40,53 +39,43 @@ exports.cleanId = function cleanId(id, axLetter) { |
40 | 39 | return id.charAt(0) + axNum; |
41 | 40 | }; |
42 | 41 |
|
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) { |
47 | 44 | var fullLayout = gd._fullLayout; |
48 | 45 | if(!fullLayout) return []; |
49 | 46 |
|
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; |
60 | 50 |
|
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)]; |
62 | 54 | } |
63 | 55 |
|
64 | | - var names = filterAxis(fullLayout, ''); |
65 | | - if(only2d) return names; |
| 56 | + if(!only2d) { |
| 57 | + var sceneIds3D = fullLayout._subplots.gl3d || []; |
66 | 58 |
|
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]]; |
74 | 61 |
|
75 | | - return names; |
76 | | -} |
| 62 | + if(axLetter) out.push(scene[axLetter + 'axis']); |
| 63 | + else out.push(scene.xaxis, scene.yaxis, scene.zaxis); |
| 64 | + } |
| 65 | + } |
77 | 66 |
|
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; |
84 | 68 | }; |
85 | 69 |
|
86 | 70 | // get all axis ids, optionally restricted by letter |
87 | 71 | // 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); |
90 | 79 | }; |
91 | 80 |
|
92 | 81 | // get an axis object from its id 'x','x2' etc |
|
0 commit comments