Skip to content

Commit 3becfb8

Browse files
authored
Merge pull request #5589 from plotly/fix5402-hide-overlapping-inside-labels
Take into account inside labels of overlaid axes in when hiding labels on the counter axis
2 parents 44b3d83 + 32381d5 commit 3becfb8

File tree

4 files changed

+125
-37
lines changed

4 files changed

+125
-37
lines changed

src/plots/cartesian/axes.js

+58-37
Original file line numberDiff line numberDiff line change
@@ -3124,49 +3124,70 @@ axes.drawLabels = function(gd, ax, opts) {
31243124
} // TODO: hide mathjax?
31253125
});
31263126

3127-
if(ax._anchorAxis) {
3128-
ax._anchorAxis._visibleLabelMin = visibleLabelMin;
3129-
ax._anchorAxis._visibleLabelMax = visibleLabelMax;
3127+
for(var subplot in fullLayout._plots) {
3128+
var plotinfo = fullLayout._plots[subplot];
3129+
if(ax._id !== plotinfo.xaxis._id && ax._id !== plotinfo.yaxis._id) continue;
3130+
var anchorAx = isX ? plotinfo.yaxis : plotinfo.xaxis;
3131+
if(anchorAx) {
3132+
anchorAx['_visibleLabelMin_' + ax._id] = visibleLabelMin;
3133+
anchorAx['_visibleLabelMax_' + ax._id] = visibleLabelMax;
3134+
}
31303135
}
31313136
};
31323137

31333138
ax._hideCounterAxisInsideTickLabels = function(partialOpts) {
3134-
if(insideTicklabelposition(ax._anchorAxis || {})) {
3135-
(partialOpts || [
3136-
ZERO_PATH,
3137-
GRID_PATH,
3138-
TICK_PATH,
3139-
TICK_TEXT
3140-
]).forEach(function(e) {
3141-
var isPeriodLabel =
3142-
e.K === 'tick' &&
3143-
e.L === 'text' &&
3144-
ax.ticklabelmode === 'period';
3145-
3146-
var sel;
3147-
if(e.K === ZERO_PATH.K) sel = opts.plotinfo.zerolinelayer.selectAll('.' + ax._id + 'zl');
3148-
else if(e.K === GRID_PATH.K) sel = opts.plotinfo.gridlayer.selectAll('.' + ax._id);
3149-
else sel = opts.plotinfo[ax._id.charAt(0) + 'axislayer'];
3150-
3151-
sel.each(function() {
3152-
var w = d3.select(this);
3153-
if(e.L) w = w.selectAll(e.L);
3154-
3155-
w.each(function(d) {
3156-
var q = ax.l2p(
3157-
isPeriodLabel ? getPosX(d) : d.x
3158-
) + ax._offset;
3159-
3160-
var t = d3.select(this);
3161-
if(q < ax._visibleLabelMax && q > ax._visibleLabelMin) {
3162-
t.style('display', 'none'); // hidden
3163-
} else if(e.K === 'tick') {
3164-
t.style('display', null); // visible
3165-
}
3139+
var isX = ax._id.charAt(0) === 'x';
3140+
3141+
var anchoredAxes = [];
3142+
for(var subplot in fullLayout._plots) {
3143+
var plotinfo = fullLayout._plots[subplot];
3144+
if(ax._id !== plotinfo.xaxis._id && ax._id !== plotinfo.yaxis._id) continue;
3145+
anchoredAxes.push(isX ? plotinfo.yaxis : plotinfo.xaxis);
3146+
}
3147+
3148+
anchoredAxes.forEach(function(anchorAx, idx) {
3149+
if(anchorAx && insideTicklabelposition(anchorAx)) {
3150+
(partialOpts || [
3151+
ZERO_PATH,
3152+
GRID_PATH,
3153+
TICK_PATH,
3154+
TICK_TEXT
3155+
]).forEach(function(e) {
3156+
var isPeriodLabel =
3157+
e.K === 'tick' &&
3158+
e.L === 'text' &&
3159+
ax.ticklabelmode === 'period';
3160+
3161+
var mainPlotinfo = fullLayout._plots[ax._mainSubplot];
3162+
3163+
var sel;
3164+
if(e.K === ZERO_PATH.K) sel = mainPlotinfo.zerolinelayer.selectAll('.' + ax._id + 'zl');
3165+
else if(e.K === GRID_PATH.K) sel = mainPlotinfo.gridlayer.selectAll('.' + ax._id);
3166+
else sel = mainPlotinfo[ax._id.charAt(0) + 'axislayer'];
3167+
3168+
sel.each(function() {
3169+
var w = d3.select(this);
3170+
if(e.L) w = w.selectAll(e.L);
3171+
3172+
w.each(function(d) {
3173+
var q = ax.l2p(
3174+
isPeriodLabel ? getPosX(d) : d.x
3175+
) + ax._offset;
3176+
3177+
var t = d3.select(this);
3178+
if(
3179+
q < ax['_visibleLabelMax_' + anchorAx._id] &&
3180+
q > ax['_visibleLabelMin_' + anchorAx._id]
3181+
) {
3182+
t.style('display', 'none'); // hidden
3183+
} else if(e.K === 'tick' && !idx) {
3184+
t.style('display', null); // visible
3185+
}
3186+
});
31663187
});
31673188
});
3168-
});
3169-
}
3189+
}
3190+
});
31703191
};
31713192

31723193
// make sure all labels are correctly positioned at their base angle
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
"range": [-1.1, 2.1]
49+
},
50+
"xaxis": {
51+
"range": [-1.1, 2.1]
52+
},
53+
"xaxis2": {
54+
"overlaying": "x3",
55+
"anchor": "y3",
56+
"ticklabelposition": "inside",
57+
"side": "bottom"
58+
},
59+
"xaxis3": {
60+
"anchor": "y3",
61+
"ticklabelposition": "inside",
62+
"side": "top"
63+
}
64+
}
65+
}

test/jasmine/tests/mock_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ var list = [
983983
'ticklabelposition-c',
984984
'ticklabelposition-d',
985985
'ticklabelposition-overlay',
986+
'ticklabelposition-overlay2',
986987
'tickson_boundaries',
987988
'titles-avoid-labels',
988989
'trace_metatext',
@@ -2082,6 +2083,7 @@ figs['ticklabelposition-b'] = require('@mocks/ticklabelposition-b');
20822083
figs['ticklabelposition-c'] = require('@mocks/ticklabelposition-c');
20832084
figs['ticklabelposition-d'] = require('@mocks/ticklabelposition-d');
20842085
figs['ticklabelposition-overlay'] = require('@mocks/ticklabelposition-overlay');
2086+
figs['ticklabelposition-overlay2'] = require('@mocks/ticklabelposition-overlay2');
20852087
figs['tickson_boundaries'] = require('@mocks/tickson_boundaries');
20862088
// figs['titles-avoid-labels'] = require('@mocks/titles-avoid-labels');
20872089
// figs['trace_metatext'] = require('@mocks/trace_metatext');

0 commit comments

Comments
 (0)