blob: 76447c0fe21101fa9ba36a037423a19c11e1b314 [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 +01003var limitYears = false;
4var showYears = new Set();
5
6function repaint() {
7 //targetYear: graf.nodes[e.source].year,
8 if(limitYears) {
9 var added = new Set();
avm99963027b5b02018-12-28 02:31:46 +010010
Javier López-Contreras052503f2018-12-26 12:34:42 +010011 s.graph.nodes().forEach(function(n) {
12 var numNeig = s.graph.numNeighborsFromYears(n.id, showYears);
avm99963027b5b02018-12-28 02:31:46 +010013
Javier López-Contreras052503f2018-12-26 12:34:42 +010014 if ((n.year == 0 && (n.sex == 'F' || n.sex == 'M') )
15 || numNeig == 0
16 || (!showYears.has("" + n.year) && (n.year != 0) )) {
17 n.hidden = true;
18 }
19 else {
20 n.hidden = false;
21 added.add(n.id);
22 }
23 });
avm99963027b5b02018-12-28 02:31:46 +010024
Javier López-Contreras052503f2018-12-26 12:34:42 +010025 s.graph.edges().forEach(function(e) {
26 if(!added.has(e.source) && !added.has(e.target)){
27 e.hidden = true;
28 }
29 else e.hidden = false;
avm99963027b5b02018-12-28 02:31:46 +010030 });
Javier López-Contreras052503f2018-12-26 12:34:42 +010031 }
32 else {
33 s.graph.nodes().forEach(function(n) {
34 n.hidden = false;
35 });
avm99963027b5b02018-12-28 02:31:46 +010036
Javier López-Contreras052503f2018-12-26 12:34:42 +010037 s.graph.edges().forEach(function(e) {
38 e.hidden = false;
39 });
40 }
41}
42
43function altYearList() {
44 var yearlist = document.querySelector("#year-list");
avm99963027b5b02018-12-28 02:31:46 +010045
Javier López-Contreras052503f2018-12-26 12:34:42 +010046 if(yearlist.style.display == "none"){
47 yearlist.style.display = "block";
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010048 document.querySelector("#settings i").innerText = "close";
Javier López-Contreras052503f2018-12-26 12:34:42 +010049 yearLimits = true;
50 }
51 else{
52 yearlist.style.display = "none";
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010053 document.querySelector("#settings i").innerText = "settings";
Javier López-Contreras052503f2018-12-26 12:34:42 +010054 yearLimits = true;
55 }
56}
57
Andreu Huguet54f90742018-12-28 13:54:59 +010058function first_day(year) {
59 start_course = new Date(year + '-09-12');
60 return start_course;
61}
62
avm99963027b5b02018-12-28 02:31:46 +010063function addYearList() {
Javier López-Contreras052503f2018-12-26 12:34:42 +010064 var ylistspan = document.querySelector("#year-list-span")
Andreu Huguet54f90742018-12-28 13:54:59 +010065 var year = 2007;
66 var today = new Date();
67 while (first_day(year) < today) {
avm99963027b5b02018-12-28 02:31:46 +010068 var lab = document.createElement("label");
69 lab.setAttribute("class", "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect custom-checkbox");
70 lab.setAttribute("for", "checkbox-"+year);
Javier López-Contreras052503f2018-12-26 12:34:42 +010071 var yin = document.createElement("input");
72 yin.type = "checkbox";
avm99963027b5b02018-12-28 02:31:46 +010073 yin.setAttribute("class", "mdl-checkbox__input");
74 yin.name = year;
75 yin.id = "checkbox-"+year;
76 yin.addEventListener("change", function() {
Javier López-Contreras052503f2018-12-26 12:34:42 +010077 limitYears = true;
avm99963027b5b02018-12-28 02:31:46 +010078
Javier López-Contreras052503f2018-12-26 12:34:42 +010079 if(this.checked) {
80 showYears.add(this.name);
avm99963027b5b02018-12-28 02:31:46 +010081 } else {
Javier López-Contreras052503f2018-12-26 12:34:42 +010082 showYears.delete(this.name);
83 }
avm99963027b5b02018-12-28 02:31:46 +010084
85 if (showYears.size == 0) limitYears = false;
86
Javier López-Contreras052503f2018-12-26 12:34:42 +010087 repaint();
avm99963027b5b02018-12-28 02:31:46 +010088
Javier López-Contreras052503f2018-12-26 12:34:42 +010089 s.refresh();
90 });
avm99963027b5b02018-12-28 02:31:46 +010091
92 var span = document.createElement("span");
93 span.innerText = year;
94 span.setAttribute("class", "mdl-checkbox__label");
95
96 lab.appendChild(yin);
97 lab.appendChild(span);
Javier López-Contreras052503f2018-12-26 12:34:42 +010098 ylistspan.appendChild(lab);
avm99963027b5b02018-12-28 02:31:46 +010099 ylistspan.insertAdjacentHTML("beforeend", "<br>");
Andreu Huguet54f90742018-12-28 13:54:59 +0100100 ++year;
Javier López-Contreras052503f2018-12-26 12:34:42 +0100101 }
avm99963027b5b02018-12-28 02:31:46 +0100102
Javier López-Contreras052503f2018-12-26 12:34:42 +0100103 document.querySelector("#settings").addEventListener("click", altYearList);
104}