1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Connector = void 0;
|
4 | const Utils_1 = require("../../../Utils");
|
5 | const Enums_1 = require("../../../Enums");
|
6 | const ExternalInteractorBase_1 = require("../../../Core/ExternalInteractorBase");
|
7 | class Connector extends ExternalInteractorBase_1.ExternalInteractorBase {
|
8 | constructor(container) {
|
9 | super(container);
|
10 | }
|
11 | isEnabled() {
|
12 | const container = this.container, mouse = container.interactivity.mouse, events = container.actualOptions.interactivity.events;
|
13 | if (!(events.onHover.enable && mouse.position)) {
|
14 | return false;
|
15 | }
|
16 | return (0, Utils_1.isInArray)(Enums_1.HoverMode.connect, events.onHover.mode);
|
17 | }
|
18 | reset() {
|
19 | }
|
20 | interact() {
|
21 | const container = this.container, options = container.actualOptions;
|
22 | if (options.interactivity.events.onHover.enable && container.interactivity.status === "mousemove") {
|
23 | const mousePos = container.interactivity.mouse.position;
|
24 | if (!mousePos) {
|
25 | return;
|
26 | }
|
27 | const distance = Math.abs(container.retina.connectModeRadius), query = container.particles.quadTree.queryCircle(mousePos, distance);
|
28 | let i = 0;
|
29 | for (const p1 of query) {
|
30 | const pos1 = p1.getPosition();
|
31 | for (const p2 of query.slice(i + 1)) {
|
32 | const pos2 = p2.getPosition(), distMax = Math.abs(container.retina.connectModeDistance), xDiff = Math.abs(pos1.x - pos2.x), yDiff = Math.abs(pos1.y - pos2.y);
|
33 | if (xDiff < distMax && yDiff < distMax) {
|
34 | container.canvas.drawConnectLine(p1, p2);
|
35 | }
|
36 | }
|
37 | ++i;
|
38 | }
|
39 | }
|
40 | }
|
41 | }
|
42 | exports.Connector = Connector;
|