-
Notifications
You must be signed in to change notification settings - Fork 12
/
interactions.js
70 lines (55 loc) · 1.93 KB
/
interactions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addDrag = exports.addHoverOpacity = exports.addZoom = void 0;
var _d3Drag = require("d3-drag");
var _d3Selection = require("d3-selection");
var _d3Zoom = require("d3-zoom");
var _events = require("./events");
var addZoom = function addZoom(svg, zoomDepth) {
if (zoomDepth) {
var svgHeight = svg._groups[0][0].clientHeight;
var svgWidth = svg._groups[0][0].clientWidth;
var zoomed = function zoomed() {
svg.selectAll("._graphZoom").attr("transform", _d3Selection.event.transform);
};
svg.call((0, _d3Zoom.zoom)().extent([[0, 0], [svgWidth, svgHeight]]).scaleExtent([1, zoomDepth]).on("zoom", zoomed));
}
return svg;
};
exports.addZoom = addZoom;
var addHoverOpacity = function addHoverOpacity(node, link, hoverOpacity) {
node.on('mouseover', function (d) {
node.style('opacity', hoverOpacity);
(0, _d3Selection.select)(this).style('opacity', '1');
link.style('opacity', function (link_d) {
return link_d.source.id === d.id || link_d.target.id === d.id ? '1' : hoverOpacity;
});
}).on('mouseout', function (d) {
node.style('opacity', "1");
link.style('opacity', '1');
});
return {
node: node,
link: link
};
};
exports.addHoverOpacity = addHoverOpacity;
var addDrag = function addDrag(node, simulation, enableDrag, pullIn) {
if (enableDrag) {
node.call((0, _d3Drag.drag)().subject(function () {
return (0, _events.dragsubject)(simulation);
}).on("start", function () {
return (0, _events.dragstarted)(simulation);
}).on("drag", _events.dragged).on("end", pullIn ? function () {
return (0, _events.dragended)(simulation);
} : null));
} else {
node.call((0, _d3Drag.drag)().subject(function () {
return (0, _events.dragsubject)(simulation);
}).on("start", null).on("drag", null).on("end", null));
}
return node;
};
exports.addDrag = addDrag;