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