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