blob: cbbef95535a015ffdb105e2858afdea75fceddde [file] [log] [blame]
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +01001// *********** HERE STARTS limit-years.js *************
2
Javier López-Contreras052503f2018-12-26 12:34:42 +01003window.addEventListener("load", addYearList);
4
5var limitYears = false;
6var showYears = new Set();
7
8function repaint() {
9 //targetYear: graf.nodes[e.source].year,
10 if(limitYears) {
11 var added = new Set();
12
13 s.graph.nodes().forEach(function(n) {
14 var numNeig = s.graph.numNeighborsFromYears(n.id, showYears);
15
16 if ((n.year == 0 && (n.sex == 'F' || n.sex == 'M') )
17 || numNeig == 0
18 || (!showYears.has("" + n.year) && (n.year != 0) )) {
19 n.hidden = true;
20 }
21 else {
22 n.hidden = false;
23 added.add(n.id);
24 }
25 });
26
27 s.graph.edges().forEach(function(e) {
28 if(!added.has(e.source) && !added.has(e.target)){
29 e.hidden = true;
30 }
31 else e.hidden = false;
32 });
33 }
34 else {
35 s.graph.nodes().forEach(function(n) {
36 n.hidden = false;
37 });
38
39 s.graph.edges().forEach(function(e) {
40 e.hidden = false;
41 });
42 }
43}
44
45function altYearList() {
46 var yearlist = document.querySelector("#year-list");
47
48 if(yearlist.style.display == "none"){
49 yearlist.style.display = "block";
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010050 document.querySelector("#settings i").innerText = "close";
Javier López-Contreras052503f2018-12-26 12:34:42 +010051 yearLimits = true;
52 }
53 else{
54 yearlist.style.display = "none";
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010055 document.querySelector("#settings i").innerText = "settings";
Javier López-Contreras052503f2018-12-26 12:34:42 +010056 yearLimits = true;
57 }
58}
59
60function addYearList() {
61 var ylistspan = document.querySelector("#year-list-span")
62 for(var year=2006; year<2019; year++) {
63 var yin = document.createElement("input");
64 yin.type = "checkbox";
65 yin.class = "mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-js-ripple-effect mdl-button--colored";
66 yin.name = "" + year;
67 yin.addEventListener("change", function(){
68 limitYears = true;
69
70 if(this.checked) {
71 showYears.add(this.name);
72 }
73 else {
74 showYears.delete(this.name);
75 }
76
77 if(showYears.size == 0) limitYears = false;
78
79 repaint();
80
81 s.refresh();
82 });
83
84 var lab = document.createElement("label");
85 lab.innerHTML = "" + year + "<br>";
86
87 ylistspan.appendChild(yin);
88 ylistspan.appendChild(lab);
89 }
90
91 document.querySelector("#settings").addEventListener("click", altYearList);
92}
93