Skip to content

Commit 0060786

Browse files
authored
fix(point): fix sensitivity error when blank area is clicked
- prevent getting attribute value from undefined value - treat point.senstivity correctly Fix #3900
1 parent d474d3b commit 0060786

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/ChartInternal/interactions/eventrect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ export default {
671671
clickHandlerForMultipleXS(ctx): void {
672672
const $$ = ctx;
673673
const {config, state} = $$;
674+
const pointSensitivity = config.point_sensitivity;
674675
const targetsToShow = $$.filterTargetsToShow($$.data.targets);
675676

676677
if ($$.hasArcType(targetsToShow)) {
@@ -679,9 +680,9 @@ export default {
679680

680681
const mouse = getPointer(state.event, this);
681682
const closest = $$.findClosestFromTargets(targetsToShow, mouse);
682-
const sensitivity = config.point_sensitivity === "radius" ?
683-
closest.r :
684-
config.point_sensitivity;
683+
const sensitivity = pointSensitivity === "radius" ? closest?.r : (
684+
isFunction(pointSensitivity) ? closest && pointSensitivity(closest) : pointSensitivity
685+
);
685686

686687
if (!closest) {
687688
return;

test/shape/point-spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,49 @@ describe("SHAPE POINT", () => {
388388
done(1);
389389
});
390390
}));
391+
392+
it("set options", () => {
393+
args = {
394+
data: {
395+
columns: [
396+
["data1", 450],
397+
],
398+
type: "bubble",
399+
onclick: sinon.spy()
400+
},
401+
point: {
402+
sensitivity: "radius"
403+
}
404+
}
405+
});
406+
407+
it("shouldn't throw error when blank(non shape) area is clicked.", () => {
408+
const {eventRect} = chart.internal.$el;
409+
410+
expect(
411+
fireEvent(eventRect.node(), "click", {
412+
clientX: 100,
413+
clientY: 100
414+
}, chart)
415+
).to.not.throw;
416+
});
417+
418+
it("set options: poinst.sensitivity=function(){}", () => {
419+
args.point.sensitivity = ({r}) => r
420+
});
421+
422+
it("should data.onclick callback called.", () => {
423+
const {circles} = chart.$;
424+
const {$el: {eventRect}} = chart.internal;
425+
const rect = circles.node().getBoundingClientRect();
426+
427+
fireEvent(eventRect.node(), "click", {
428+
clientX: rect.left + 3,
429+
clientY: rect.top + 3
430+
}, chart);
431+
432+
expect(args.data.onclick.called).to.be.true;
433+
});
391434
});
392435

393436
describe("point.focus.only", () => {

0 commit comments

Comments
 (0)