Skip to content

Commit

Permalink
fix(axis): calculate x axis height correctly for negative tick rotati…
Browse files Browse the repository at this point in the history
…on settings

use absolute rotate value for calculation inside getHorizontalAxisHeight()

Fix #1994
Close #1995
  • Loading branch information
GDFaber authored and netil committed Mar 23, 2021
1 parent de06361 commit fe42e64
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Artem Savienkov <[email protected]>
Hamid Sarfraz <[email protected]>
Alan Hamlett <[email protected]>
Nicolas Forêt <[email protected]>
Marc Faber <[email protected]>
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/size.axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
) {
h = 30 +
$$.axis.getMaxTickWidth(id) *
Math.cos(Math.PI * (90 - rotate) / 180);
Math.cos(Math.PI * (90 - Math.abs(rotate)) / 180);

if (!config.axis_x_tick_multiline && current.height) {
if (h > current.height / 2) {
Expand Down
47 changes: 46 additions & 1 deletion test/internals/axis-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ describe("AXIS", function() {
});

describe("axis.x.tick.rotate", () => {
describe("not rotated", () => {
describe("rotation > 0", () => {
before(() => {
args = {
data: {
Expand Down Expand Up @@ -1073,6 +1073,51 @@ describe("AXIS", function() {
expect(height).to.be.below(80);
});
});

describe("rotation < 0", () => {
before(() => {
args = {
data: {
x: "x",
columns: [
["x", "category 1", "category 2", "category 3", "category 4", "category 5", "category 6"],
["data1", 30, 200, 100, 400, 150, 250],
["data2", 50, 20, 10, 40, 15, 25]
]
},
axis: {
x: {
type: "category",
tick: {
rotate: -60
}
}
}
};
});

it("should rotate tick texts", () => {
chart.$.main.selectAll(`.${CLASS.axisX} g.tick`).each(function() {
const tick = d3Select(this);
const text = tick.select("text");
const tspan = text.select("tspan");

expect(text.attr("transform")).to.be.equal("rotate(-60)");
expect(text.attr("y")).to.be.equal("1.5");
expect(tspan.attr("dx")).to.be.equal("-6.928203230275509");
});
});

it("should have automatically calculated x axis height", () => {
const internal = chart.internal;
const box = internal.$el.main.select(`.${CLASS.axisX}`).node().getBoundingClientRect();
const height = internal.getHorizontalAxisHeight("x");

expect(box.height).to.be.above(50);
expect(height).to.be.above(68);
expect(height).to.be.below(80);
});
});
});

describe("axis.x.tick.autorotate", () => {
Expand Down

0 comments on commit fe42e64

Please sign in to comment.