Skip to content

Commit 54b559f

Browse files
committed
hide overlapping gridlines over inside ticklabels
1 parent 3f33829 commit 54b559f

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/plots/cartesian/axes.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,12 +2177,18 @@ axes.drawOne = function(gd, ax, opts) {
21772177
// TODO: mirror labels, esp for subplots
21782178

21792179
seq.push(function() {
2180-
return axes.drawLabels(gd, ax, {
2180+
var opts = {
21812181
vals: vals,
21822182
layer: mainAxLayer,
21832183
transFn: transTickLabelFn,
21842184
labelFns: axes.makeLabelFns(ax, mainLinePosition)
2185-
});
2185+
};
2186+
2187+
if(ax._anchorAxis) {
2188+
opts.grid = plotinfo.gridlayer.select('.' + ax._anchorAxis._id);
2189+
}
2190+
2191+
return axes.drawLabels(gd, ax, opts);
21862192
});
21872193

21882194
if(ax.type === 'multicategory') {
@@ -2861,7 +2867,9 @@ axes.drawGrid = function(gd, ax, opts) {
28612867
grid.attr('transform', opts.transFn)
28622868
.attr('d', opts.path)
28632869
.call(Color.stroke, ax.gridcolor || '#ddd')
2864-
.style('stroke-width', ax._gw + 'px');
2870+
.style('stroke-width', ax._gw + 'px')
2871+
.style({ opacity: 100 }); // ensure visible
2872+
28652873

28662874
if(typeof opts.path === 'function') grid.attr('d', opts.path);
28672875
};
@@ -3054,6 +3062,9 @@ axes.drawLabels = function(gd, ax, opts) {
30543062

30553063
var isX = ax._id.charAt(0) === 'x';
30563064

3065+
var visibleLabelMin = Infinity;
3066+
var visibleLabelMax = -Infinity;
3067+
30573068
tickLabels.each(function(d) {
30583069
var thisLabel = d3.select(this);
30593070
var mathjaxGroup = thisLabel.select('.text-math-group');
@@ -3068,9 +3079,31 @@ axes.drawLabels = function(gd, ax, opts) {
30683079
if(bb.bottom > max) hide = true;
30693080
else if(bb.top + (ax.tickangle ? 0 : d.fontSize / 4) < min) hide = true;
30703081
}
3071-
if(hide) thisLabel.select('text').style({ opacity: 0 });
3082+
if(hide) {
3083+
thisLabel.select('text').style({ opacity: 0 });
3084+
} else {
3085+
visibleLabelMin = Math.min(visibleLabelMin, isX ? bb.top : bb.left);
3086+
visibleLabelMax = Math.max(visibleLabelMax, isX ? bb.bottom : bb.right);
3087+
}
30723088
} // TODO: hide mathjax?
30733089
});
3090+
3091+
var anchorAx = ax._anchorAxis || {};
3092+
3093+
if((anchorAx.ticklabelposition || '').indexOf('inside') !== -1) {
3094+
var grid = opts.grid;
3095+
if(grid) {
3096+
grid.each(function() {
3097+
d3.select(this).selectAll('path').each(function(d) {
3098+
var q = anchorAx.l2p(d.x) + anchorAx._offset;
3099+
3100+
if(q < visibleLabelMax && q > visibleLabelMin) {
3101+
d3.select(this).style({ opacity: 0 });
3102+
}
3103+
});
3104+
});
3105+
}
3106+
}
30743107
};
30753108
}
30763109

0 commit comments

Comments
 (0)