Skip to content

Commit 09ac230

Browse files
committed
rotate labels 90deg when they overlap w/ tick-on-boundaries positions
1 parent 6d0a3fc commit 09ac230

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/plots/cartesian/axes.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,6 @@ axes.drawTicks = function(gd, ax, opts) {
20592059
ticks.attr('transform', opts.transFn);
20602060
};
20612061

2062-
20632062
/**
20642063
* Draw axis grid
20652064
*
@@ -2318,6 +2317,7 @@ axes.drawLabels = function(gd, ax, opts) {
23182317
(ax.type !== 'log' || String(ax.dtick).charAt(0) !== 'D')
23192318
) {
23202319
var lbbArray = [];
2320+
var i;
23212321

23222322
tickLabels.each(function(d) {
23232323
var s = d3.select(this);
@@ -2339,14 +2339,26 @@ axes.drawLabels = function(gd, ax, opts) {
23392339
});
23402340
});
23412341

2342-
for(var i = 0; i < lbbArray.length - 1; i++) {
2342+
for(i = 0; i < lbbArray.length - 1; i++) {
23432343
if(Lib.bBoxIntersect(lbbArray[i], lbbArray[i + 1])) {
23442344
// any overlap at all - set 30 degrees
23452345
autoangle = 30;
23462346
break;
23472347
}
23482348
}
23492349

2350+
if(ax.tickson === 'boundaries') {
2351+
for(i = 0; i < lbbArray.length; i++) {
2352+
if(
2353+
(vals[i].xl !== null && (lbbArray[i].left - ax.l2p(vals[i].xbnd[0])) < 2) ||
2354+
(vals[i].xr !== null && (ax.l2p(vals[i].xbnd[1]) - lbbArray[i].right) < 2)
2355+
) {
2356+
autoangle = 90;
2357+
break;
2358+
}
2359+
}
2360+
}
2361+
23502362
if(autoangle) {
23512363
var tickspacing = Math.abs(
23522364
(vals[vals.length - 1].x - vals[0].x) * ax._m

0 commit comments

Comments
 (0)