Skip to content

Commit 2bc8420

Browse files
committed
rewrite forEach and isLinked - add comment - etc
1 parent 21d0a12 commit 2bc8420

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/plots/cartesian/axes.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ axes.setConvert = require('./set_convert');
5656
var autoType = require('./axis_autotype');
5757

5858
var axisIds = require('./axis_ids');
59+
var idSort = axisIds.idSort;
60+
var isLinked = axisIds.isLinked;
61+
62+
// tight coupling to chart studio so should generally not be expanded.
5963
axes.id2name = axisIds.id2name;
6064
axes.name2id = axisIds.name2id;
6165
axes.cleanId = axisIds.cleanId;
6266
axes.list = axisIds.list;
6367
axes.listIds = axisIds.listIds;
6468
axes.getFromId = axisIds.getFromId;
6569
axes.getFromTrace = axisIds.getFromTrace;
66-
axes.isLinked = axisIds.isLinked;
6770

6871
var autorange = require('./autorange');
6972
axes.getAutoRange = autorange.getAutoRange;
@@ -2908,7 +2911,7 @@ axes.drawZeroLine = function(gd, ax, opts) {
29082911
// If several zerolines enter at the same time we will sort once per,
29092912
// but generally this should be a minimal overhead.
29102913
opts.layer.selectAll('path').sort(function(da, db) {
2911-
return axisIds.idSort(da.id, db.id);
2914+
return idSort(da.id, db.id);
29122915
});
29132916
});
29142917

@@ -3207,7 +3210,7 @@ axes.drawLabels = function(gd, ax, opts) {
32073210
if(
32083211
anchorAx && anchorAx.autorange &&
32093212
(ax.ticklabelposition || '').indexOf('inside') !== -1 &&
3210-
!axisIds.isLinked(fullLayout, ax._id)
3213+
!isLinked(fullLayout, ax._id)
32113214
) {
32123215
if(!fullLayout._insideTickLabelsAutorange) {
32133216
fullLayout._insideTickLabelsAutorange = {};

src/plots/cartesian/axis_ids.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,18 @@ exports.ref2id = function(ar) {
137137
return (/^[xyz]/.test(ar)) ? ar.split(' ')[0] : false;
138138
};
139139

140-
141-
exports.isLinked = function(fullLayout, axId) {
142-
var linked = false;
143-
144-
(fullLayout._axisConstraintGroups || []).forEach(function(e) {
145-
if(e[axId]) {
146-
linked = true;
147-
return;
140+
function isFound(axId, list) {
141+
if(list && list.length) {
142+
for(var i = 0; i < list.length; i++) {
143+
if(list[i][axId]) return true;
148144
}
149-
});
150-
151-
if(!linked) {
152-
(fullLayout._axisMatchGroups || []).forEach(function(e) {
153-
if(e[axId]) {
154-
linked = true;
155-
return;
156-
}
157-
});
158145
}
146+
return false;
147+
}
159148

160-
return linked;
149+
exports.isLinked = function(fullLayout, axId) {
150+
return (
151+
isFound(axId, fullLayout._axisMatchGroups) ||
152+
isFound(axId, fullLayout._axisConstraintGroups)
153+
);
161154
};

0 commit comments

Comments
 (0)