diff --git a/src/ChartInternal/shape/point.ts b/src/ChartInternal/shape/point.ts index fae1b7759..38478643b 100644 --- a/src/ChartInternal/shape/point.ts +++ b/src/ChartInternal/shape/point.ts @@ -378,9 +378,12 @@ export default { const mouse = getPointer(state.event, node); const element = d3Select(node); const prefix = this.isCirclePoint(node) ? "c" : ""; - const sensitivity = config.point_sensitivity === "radius" ? + let pointSensitivity = config.point_sensitivity; + + pointSensitivity = pointSensitivity === "radius" ? node.getAttribute("r") : - config.point_sensitivity; + (isFunction(pointSensitivity) ? node && pointSensitivity(node) : pointSensitivity); + let cx = +element.attr(`${prefix}x`); let cy = +element.attr(`${prefix}y`); @@ -394,7 +397,7 @@ export default { return Math.sqrt( Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2) - ) < (r || sensitivity); + ) < (r || pointSensitivity); }, /** diff --git a/test/shape/point-spec.ts b/test/shape/point-spec.ts index eb8b1dbfc..b92116d29 100644 --- a/test/shape/point-spec.ts +++ b/test/shape/point-spec.ts @@ -277,7 +277,7 @@ describe("SHAPE POINT", () => { tooltip: { grouped: false } - }; + }; }); it("default sensitivity", () => { @@ -431,8 +431,46 @@ describe("SHAPE POINT", () => { expect(args.data.onclick.called).to.be.true; }); - }); + it("set options", () => { + args = { + data: { + columns: [ + ["data1", 450], + ], + onclick: sinon.spy(function() { + console.log("3333333") + }), + type: "line" + }, + point: { + sensitivity: function(r) { + return 10; + }, + r: 10, + focus: { + expand: { + r: 10 + } + } + }, + }; + }); + + it("should data.onclick callback called.", () => { + const {circles} = chart.$; + const {$el: {eventRect}} = chart.internal; + const rect = circles.node().getBoundingClientRect(); + + fireEvent(eventRect.node(), "click", { + clientX: 300, + clientY: 40 + }, chart); + + expect(args.data.onclick.called).to.be.true; + }); + }); + describe("point.focus.only", () => { beforeAll(() => { args = {