From 4b9bb93a58ff19d9aa4c443b65b49b273a157a6d Mon Sep 17 00:00:00 2001 From: netil Date: Fri, 15 Nov 2024 15:53:58 +0900 Subject: [PATCH] refactor(point): remove duplication getting sensitivity value --- src/ChartInternal/interactions/eventrect.ts | 5 +---- src/ChartInternal/shape/point.ts | 12 +++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ChartInternal/interactions/eventrect.ts b/src/ChartInternal/interactions/eventrect.ts index ca3887540..623bbc08e 100644 --- a/src/ChartInternal/interactions/eventrect.ts +++ b/src/ChartInternal/interactions/eventrect.ts @@ -671,7 +671,6 @@ export default { clickHandlerForMultipleXS(ctx): void { const $$ = ctx; const {config, state} = $$; - const pointSensitivity = config.point_sensitivity; const targetsToShow = $$.filterTargetsToShow($$.data.targets); if ($$.hasArcType(targetsToShow)) { @@ -680,9 +679,7 @@ export default { const mouse = getPointer(state.event, this); const closest = $$.findClosestFromTargets(targetsToShow, mouse); - const sensitivity = pointSensitivity === "radius" ? closest?.r : ( - isFunction(pointSensitivity) ? closest && pointSensitivity(closest) : pointSensitivity - ); + const sensitivity = $$.getPointSensitivity(closest); if (!closest) { return; diff --git a/src/ChartInternal/shape/point.ts b/src/ChartInternal/shape/point.ts index 38478643b..ed8b4a6dc 100644 --- a/src/ChartInternal/shape/point.ts +++ b/src/ChartInternal/shape/point.ts @@ -374,15 +374,11 @@ export default { }, isWithinCircle(node: SVGElement, r?: number): boolean { - const {config, state} = this; + const {state} = this; const mouse = getPointer(state.event, node); const element = d3Select(node); const prefix = this.isCirclePoint(node) ? "c" : ""; - let pointSensitivity = config.point_sensitivity; - - pointSensitivity = pointSensitivity === "radius" ? - node.getAttribute("r") : - (isFunction(pointSensitivity) ? node && pointSensitivity(node) : pointSensitivity); + const pointSensitivity = this.getPointSensitivity(node); let cx = +element.attr(`${prefix}x`); let cy = +element.attr(`${prefix}y`); @@ -409,7 +405,9 @@ export default { const $$ = this; let sensitivity = $$.config.point_sensitivity; - if (isFunction(sensitivity)) { + if (!d) { + return sensitivity; + } else if (isFunction(sensitivity)) { sensitivity = sensitivity.call($$.api, d); } else if (sensitivity === "radius") { sensitivity = d.r;