Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8223_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix auto-angling of overlapping tick labels when `tickvals` are not sorted [[#8223](https://github.com/plotly/plotly.js/pull/8223)], with thanks to @toyeshhm for the contribution!
1 change: 1 addition & 0 deletions draftlogs/8226_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix auto-angling of overlapping tick labels when `tickvals` are not sorted [[#8226](https://github.com/plotly/plotly.js/pull/8226)], with thanks to @toyeshhm for the contribution!
1 change: 1 addition & 0 deletions draftlogs/8227_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix auto-angling of overlapping tick labels when `tickvals` are not sorted [[#8227](https://github.com/plotly/plotly.js/pull/8227)], with thanks to @toyeshhm for the contribution!
4 changes: 4 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,10 @@ function arrayTicks(ax, majorOnly) {
}
}

// tickvals may come in any order, but label overlap checks
// compare neighboring ticks, so put them in axis order
ticksOut.sort(function(a, b) { return a.x - b.x; });

ticksOut = filterRangeBreaks(ax, ticksOut);

return ticksOut;
Expand Down
28 changes: 28 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8736,6 +8736,34 @@ describe('test tickmode calculator', function() {
_assert(xMajorConfig.tickvals.length + xMinorConfig.tickvals.length);
}).then(done, done.fail);
});

it('should auto-angle overlapping labels when tickvals are not sorted', function(done) {
function plot(tickvals) {
return Plotly.newPlot(gd, [{x: [0, 5], y: [0, 1]}], {
width: 400,
height: 400,
xaxis: {
range: [-0.5, 5.5],
tickmode: 'array',
tickvals: tickvals,
ticktext: tickvals.map(function(v) { return 'long tick label ' + v; })
}
});
}

plot([0, 1, 2, 3, 4, 5]).then(function() {
expect(gd._fullLayout.xaxis._tickAngles.xtick).toBeCloseTo(30, 3);

return plot([3, 0, 5, 1, 4, 2]);
}).then(function() {
var ax = gd._fullLayout.xaxis;
expect(ax._vals.map(function(d) { return d.x; })).toEqual([0, 1, 2, 3, 4, 5]);
expect(ax._vals.map(function(d) { return d.text; })).toEqual([0, 1, 2, 3, 4, 5].map(function(v) {
return 'long tick label ' + v;
}));
expect(ax._tickAngles.xtick).toBeCloseTo(30, 3);
}).then(done, done.fail);
});
});

describe('sync', function() {
Expand Down
Loading