Skip to content

Commit

Permalink
refactor(point): remove duplication getting sensitivity value
Browse files Browse the repository at this point in the history
  • Loading branch information
netil authored and netil committed Nov 15, 2024
1 parent 3540640 commit 4b9bb93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/ChartInternal/interactions/eventrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/ChartInternal/shape/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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;
Expand Down

0 comments on commit 4b9bb93

Please sign in to comment.