Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 1 | // *********** HERE STARTS circle-mode.js *************
|
| 2 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 3 | circleMode = false;
|
| 4 |
|
| 5 | function initCircleMode() {
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 6 | document.querySelector("#circle-mode").addEventListener('click', function() {
|
avm99963 | 9f5952a | 2018-12-31 01:36:38 +0100 | [diff] [blame] | 7 | 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-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 14 |
|
avm99963 | 9f5952a | 2018-12-31 01:36:38 +0100 | [diff] [blame] | 15 | s.refresh();
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 16 | });
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 17 | }
|
| 18 |
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 19 | function 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;
|
avm99963 | 9f5952a | 2018-12-31 01:36:38 +0100 | [diff] [blame] | 24 | var c = crossProd(rect[0], rect[1], x, y);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 25 |
|
avm99963 | 9f5952a | 2018-12-31 01:36:38 +0100 | [diff] [blame] | 26 | for (var i = 1; i < 4; i++) {
|
| 27 | var temp = crossProd(rect[i], rect[(i+1)%4], x, y);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 28 | if (c*temp < 0) ans = false;
|
| 29 | }
|
| 30 | return ans;
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 31 | }
|
| 32 |
|
| 33 | function crossProd(r1, r2, x, y) {
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 34 | return r1[0]*r2[1] + r2[0]*y + x*r1[1] - r1[0]*y - r2[0]*r1[1] - x*r2[1];
|
| 35 | }
|