Skip to content

Commit

Permalink
fix(axis): fix error when showing tick only
Browse files Browse the repository at this point in the history
Do not call .getBBox() for empty node

Fix #3881
  • Loading branch information
netil authored Sep 20, 2024
1 parent 385907e commit 705947f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/ChartInternal/Axis/AxisRendererHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export default class AxisRendererHelper {
w: 5.5,
h: 11.5
};
const text = node?.select("text");

!node.empty() && node.select("text")
!text.empty() && text

This comment has been minimized.

Copy link
@boris-petrov

boris-petrov Sep 20, 2024

@netil isn't there a possibility for a NPE here? node is nullable on the line above so text could also be null/undefined here?

This comment has been minimized.

Copy link
@netil

netil Sep 20, 2024

Author Member

node is required param here.
I'll fix some of the types to clarify on this. Thanks!

.text("0")
.call(el => {
try {
Expand Down
6 changes: 3 additions & 3 deletions test/api/export-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ describe("API export", () => {

// pattern for local: preserveFontStyle=true
[
"byuVSgeSACZuGnZIBBJFgAQwUbjZWVoQIAFMi6UoZ1gEhoeHzxORj7",
"gEMwIYvjgilxAsgoYFymZLtEoI4ACaBlzpB5Aqh4u1HAwik2LwOTAFo2",
"n3KPP7RFhvxMH97ZLyZpsgzMpjX2Qk8O3IUePj1WqYqk0kYkwz"
"i2iAoIcLvwVDzzAQUBmuodjmOmu+NeryqrOrq4jsyozKyLzy99vftNVcb343ou",
"JXSOKRvoLXeaeBnwyQ3q5TJIDtEMpaehdeQBLArBlL9P1Ni",
"iDzpkxgBoCd9qkExwC4O8qSCPVk3lyWshNuFqQAdJNm6rb+GVkH2CdOcenYIgj5Cy"
],

// pattern for webdriverio
Expand Down
39 changes: 39 additions & 0 deletions test/internals/axis-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,45 @@ describe("AXIS", function() {
expect(axis.selectAll(".tick line").size()).to.be.equal(0);
});
});

it("set options", () => {
args = {
data: {
columns: [
["data1", 90, 100, 140, 200, 100]
],
type: "bar",
},
axis: {
x: {
tick: {
show: false,
text: {
show: false
}
}
},
y: {
tick: {
show: false,
text: {
show: false
}
}
}
}
};
});

it("should show tick without error", () => {
expect(
chart.config("axis.y.tick.show", true, true)
).to.not.throw;

expect(
chart.internal.$el.axis.y.selectAll(".tick").size() > 0
).to.be.true;
});
});

describe("axis text on 'binary floating point'", () => {
Expand Down

0 comments on commit 705947f

Please sign in to comment.