Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 1 | // *********** HERE STARTS limit-years.js *************
|
| 2 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 3 | var limitYears = false;
|
| 4 | var showYears = new Set();
|
| 5 |
|
| 6 | function repaint() {
|
| 7 | //targetYear: graf.nodes[e.source].year,
|
| 8 | if(limitYears) {
|
| 9 | var added = new Set();
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 10 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 11 | s.graph.nodes().forEach(function(n) {
|
| 12 | var numNeig = s.graph.numNeighborsFromYears(n.id, showYears);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 13 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 14 | 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 | });
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 24 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 25 | 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;
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 30 | });
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 31 | }
|
| 32 | else {
|
| 33 | s.graph.nodes().forEach(function(n) {
|
| 34 | n.hidden = false;
|
| 35 | });
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 36 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 37 | s.graph.edges().forEach(function(e) {
|
| 38 | e.hidden = false;
|
| 39 | });
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | function altYearList() {
|
| 44 | var yearlist = document.querySelector("#year-list");
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 45 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 46 | if(yearlist.style.display == "none"){
|
| 47 | yearlist.style.display = "block";
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 48 | document.querySelector("#settings i").innerText = "close";
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 49 | yearLimits = true;
|
| 50 | }
|
| 51 | else{
|
| 52 | yearlist.style.display = "none";
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 53 | document.querySelector("#settings i").innerText = "settings";
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 54 | yearLimits = true;
|
| 55 | }
|
| 56 | }
|
| 57 |
|
Andreu Huguet | 54f9074 | 2018-12-28 13:54:59 +0100 | [diff] [blame^] | 58 | function first_day(year) {
|
| 59 | start_course = new Date(year + '-09-12');
|
| 60 | return start_course;
|
| 61 | }
|
| 62 |
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 63 | function addYearList() {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 64 | var ylistspan = document.querySelector("#year-list-span")
|
Andreu Huguet | 54f9074 | 2018-12-28 13:54:59 +0100 | [diff] [blame^] | 65 | var year = 2007;
|
| 66 | var today = new Date();
|
| 67 | while (first_day(year) < today) {
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 68 | 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-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 71 | var yin = document.createElement("input");
|
| 72 | yin.type = "checkbox";
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 73 | yin.setAttribute("class", "mdl-checkbox__input");
|
| 74 | yin.name = year;
|
| 75 | yin.id = "checkbox-"+year;
|
| 76 | yin.addEventListener("change", function() {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 77 | limitYears = true;
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 78 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 79 | if(this.checked) {
|
| 80 | showYears.add(this.name);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 81 | } else {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 82 | showYears.delete(this.name);
|
| 83 | }
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 84 |
|
| 85 | if (showYears.size == 0) limitYears = false;
|
| 86 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 87 | repaint();
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 88 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 89 | s.refresh();
|
| 90 | });
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 91 |
|
| 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-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 98 | ylistspan.appendChild(lab);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 99 | ylistspan.insertAdjacentHTML("beforeend", "<br>");
|
Andreu Huguet | 54f9074 | 2018-12-28 13:54:59 +0100 | [diff] [blame^] | 100 | ++year;
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 101 | }
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 102 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 103 | document.querySelector("#settings").addEventListener("click", altYearList);
|
| 104 | }
|