Skip to content

Commit

Permalink
fix(size.axis): fix truncated axis when has no data
Browse files Browse the repository at this point in the history
Add gap pixels when tickWidth is zero.

Fix #2675
  • Loading branch information
netil committed May 20, 2022
1 parent 79e1ab7 commit 40f4b66
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ChartInternal/internals/size.axis.ts
Expand Up @@ -25,9 +25,12 @@ export default {

if ($$.axis) {
const position = $$.axis?.getLabelPositionById(id);
const width = $$.axis.getMaxTickWidth(id, withoutRecompute);
const gap = width === 0 ? 0.5 : 0;

return $$.axis.getMaxTickWidth(id, withoutRecompute) +
(position.isInner ? 20 : 40);
return width + (
position.isInner ? (20 + gap) : 40
);
} else {
return 40;
}
Expand Down
27 changes: 27 additions & 0 deletions test/internals/axis-spec.ts
Expand Up @@ -2537,6 +2537,33 @@ describe("AXIS", function() {
axisY.select(".tick:nth-child(12)").node().getBoundingClientRect().width
);
});

it("set option", () => {
args = {
data: {
columns: [
["data1"]
],
empty: {
label: {
text: "No data..."
}
},
type: "line"
},
axis: {
y: {
label: "Your Y Axis"
}
}
};
});

it("<clipPath> width shouldn't truncate y axis tick when has no data", () => {
const rect = chart.internal.$el.defs.selectAll("clipPath[id$='yaxis'] rect");

expect(+rect.attr("width")).to.be.equal(50);
});
});

describe("Axes tick culling", () => {
Expand Down

0 comments on commit 40f4b66

Please sign in to comment.