Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 1 | // *********** HERE STARTS dialog.js *************
|
| 2 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 3 | var dialog = {
|
| 4 | fill: function(data, text, html=false) {
|
| 5 | var el = document.querySelectorAll("*[data-fill=\""+data+"\"]");
|
| 6 | for (var i in el) {
|
| 7 | if (html === true) {
|
| 8 | el[i].innerHTML = text;
|
| 9 | } else {
|
| 10 | el[i].innerText = text;
|
| 11 | }
|
| 12 | }
|
| 13 | },
|
| 14 | show: function(id, neighbors) {
|
| 15 | var neighbors = Object.values(neighbors);
|
| 16 |
|
| 17 | this.fill("name", graf.nodes[id].name);
|
| 18 | this.fill("year", graf.nodes[id].year);
|
| 19 | this.fill("sex", graf.nodes[id].sex);
|
| 20 | this.fill("id", "#"+id);
|
| 21 | this.fill("n-edges", neighbors.length);
|
| 22 |
|
| 23 | var list = "";
|
| 24 | neighbors.forEach(function (a) {
|
| 25 | list += "<li><b>"+graf.nodes[id].name+" - "+a.label+":</b> "+(graf.edges[id+"_"+a.id] ? graf.edges[id+"_"+a.id].votes : graf.edges[a.id+"_"+id].votes)+" vots</li>";
|
| 26 | });
|
| 27 | this.fill("edges", list, true);
|
| 28 |
|
| 29 | if (window.innerWidth > 700) {
|
| 30 | document.querySelector("#dialog").style.display = "block";
|
| 31 | document.querySelector("#backdrop-container").style.display = "block";
|
| 32 | } else {
|
| 33 | document.querySelector("#summary-dialog").style.display = "block";
|
| 34 | }
|
| 35 | },
|
| 36 | close: function() {
|
| 37 | document.querySelector("#dialog").style.display = "none";
|
| 38 | document.querySelector("#summary-dialog").style.display = "none";
|
| 39 | document.querySelector("#backdrop-container").style.display = "none";
|
| 40 |
|
| 41 | s.graph.nodes().forEach(function(n) {
|
| 42 | n.color = n.originalColor;
|
| 43 | });
|
| 44 |
|
| 45 | s.graph.edges().forEach(function(e) {
|
| 46 | e.color = e.originalColor;
|
| 47 | });
|
| 48 |
|
| 49 | if(circleMode) {
|
| 50 | s.graph.nodes().forEach(function (n) {
|
| 51 | n.x = n.circleX;
|
| 52 | n.y = n.circleY;
|
| 53 | n.size = 10;
|
| 54 | });
|
| 55 | }
|
| 56 | else {
|
| 57 | s.graph.nodes().forEach(function (n) {
|
| 58 | n.x = n.originalX;
|
| 59 | n.y = n.originalY;
|
| 60 | n.size = 10;
|
| 61 | });
|
| 62 | }
|
| 63 | s.refresh();
|
| 64 |
|
| 65 | },
|
| 66 | max: function() {
|
| 67 | document.querySelector("#summary-dialog").style.display = "none";
|
| 68 | document.querySelector("#dialog").style.display = "block";
|
| 69 | },
|
| 70 | min: function() {
|
| 71 | document.querySelector("#dialog").style.display = "none";
|
| 72 | document.querySelector("#summary-dialog").style.display = "block";
|
| 73 | }
|
| 74 | };
|
| 75 |
|
| 76 |
|
| 77 | function initDialog() {
|
| 78 | document.querySelector("#quit-dialog").addEventListener("click", dialog.close);
|
| 79 | document.querySelector("#quit2-dialog").addEventListener("click", dialog.close);
|
| 80 | document.querySelector("#max-dialog").addEventListener("click", dialog.max);
|
| 81 | document.querySelector("#min-dialog").addEventListener("click", dialog.min);
|
| 82 | }
|