Skip to content

Commit 49ba846

Browse files
committed
search for links in constraint and match groups
1 parent 0086aaa commit 49ba846

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed

src/plots/cartesian/autorange.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ var Lib = require('../../lib');
1414
var FP_SAFE = require('../../constants/numerical').FP_SAFE;
1515
var Registry = require('../../registry');
1616

17-
var getFromId = require('./axis_ids').getFromId;
17+
var axIds = require('./axis_ids');
18+
var getFromId = axIds.getFromId;
19+
var isLinked = axIds.isLinked;
1820

1921
module.exports = {
2022
getAutoRange: getAutoRange,
@@ -56,8 +58,9 @@ function getAutoRange(gd, ax) {
5658
var i, j;
5759
var newRange = [];
5860

59-
var getPadMin = makePadFn(ax, 0);
60-
var getPadMax = makePadFn(ax, 1);
61+
var fullLayout = gd._fullLayout;
62+
var getPadMin = makePadFn(fullLayout, ax, 0);
63+
var getPadMax = makePadFn(fullLayout, ax, 1);
6164
var extremes = concatExtremes(gd, ax);
6265
var minArray = extremes.min;
6366
var maxArray = extremes.max;
@@ -202,7 +205,7 @@ function calcBreaksLength(ax, v0, v1) {
202205
* calculate the pixel padding for ax._min and ax._max entries with
203206
* optional extrapad as 5% of the total axis length
204207
*/
205-
function makePadFn(ax, max) {
208+
function makePadFn(fullLayout, ax, max) {
206209
// 5% padding for points that specify extrapad: true
207210
var extrappad = 0.05 * ax._length;
208211

@@ -222,11 +225,7 @@ function makePadFn(ax, max) {
222225

223226
var A = 0;
224227
var B = 0;
225-
226-
if(
227-
!anchorAxis.matches && !ax.matches &&
228-
!anchorAxis.scaleanchor && !ax.scaleanchor
229-
) {
228+
if(!isLinked(fullLayout, ax._id)) {
230229
A = padInsideLabelsOnAnchorAxis(ax, max);
231230
B = padInsideLabelsOnThisAxis(ax, max);
232231
}

src/plots/cartesian/axes.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ axes.list = axisIds.list;
6363
axes.listIds = axisIds.listIds;
6464
axes.getFromId = axisIds.getFromId;
6565
axes.getFromTrace = axisIds.getFromTrace;
66+
axes.isLinked = axisIds.isLinked;
6667

6768
var autorange = require('./autorange');
6869
axes.getAutoRange = autorange.getAutoRange;
@@ -3202,26 +3203,26 @@ axes.drawLabels = function(gd, ax, opts) {
32023203
});
32033204
}
32043205

3205-
var anchorAx = ax._anchorAxis;
3206-
if(
3207-
anchorAx && anchorAx.autorange &&
3208-
!anchorAx.matches && !ax.matches &&
3209-
!anchorAx.scaleanchor && !ax.scaleanchor &&
3210-
(ax.ticklabelposition || '').indexOf('inside') !== -1
3211-
) {
3212-
if(!fullLayout._insideTickLabelsAutorange) {
3213-
fullLayout._insideTickLabelsAutorange = {};
3214-
}
3215-
fullLayout._insideTickLabelsAutorange[anchorAx._name + '.autorange'] = anchorAx.autorange;
3216-
3217-
seq.push(
3218-
function computeFinalTickLabelBoundingBoxes() {
3219-
tickLabels.each(function(d, i) {
3220-
var thisLabel = selectTickLabel(this);
3221-
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
3222-
});
3206+
if(!axisIds.isLinked(fullLayout, ax._id)) {
3207+
var anchorAx = ax._anchorAxis;
3208+
if(
3209+
anchorAx && anchorAx.autorange &&
3210+
(ax.ticklabelposition || '').indexOf('inside') !== -1
3211+
) {
3212+
if(!fullLayout._insideTickLabelsAutorange) {
3213+
fullLayout._insideTickLabelsAutorange = {};
32233214
}
3224-
);
3215+
fullLayout._insideTickLabelsAutorange[anchorAx._name + '.autorange'] = anchorAx.autorange;
3216+
3217+
seq.push(
3218+
function computeFinalTickLabelBoundingBoxes() {
3219+
tickLabels.each(function(d, i) {
3220+
var thisLabel = selectTickLabel(this);
3221+
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
3222+
});
3223+
}
3224+
);
3225+
}
32253226
}
32263227

32273228
var done = Lib.syncOrAsync(seq);

src/plots/cartesian/axis_ids.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,26 @@ exports.ref2id = function(ar) {
136136
// return the axis ID. Otherwise it returns false.
137137
return (/^[xyz]/.test(ar)) ? ar.split(' ')[0] : false;
138138
};
139+
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;
148+
}
149+
});
150+
151+
if(!linked) {
152+
(fullLayout._axisMatchGroups || []).forEach(function(e) {
153+
if(e[axId]) {
154+
linked = true;
155+
return;
156+
}
157+
});
158+
}
159+
160+
return linked;
161+
};

src/plots/cartesian/constraints.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ exports.enforce = function enforce(gd) {
565565
// *are* expanding to the full domain
566566
var outerMin = rangeCenter - halfRange * factor * 1.0001;
567567
var outerMax = rangeCenter + halfRange * factor * 1.0001;
568-
var getPadMin = autorange.makePadFn(ax, 0);
569-
var getPadMax = autorange.makePadFn(ax, 1);
568+
var getPadMin = autorange.makePadFn(fullLayout, ax, 0);
569+
var getPadMax = autorange.makePadFn(fullLayout, ax, 1);
570570

571571
updateDomain(ax, factor);
572572
var m = Math.abs(ax._m);

0 commit comments

Comments
 (0)