From d5b5d09f9e287428aec72cee173f94225a9b8cba Mon Sep 17 00:00:00 2001 From: Kamil Michalski Date: Mon, 8 Jan 2024 16:42:12 +0100 Subject: [PATCH] fix(Axis): Correct x axis height calculation for autorotated x axis tick texts The height of the rotated tick text was also added when the tick texts were not rotated due to the autorotate being enabled. The `maxtickSize.height` is now only added if the tick texts are actually rotated or if multiline is enabled. Fix #3584 Close #3585 --- src/ChartInternal/internals/size.axis.ts | 6 ++++- test/internals/axis-spec.ts | 32 ++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/ChartInternal/internals/size.axis.ts b/src/ChartInternal/internals/size.axis.ts index 3b81e15ce..e7f4e910b 100644 --- a/src/ChartInternal/internals/size.axis.ts +++ b/src/ChartInternal/internals/size.axis.ts @@ -71,7 +71,11 @@ export default { const maxtickSize = $$.axis.getMaxTickSize(id); - if (maxtickSize.height > defaultHeight) { + const isXAxisTickRotated = config.axis_x_tick_rotate > 0 && ( + !config.axis_x_tick_autorotate || $$.needToRotateXAxisTickTexts() + ); + + if ((config.axis_x_tick_multiline || isXAxisTickRotated) && maxtickSize.height > defaultHeight) { h += maxtickSize.height - defaultHeight; } diff --git a/test/internals/axis-spec.ts b/test/internals/axis-spec.ts index 85dcc909e..f0d434545 100644 --- a/test/internals/axis-spec.ts +++ b/test/internals/axis-spec.ts @@ -1349,7 +1349,21 @@ describe("AXIS", function() { expect(tspan.attr("dx")).to.be.equal("0"); }); - compare(0, 18.8125, 48, 0); + compare(0, 18.8125, 30, 0); + }); + + it("should not use the height of the longest tick text when ticks are not rotated", () => { + chart.$.main.selectAll(`.${$AXIS.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.null; + expect(text.attr("y")).to.be.equal("9"); + expect(tspan.attr("dx")).to.be.equal("0"); + }); + + compare(0, 18.8125, 30, 0); }); it("update args", () => { @@ -1535,7 +1549,21 @@ describe("AXIS", function() { expect(tspan.attr("dx")).to.be.equal("0"); }); - compare(0, 18.8125, 55, 0); + compare(0, 18.8125, 30, 0); + }); + + it("should not use the height of the longest tick text when ticks are not rotated", () => { + chart.$.main.selectAll(`.${$AXIS.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.null; + expect(text.attr("y")).to.be.equal("9"); + expect(tspan.attr("dx")).to.be.equal("0"); + }); + + compare(0, 18.8125, 30, 0); }); it("update args", () => {