Skip to content

Commit

Permalink
rotate labels 90deg when they overlap w/ tick-on-boundaries positions
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Nov 22, 2018
1 parent 6d0a3fc commit 09ac230
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,6 @@ axes.drawTicks = function(gd, ax, opts) {
ticks.attr('transform', opts.transFn);
};


/**
* Draw axis grid
*
Expand Down Expand Up @@ -2318,6 +2317,7 @@ axes.drawLabels = function(gd, ax, opts) {
(ax.type !== 'log' || String(ax.dtick).charAt(0) !== 'D')
) {
var lbbArray = [];
var i;

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

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

if(ax.tickson === 'boundaries') {
for(i = 0; i < lbbArray.length; i++) {
if(
(vals[i].xl !== null && (lbbArray[i].left - ax.l2p(vals[i].xbnd[0])) < 2) ||
(vals[i].xr !== null && (ax.l2p(vals[i].xbnd[1]) - lbbArray[i].right) < 2)
) {
autoangle = 90;
break;
}
}
}

if(autoangle) {
var tickspacing = Math.abs(
(vals[vals.length - 1].x - vals[0].x) * ax._m
Expand Down

0 comments on commit 09ac230

Please sign in to comment.