blob: 3677f6835faf2bfdaaa019c0ab401ac2649a4b81 [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() {
avm999639f5952a2018-12-31 01:36:38 +01007 circleMode = !circleMode;
8 document.querySelector("#circle-mode i").innerText = (circleMode ? "scatter_plot" : "trip_origin");
9 s.graph.nodes().forEach(function(n) {
10 n.x = (circleMode ? n.circleX : n.originalX);
11 n.y = (circleMode ? n.circleY : n.originalY);
12 n.size = 10;
13 });
Javier López-Contreras052503f2018-12-26 12:34:42 +010014
avm999639f5952a2018-12-31 01:36:38 +010015 s.refresh();
avm99963027b5b02018-12-28 02:31:46 +010016 });
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010017}
18
avm99963027b5b02018-12-28 02:31:46 +010019function isInRect(x, y, rect) {
20 if (x < -10000 || x > 10000) return true;
21 if (y < -10000 || y > 10000) return true;
22
23 var ans = true;
avm999639f5952a2018-12-31 01:36:38 +010024 var c = crossProd(rect[0], rect[1], x, y);
avm99963027b5b02018-12-28 02:31:46 +010025
avm999639f5952a2018-12-31 01:36:38 +010026 for (var i = 1; i < 4; i++) {
27 var temp = crossProd(rect[i], rect[(i+1)%4], x, y);
avm99963027b5b02018-12-28 02:31:46 +010028 if (c*temp < 0) ans = false;
29 }
30 return ans;
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010031}
32
33function crossProd(r1, r2, x, y) {
avm99963027b5b02018-12-28 02:31:46 +010034 return r1[0]*r2[1] + r2[0]*y + x*r1[1] - r1[0]*y - r2[0]*r1[1] - x*r2[1];
35}