From 705947f635807e359c5c2f869a7d906e2315a01a Mon Sep 17 00:00:00 2001 From: Jae Sung Park Date: Fri, 20 Sep 2024 11:42:19 +0900 Subject: [PATCH] fix(axis): fix error when showing tick only Do not call .getBBox() for empty node Fix #3881 --- src/ChartInternal/Axis/AxisRendererHelper.ts | 3 +- test/api/export-spec.ts | 6 +-- test/internals/axis-spec.ts | 39 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/ChartInternal/Axis/AxisRendererHelper.ts b/src/ChartInternal/Axis/AxisRendererHelper.ts index d8ac63054..2d0c63771 100644 --- a/src/ChartInternal/Axis/AxisRendererHelper.ts +++ b/src/ChartInternal/Axis/AxisRendererHelper.ts @@ -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 .text("0") .call(el => { try { diff --git a/test/api/export-spec.ts b/test/api/export-spec.ts index 933daed80..2f6a683d4 100644 --- a/test/api/export-spec.ts +++ b/test/api/export-spec.ts @@ -201,9 +201,9 @@ describe("API export", () => { // pattern for local: preserveFontStyle=true [ - "byuVSgeSACZuGnZIBBJFgAQwUbjZWVoQIAFMi6UoZ1gEhoeHzxORj7", - "gEMwIYvjgilxAsgoYFymZLtEoI4ACaBlzpB5Aqh4u1HAwik2LwOTAFo2", - "n3KPP7RFhvxMH97ZLyZpsgzMpjX2Qk8O3IUePj1WqYqk0kYkwz" + "i2iAoIcLvwVDzzAQUBmuodjmOmu+NeryqrOrq4jsyozKyLzy99vftNVcb343ou", + "JXSOKRvoLXeaeBnwyQ3q5TJIDtEMpaehdeQBLArBlL9P1Ni", + "iDzpkxgBoCd9qkExwC4O8qSCPVk3lyWshNuFqQAdJNm6rb+GVkH2CdOcenYIgj5Cy" ], // pattern for webdriverio diff --git a/test/internals/axis-spec.ts b/test/internals/axis-spec.ts index b6f8f96ac..d0f30aa08 100644 --- a/test/internals/axis-spec.ts +++ b/test/internals/axis-spec.ts @@ -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'", () => {