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