blob: 492c6c6b3968682100be8006e0793668cf5ae67a [file] [log] [blame]
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +01001// *********** HERE STARTS circle-mode.js *************
2
Javier López-Contreras052503f2018-12-26 12:34:42 +01003circleMode = false;
4
5function initCircleMode() {
avm99963027b5b02018-12-28 02:31:46 +01006 document.querySelector("#circle-mode").addEventListener('click', function() {
7 if(circleMode) {
8 circleMode = false;
9 document.querySelector("#circle-mode i").innerText = "trip_origin";
Javier López-Contreras052503f2018-12-26 12:34:42 +010010
avm99963027b5b02018-12-28 02:31:46 +010011 s.graph.nodes().forEach(function(n) {
12 n.x = n.originalX;
13 n.y = n.originalY;
14 n.size = 10;
15 });
16
17 s.refresh();
18 } else {
19 circleMode = true;
20 document.querySelector("#circle-mode i").innerText = "scatter_plot";
21
22 s.graph.nodes().forEach(function(n) {
23 n.x = n.circleX;
24 n.y = n.circleY;
25 });
26
27 s.refresh();
28 }
29 });
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010030}
31
avm99963027b5b02018-12-28 02:31:46 +010032function isInRect(x, y, rect) {
33 if (x < -10000 || x > 10000) return true;
34 if (y < -10000 || y > 10000) return true;
35
36 var ans = true;
37 var c = crossProd (rect[0], rect[1], x, y);
38
39 for(var i = 1; i < 4; i++) {
40 var temp = crossProd (rect[i], rect[(i+1)%4], x, y);
41 if (c*temp < 0) ans = false;
42 }
43 return ans;
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010044}
45
46function crossProd(r1, r2, x, y) {
avm99963027b5b02018-12-28 02:31:46 +010047 return r1[0]*r2[1] + r2[0]*y + x*r1[1] - r1[0]*y - r2[0]*r1[1] - x*r2[1];
48}