Skip to content

Commit c35e5c4

Browse files
authored
Merge pull request #5586 from plotly/fix5402-inside-ticks-on-overlaid-axes
Take into account inside labels of overlaid axes in autorange padding
2 parents e446743 + 79ec5b7 commit c35e5c4

File tree

4 files changed

+109
-37
lines changed

4 files changed

+109
-37
lines changed

src/plots/cartesian/autorange.js

+46-37
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function makePadFn(fullLayout, ax, max) {
217217

218218
var zero = 0;
219219
if(!isLinked(fullLayout, ax._id)) {
220-
zero = padInsideLabelsOnAnchorAxis(ax, max);
220+
zero = padInsideLabelsOnAnchorAxis(fullLayout, ax, max);
221221
}
222222
extrappad = Math.max(zero, extrappad);
223223

@@ -236,45 +236,54 @@ function makePadFn(fullLayout, ax, max) {
236236

237237
var TEXTPAD = 3;
238238

239-
function padInsideLabelsOnAnchorAxis(ax, max) {
239+
function padInsideLabelsOnAnchorAxis(fullLayout, ax, max) {
240240
var pad = 0;
241-
var anchorAxis = ax._anchorAxis || {};
242-
if((anchorAxis.ticklabelposition || '').indexOf('inside') !== -1) {
243-
// increase padding to make more room for inside tick labels of the counter axis
244-
if((
245-
!max && (
246-
anchorAxis.side === 'left' ||
247-
anchorAxis.side === 'bottom'
248-
)
249-
) || (
250-
max && (
251-
anchorAxis.side === 'top' ||
252-
anchorAxis.side === 'right'
253-
)
254-
)) {
255-
var isX = ax._id.charAt(0) === 'x';
256-
257-
if(anchorAxis._vals) {
258-
var rad = Lib.deg2rad(anchorAxis._tickAngles[anchorAxis._id + 'tick'] || 0);
259-
var cosA = Math.abs(Math.cos(rad));
260-
var sinA = Math.abs(Math.sin(rad));
261-
262-
// use bounding boxes
263-
anchorAxis._vals.forEach(function(t) {
264-
if(t.bb) {
265-
var w = 2 * TEXTPAD + t.bb.width;
266-
var h = 2 * TEXTPAD + t.bb.height;
267-
268-
pad = Math.max(pad, isX ?
269-
Math.max(w * cosA, h * sinA) :
270-
Math.max(h * cosA, w * sinA)
271-
);
241+
242+
var isX = ax._id.charAt(0) === 'x';
243+
244+
for(var subplot in fullLayout._plots) {
245+
var plotinfo = fullLayout._plots[subplot];
246+
247+
if(ax._id !== plotinfo.xaxis._id && ax._id !== plotinfo.yaxis._id) continue;
248+
249+
var anchorAxis = (isX ? plotinfo.yaxis : plotinfo.xaxis) || {};
250+
251+
if((anchorAxis.ticklabelposition || '').indexOf('inside') !== -1) {
252+
// increase padding to make more room for inside tick labels of the counter axis
253+
if((
254+
!max && (
255+
anchorAxis.side === 'left' ||
256+
anchorAxis.side === 'bottom'
257+
)
258+
) || (
259+
max && (
260+
anchorAxis.side === 'top' ||
261+
anchorAxis.side === 'right'
262+
)
263+
)) {
264+
if(anchorAxis._vals) {
265+
var rad = Lib.deg2rad(anchorAxis._tickAngles[anchorAxis._id + 'tick'] || 0);
266+
var cosA = Math.abs(Math.cos(rad));
267+
var sinA = Math.abs(Math.sin(rad));
268+
269+
// use bounding boxes
270+
for(var i = 0; i < anchorAxis._vals.length; i++) {
271+
var t = anchorAxis._vals[i];
272+
if(t.bb) {
273+
var w = 2 * TEXTPAD + t.bb.width;
274+
var h = 2 * TEXTPAD + t.bb.height;
275+
276+
pad = Math.max(pad, isX ?
277+
Math.max(w * cosA, h * sinA) :
278+
Math.max(h * cosA, w * sinA)
279+
);
280+
}
272281
}
273-
});
274-
}
282+
}
275283

276-
if(anchorAxis.ticks === 'inside' && anchorAxis.ticklabelposition === 'inside') {
277-
pad += anchorAxis.ticklen || 0;
284+
if(anchorAxis.ticks === 'inside' && anchorAxis.ticklabelposition === 'inside') {
285+
pad += anchorAxis.ticklen || 0;
286+
}
278287
}
279288
}
280289
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"data": [
3+
{
4+
"y": [0, 100],
5+
"yaxis": "y"
6+
},
7+
{
8+
"y": [100, 0],
9+
"yaxis": "y2"
10+
},
11+
{
12+
"x": [0, 100],
13+
"xaxis": "x2",
14+
"yaxis": "y3"
15+
},
16+
{
17+
"x": [100, 0],
18+
"xaxis": "x3",
19+
"yaxis": "y3"
20+
}
21+
],
22+
"layout": {
23+
"width": 300,
24+
"height": 400,
25+
"margin": {
26+
"t": 40,
27+
"b": 40,
28+
"l": 40,
29+
"r": 40
30+
},
31+
"plot_bgcolor": "lightblue",
32+
"showlegend": false,
33+
"yaxis": {
34+
"domain" : [0, 0.45],
35+
"anchor": "x",
36+
"ticklabelposition": "inside",
37+
"side": "left"
38+
},
39+
"yaxis2": {
40+
"overlaying": "y",
41+
"anchor": "x",
42+
"ticklabelposition": "inside",
43+
"side": "right"
44+
},
45+
"yaxis3": {
46+
"anchor": "x3",
47+
"domain" : [0.55, 1]
48+
},
49+
"xaxis2": {
50+
"overlaying": "x3",
51+
"anchor": "y3",
52+
"ticklabelposition": "inside",
53+
"side": "bottom"
54+
},
55+
"xaxis3": {
56+
"anchor": "y3",
57+
"ticklabelposition": "inside",
58+
"side": "top"
59+
}
60+
}
61+
}

test/jasmine/tests/mock_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ var list = [
973973
'ticklabelposition-b',
974974
'ticklabelposition-c',
975975
'ticklabelposition-d',
976+
'ticklabelposition-overlay',
976977
'tickson_boundaries',
977978
'titles-avoid-labels',
978979
'trace_metatext',
@@ -2062,6 +2063,7 @@ figs['ticklabelposition-a'] = require('@mocks/ticklabelposition-a');
20622063
figs['ticklabelposition-b'] = require('@mocks/ticklabelposition-b');
20632064
figs['ticklabelposition-c'] = require('@mocks/ticklabelposition-c');
20642065
figs['ticklabelposition-d'] = require('@mocks/ticklabelposition-d');
2066+
figs['ticklabelposition-overlay'] = require('@mocks/ticklabelposition-overlay');
20652067
figs['tickson_boundaries'] = require('@mocks/tickson_boundaries');
20662068
// figs['titles-avoid-labels'] = require('@mocks/titles-avoid-labels');
20672069
// figs['trace_metatext'] = require('@mocks/trace_metatext');

0 commit comments

Comments
 (0)