From 979622d4cbca7d0d32a11ffac43a0727aba475e2 Mon Sep 17 00:00:00 2001 From: netil Date: Thu, 26 Oct 2023 22:51:10 +0900 Subject: [PATCH] fix(tooltip): Fix tooltip error on Arc type Side effect caused by #3475. The condition set where valid only for axis based chart Ref https://github.com/naver/billboard.js/issues/3473#issuecomment-1781091685 --- src/ChartInternal/internals/size.ts | 8 +++++--- test/esm/donut-spec.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ChartInternal/internals/size.ts b/src/ChartInternal/internals/size.ts index b6e1cbb7d..8281f9f94 100644 --- a/src/ChartInternal/internals/size.ts +++ b/src/ChartInternal/internals/size.ts @@ -86,16 +86,18 @@ export default { getSvgLeft(withoutRecompute?: boolean): number { const $$ = this; - const {config, $el} = $$; + const {config, state: {hasAxis}, $el} = $$; const isRotated = config.axis_rotated; const hasLeftAxisRect = isRotated || (!isRotated && !config.axis_y_inner); const leftAxisClass = isRotated ? $AXIS.axisX : $AXIS.axisY; const leftAxis = $el.main.select(`.${leftAxisClass}`).node(); - const leftLabel = config[`axis_${isRotated ? "x" : "y"}_label`]; + const leftLabel = hasAxis && config[`axis_${isRotated ? "x" : "y"}_label`]; let labelWidth = 0; // if axis label position set to inner, exclude from the value - if (isString(leftLabel) || isString(leftLabel.text) || /^inner-/.test(leftLabel?.position)) { + if (hasAxis && ( + isString(leftLabel) || isString(leftLabel.text) || /^inner-/.test(leftLabel?.position) + )) { const label = $el.main.select(`.${leftAxisClass}-label`); if (!label.empty()) { diff --git a/test/esm/donut-spec.ts b/test/esm/donut-spec.ts index 43ba6ca9f..a2e45a43e 100644 --- a/test/esm/donut-spec.ts +++ b/test/esm/donut-spec.ts @@ -43,4 +43,12 @@ describe("ESM donut", function() { done(); }, 500); }); + + it("shouldn't throw error on call of tooltip API.", () => { + delete chart.internal.config.axis_y_label; + + chart.tooltip.show({x:0}); + + chart.internal.config.axis_y_label = {}; + }); });