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