Minor bug fixes and code formatting, and limit-years style modified a little bit
diff --git a/js/limit-years.js b/js/limit-years.js
index cbbef95..41647f7 100644
--- a/js/limit-years.js
+++ b/js/limit-years.js
@@ -1,7 +1,5 @@
// *********** HERE STARTS limit-years.js *************
-window.addEventListener("load", addYearList);
-
var limitYears = false;
var showYears = new Set();
@@ -9,10 +7,10 @@
//targetYear: graf.nodes[e.source].year,
if(limitYears) {
var added = new Set();
-
+
s.graph.nodes().forEach(function(n) {
var numNeig = s.graph.numNeighborsFromYears(n.id, showYears);
-
+
if ((n.year == 0 && (n.sex == 'F' || n.sex == 'M') )
|| numNeig == 0
|| (!showYears.has("" + n.year) && (n.year != 0) )) {
@@ -23,19 +21,19 @@
added.add(n.id);
}
});
-
+
s.graph.edges().forEach(function(e) {
if(!added.has(e.source) && !added.has(e.target)){
e.hidden = true;
}
else e.hidden = false;
- });
+ });
}
else {
s.graph.nodes().forEach(function(n) {
n.hidden = false;
});
-
+
s.graph.edges().forEach(function(e) {
e.hidden = false;
});
@@ -44,7 +42,7 @@
function altYearList() {
var yearlist = document.querySelector("#year-list");
-
+
if(yearlist.style.display == "none"){
yearlist.style.display = "block";
document.querySelector("#settings i").innerText = "close";
@@ -57,37 +55,42 @@
}
}
-function addYearList() {
+function addYearList() {
var ylistspan = document.querySelector("#year-list-span")
- for(var year=2006; year<2019; year++) {
+ for(var year = 2006; year < 2019; year++) {
+ var lab = document.createElement("label");
+ lab.setAttribute("class", "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect custom-checkbox");
+ lab.setAttribute("for", "checkbox-"+year);
var yin = document.createElement("input");
yin.type = "checkbox";
- yin.class = "mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-js-ripple-effect mdl-button--colored";
- yin.name = "" + year;
- yin.addEventListener("change", function(){
+ yin.setAttribute("class", "mdl-checkbox__input");
+ yin.name = year;
+ yin.id = "checkbox-"+year;
+ yin.addEventListener("change", function() {
limitYears = true;
-
+
if(this.checked) {
showYears.add(this.name);
- }
- else {
+ } else {
showYears.delete(this.name);
}
-
- if(showYears.size == 0) limitYears = false;
-
+
+ if (showYears.size == 0) limitYears = false;
+
repaint();
-
+
s.refresh();
});
-
- var lab = document.createElement("label");
- lab.innerHTML = "" + year + "<br>";
-
- ylistspan.appendChild(yin);
+
+ var span = document.createElement("span");
+ span.innerText = year;
+ span.setAttribute("class", "mdl-checkbox__label");
+
+ lab.appendChild(yin);
+ lab.appendChild(span);
ylistspan.appendChild(lab);
+ ylistspan.insertAdjacentHTML("beforeend", "<br>");
}
-
+
document.querySelector("#settings").addEventListener("click", altYearList);
}
-