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 |
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 58 | function addYearList() {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 59 | var ylistspan = document.querySelector("#year-list-span")
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 60 | 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-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 64 | var yin = document.createElement("input");
|
| 65 | yin.type = "checkbox";
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 66 | yin.setAttribute("class", "mdl-checkbox__input");
|
| 67 | yin.name = year;
|
| 68 | yin.id = "checkbox-"+year;
|
| 69 | yin.addEventListener("change", function() {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 70 | limitYears = true;
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 71 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 72 | if(this.checked) {
|
| 73 | showYears.add(this.name);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 74 | } else {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 75 | showYears.delete(this.name);
|
| 76 | }
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 77 |
|
| 78 | if (showYears.size == 0) limitYears = false;
|
| 79 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 80 | repaint();
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 81 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 82 | s.refresh();
|
| 83 | });
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 84 |
|
| 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-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 91 | ylistspan.appendChild(lab);
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 92 | ylistspan.insertAdjacentHTML("beforeend", "<br>");
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 93 | }
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 94 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 95 | document.querySelector("#settings").addEventListener("click", altYearList);
|
| 96 | }
|