blob: eeab183d8a9fa4d2640d78549ee20bc3085248e3 [file] [log] [blame]
Javier López-Contreras052503f2018-12-26 12:34:42 +01001var limitYears = false;
2var showYears = new Set();
3
4function repaint() {
5 //targetYear: graf.nodes[e.source].year,
6 if(limitYears) {
7 var added = new Set();
avm99963027b5b02018-12-28 02:31:46 +01008
Javier López-Contreras052503f2018-12-26 12:34:42 +01009 s.graph.nodes().forEach(function(n) {
10 var numNeig = s.graph.numNeighborsFromYears(n.id, showYears);
avm99963027b5b02018-12-28 02:31:46 +010011
Javier López-Contreras052503f2018-12-26 12:34:42 +010012 if ((n.year == 0 && (n.sex == 'F' || n.sex == 'M') )
13 || numNeig == 0
14 || (!showYears.has("" + n.year) && (n.year != 0) )) {
15 n.hidden = true;
16 }
17 else {
18 n.hidden = false;
19 added.add(n.id);
20 }
21 });
avm99963027b5b02018-12-28 02:31:46 +010022
Javier López-Contreras052503f2018-12-26 12:34:42 +010023 s.graph.edges().forEach(function(e) {
24 if(!added.has(e.source) && !added.has(e.target)){
25 e.hidden = true;
26 }
27 else e.hidden = false;
avm99963027b5b02018-12-28 02:31:46 +010028 });
Javier López-Contreras052503f2018-12-26 12:34:42 +010029 }
30 else {
31 s.graph.nodes().forEach(function(n) {
32 n.hidden = false;
33 });
avm99963027b5b02018-12-28 02:31:46 +010034
Javier López-Contreras052503f2018-12-26 12:34:42 +010035 s.graph.edges().forEach(function(e) {
36 e.hidden = false;
37 });
38 }
39}
40
41function altYearList() {
42 var yearlist = document.querySelector("#year-list");
avm99963027b5b02018-12-28 02:31:46 +010043
Javier López-Contreras052503f2018-12-26 12:34:42 +010044 if(yearlist.style.display == "none"){
45 yearlist.style.display = "block";
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010046 document.querySelector("#settings i").innerText = "close";
Javier López-Contreras052503f2018-12-26 12:34:42 +010047 yearLimits = true;
48 }
49 else{
50 yearlist.style.display = "none";
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010051 document.querySelector("#settings i").innerText = "settings";
Javier López-Contreras052503f2018-12-26 12:34:42 +010052 yearLimits = true;
53 }
54}
55
Andreu Huguet54f90742018-12-28 13:54:59 +010056function first_day(year) {
57 start_course = new Date(year + '-09-12');
58 return start_course;
59}
60
avm99963027b5b02018-12-28 02:31:46 +010061function addYearList() {
Javier López-Contreras052503f2018-12-26 12:34:42 +010062 var ylistspan = document.querySelector("#year-list-span")
Andreu Huguet54f90742018-12-28 13:54:59 +010063 var year = 2007;
64 var today = new Date();
65 while (first_day(year) < today) {
avm99963027b5b02018-12-28 02:31:46 +010066 var lab = document.createElement("label");
67 lab.setAttribute("class", "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect custom-checkbox");
68 lab.setAttribute("for", "checkbox-"+year);
Javier López-Contreras052503f2018-12-26 12:34:42 +010069 var yin = document.createElement("input");
70 yin.type = "checkbox";
avm99963027b5b02018-12-28 02:31:46 +010071 yin.setAttribute("class", "mdl-checkbox__input");
72 yin.name = year;
73 yin.id = "checkbox-"+year;
74 yin.addEventListener("change", function() {
Javier López-Contreras052503f2018-12-26 12:34:42 +010075 limitYears = true;
avm99963027b5b02018-12-28 02:31:46 +010076
Javier López-Contreras052503f2018-12-26 12:34:42 +010077 if(this.checked) {
78 showYears.add(this.name);
avm99963027b5b02018-12-28 02:31:46 +010079 } else {
Javier López-Contreras052503f2018-12-26 12:34:42 +010080 showYears.delete(this.name);
81 }
avm99963027b5b02018-12-28 02:31:46 +010082
83 if (showYears.size == 0) limitYears = false;
84
Javier López-Contreras052503f2018-12-26 12:34:42 +010085 repaint();
avm99963027b5b02018-12-28 02:31:46 +010086
Javier López-Contreras052503f2018-12-26 12:34:42 +010087 s.refresh();
88 });
avm99963027b5b02018-12-28 02:31:46 +010089
90 var span = document.createElement("span");
91 span.innerText = year;
92 span.setAttribute("class", "mdl-checkbox__label");
93
94 lab.appendChild(yin);
95 lab.appendChild(span);
Javier López-Contreras052503f2018-12-26 12:34:42 +010096 ylistspan.appendChild(lab);
avm99963027b5b02018-12-28 02:31:46 +010097 ylistspan.insertAdjacentHTML("beforeend", "<br>");
Andreu Huguet54f90742018-12-28 13:54:59 +010098 ++year;
Javier López-Contreras052503f2018-12-26 12:34:42 +010099 }
avm99963027b5b02018-12-28 02:31:46 +0100100
Javier López-Contreras052503f2018-12-26 12:34:42 +0100101 document.querySelector("#settings").addEventListener("click", altYearList);
102}