blob: c4aac8433657c58d53d7545590a142f0e7cd557b [file] [log] [blame]
Javier López-Contreras052503f2018-12-26 12:34:42 +01001circleMode = false;
2
3function initCircleMode() {
avm99963027b5b02018-12-28 02:31:46 +01004 document.querySelector("#circle-mode").addEventListener('click', function() {
avm999639f5952a2018-12-31 01:36:38 +01005 circleMode = !circleMode;
6 document.querySelector("#circle-mode i").innerText = (circleMode ? "scatter_plot" : "trip_origin");
7 s.graph.nodes().forEach(function(n) {
8 n.x = (circleMode ? n.circleX : n.originalX);
9 n.y = (circleMode ? n.circleY : n.originalY);
10 n.size = 10;
11 });
Javier López-Contreras052503f2018-12-26 12:34:42 +010012
avm999639f5952a2018-12-31 01:36:38 +010013 s.refresh();
avm99963027b5b02018-12-28 02:31:46 +010014 });
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010015}
16
avm99963027b5b02018-12-28 02:31:46 +010017function isInRect(x, y, rect) {
18 if (x < -10000 || x > 10000) return true;
19 if (y < -10000 || y > 10000) return true;
20
21 var ans = true;
avm999639f5952a2018-12-31 01:36:38 +010022 var c = crossProd(rect[0], rect[1], x, y);
avm99963027b5b02018-12-28 02:31:46 +010023
avm999639f5952a2018-12-31 01:36:38 +010024 for (var i = 1; i < 4; i++) {
25 var temp = crossProd(rect[i], rect[(i+1)%4], x, y);
avm99963027b5b02018-12-28 02:31:46 +010026 if (c*temp < 0) ans = false;
27 }
28 return ans;
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010029}
30
31function crossProd(r1, r2, x, y) {
avm99963027b5b02018-12-28 02:31:46 +010032 return r1[0]*r2[1] + r2[0]*y + x*r1[1] - r1[0]*y - r2[0]*r1[1] - x*r2[1];
33}