blob: 41647f70a762f00c70bdda4fb1b3d26e40011c78 [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
avm99963027b5b02018-12-28 02:31:46 +010058function addYearList() {
Javier López-Contreras052503f2018-12-26 12:34:42 +010059 var ylistspan = document.querySelector("#year-list-span")
avm99963027b5b02018-12-28 02:31:46 +010060 for(var year = 2006; year < 2019; year++) {
61 var lab = document.createElement("label");
62 lab.setAttribute("class", "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect custom-checkbox");
63 lab.setAttribute("for", "checkbox-"+year);
Javier López-Contreras052503f2018-12-26 12:34:42 +010064 var yin = document.createElement("input");
65 yin.type = "checkbox";
avm99963027b5b02018-12-28 02:31:46 +010066 yin.setAttribute("class", "mdl-checkbox__input");
67 yin.name = year;
68 yin.id = "checkbox-"+year;
69 yin.addEventListener("change", function() {
Javier López-Contreras052503f2018-12-26 12:34:42 +010070 limitYears = true;
avm99963027b5b02018-12-28 02:31:46 +010071
Javier López-Contreras052503f2018-12-26 12:34:42 +010072 if(this.checked) {
73 showYears.add(this.name);
avm99963027b5b02018-12-28 02:31:46 +010074 } else {
Javier López-Contreras052503f2018-12-26 12:34:42 +010075 showYears.delete(this.name);
76 }
avm99963027b5b02018-12-28 02:31:46 +010077
78 if (showYears.size == 0) limitYears = false;
79
Javier López-Contreras052503f2018-12-26 12:34:42 +010080 repaint();
avm99963027b5b02018-12-28 02:31:46 +010081
Javier López-Contreras052503f2018-12-26 12:34:42 +010082 s.refresh();
83 });
avm99963027b5b02018-12-28 02:31:46 +010084
85 var span = document.createElement("span");
86 span.innerText = year;
87 span.setAttribute("class", "mdl-checkbox__label");
88
89 lab.appendChild(yin);
90 lab.appendChild(span);
Javier López-Contreras052503f2018-12-26 12:34:42 +010091 ylistspan.appendChild(lab);
avm99963027b5b02018-12-28 02:31:46 +010092 ylistspan.insertAdjacentHTML("beforeend", "<br>");
Javier López-Contreras052503f2018-12-26 12:34:42 +010093 }
avm99963027b5b02018-12-28 02:31:46 +010094
Javier López-Contreras052503f2018-12-26 12:34:42 +010095 document.querySelector("#settings").addEventListener("click", altYearList);
96}