Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(axis): Added y2 axis and legend width to xAxisTickTextY2Overflow calculation #3571

Closed
wants to merge 2 commits into from
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
4 changes: 3 additions & 1 deletion src/ChartInternal/Axis/Axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,12 @@ class Axis {
!config.axis_x_tick_multiline &&
positiveRotation
) {
const y2AxisWidth = (state.orgConfig.axis?.y2?.show && state.current.maxTickSize.y2.width) || 0;
const legendWidth = (state.isLegendRight && state.legendItemWidth) || 0;
const widthWithoutCurrentPaddingLeft = state.current.width - $$.getCurrentPaddingByDirection("left");
const maxOverflow = this.getXAxisTickMaxOverflow(
xAxisTickRotate, widthWithoutCurrentPaddingLeft - defaultPadding
);
) - y2AxisWidth - legendWidth;
const xAxisTickTextY2Overflow = Math.max(0, maxOverflow) +
defaultPadding; // for display inconsistencies between browsers

Expand Down
5 changes: 3 additions & 2 deletions src/ChartInternal/internals/size.axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ export default {
*/
needToRotateXAxisTickTexts(): boolean {
const $$ = this;
const {state: {axis, current}} = $$;
const xAxisLength = current.width -
const {state: {axis, current, isLegendRight, legendItemWidth}} = $$;
const legendWidth = isLegendRight && legendItemWidth;
const xAxisLength = current.width - legendWidth -
$$.getCurrentPaddingByDirection("left") - $$.getCurrentPaddingByDirection("right");
const tickCountWithPadding = axis.x.tickCount +
axis.x.padding.left + axis.x.padding.right;
Expand Down
40 changes: 36 additions & 4 deletions test/internals/axis-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,38 @@ describe("AXIS", function() {
compare(0, 18.8125, 48, 0);
});

it("update args", () => {
args = {
...args,
legend: {
position: "right"
}
};
args.data.columns[0] = [
"x",
"categoryname1111",
"categoryname2222",
"categoryname3333",
"categoryname4444",
"categoryname5555",
"categoryname6666"
]
});

it("should rotate tick texts if there is not enough space between ticks and legend is right", () => {
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.equal("rotate(15)");
expect(text.attr("y")).to.be.equal("9");
expect(tspan.attr("dx")).to.be.equal("2.070552360820166");
});

compare(15, 43, 53, 10)
});

it("update args", () => {
args.data.columns[0] = [
"x",
Expand All @@ -1376,13 +1408,13 @@ describe("AXIS", function() {
expect(tspan.attr("dx")).to.be.equal("2.070552360820166");
});

compare(15, 45, 56, 71)
compare(15, 45, 56, 18)
});

it("should not resize x axis when all data hidden", () => {
chart.hide("data1");

compare(args.axis.x.tick.rotate, 6, 55, 71);
compare(args.axis.x.tick.rotate, 6, 55, 18);

chart.show("data1");
});
Expand Down Expand Up @@ -1422,7 +1454,7 @@ describe("AXIS", function() {
});

it("should be above 0 if rotated", () => {
compareOverflow(71);
compareOverflow(18);
});

it("update config", () => {
Expand All @@ -1438,7 +1470,7 @@ describe("AXIS", function() {
});

it("should be above defaultPadding if padding left is set", () => {
compareOverflow( 80);
compareOverflow( 27);
});

it("update config", () => {
Expand Down