diff --git a/src/js/familyTreeJS.js b/src/js/familyTreeJS.js index 4819a4019cad81bb1a854391173009beb8d321c6..491dfcd9d01c0e7699e1e4cb50dbfaaf260b21bf 100644 --- a/src/js/familyTreeJS.js +++ b/src/js/familyTreeJS.js @@ -37,14 +37,14 @@ window.renderFamilyTree = function(slaves, filterID) { function initFtreeSVG(data) { ftreeWidth = data.nodes.length * 45; ftreeHeight = data.nodes.length * 35; - if(ftreeWidth < 600) { + if (ftreeWidth < 600) { ftreeWidth = 600; - } else if(ftreeWidth > 1920) { + } else if (ftreeWidth > 1920) { ftreeWidth = 1920; } - if(ftreeHeight < 480) { + if (ftreeHeight < 480) { ftreeHeight = 480; - } else if(ftreeHeight > 1200) { + } else if (ftreeHeight > 1200) { ftreeHeight = 1200; } @@ -95,9 +95,9 @@ window.renderFamilyTree = function(slaves, filterID) { .append('line') .attr('marker-end', 'url(#arrowhead)') .attr('stroke', function(d) { - if(d.type === 'homologous') { + if (d.type === 'homologous') { return '#862d59'; - } else if(d.type === 'paternal') { + } else if (d.type === 'paternal') { return '#24478f'; } else { return '#aa909b'; @@ -118,7 +118,7 @@ window.renderFamilyTree = function(slaves, filterID) { node.append('circle') .attr('r', function (d) { return d.r; }) .attr('stroke', function(d) { - if(d.ID === filterID) { + if (d.ID === filterID) { return '#ffff20'; } else { return '#5a5a5a'; @@ -130,8 +130,8 @@ window.renderFamilyTree = function(slaves, filterID) { node.append('text') .text(function(d) { var ssym; - if(d.ID === -1) { - if(d.dick === 1 && d.vagina === 1) { + if (d.ID === -1) { + if (d.dick === 1 && d.vagina === 1) { ssym = '☿'; } else if (d.dick === 1) { ssym = '♂'; @@ -153,13 +153,13 @@ window.renderFamilyTree = function(slaves, filterID) { .attr('dx', function(d) { return -(8*d.name.length)/2; }) .attr('class', 'node-text') .style('fill', function(d) { - if(d.is_mother && d.is_father) { + if (d.is_mother && d.is_father) { return '#b84dff'; - } else if(d.is_father) { + } else if (d.is_father) { return '#00ffff'; - } else if(d.is_mother) { + } else if (d.is_mother) { return '#ff3399'; - } else if(d.unborn) { + } else if (d.unborn) { return '#a3a3c2'; } else { return '#66cc66'; @@ -202,7 +202,6 @@ window.renderFamilyTree = function(slaves, filterID) { d.fx = null; d.fy = null; } - } }; @@ -237,78 +236,78 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { charList.push.apply(charList, State.variables.tanks); var unborn = {}; - for(let i = 0; i < State.variables.tanks.length; i++) { + for (let i = 0; i < State.variables.tanks.length; i++) { unborn[State.variables.tanks[i].ID] = true; } for (let i = 0; i < State.variables.cribs.length; i++) { unborn[State.variables.cribs[i].ID] = true; } - for(let i = 0; i < charList.length; i++) { + for (let i = 0; i < charList.length; i++) { var mom = charList[i].mother; var dad = charList[i].father; - if(mom) { - if(!kids[mom]) { + if (mom) { + if (!kids[mom]) { kids[mom] = {}; } kids[mom].mother = true; } - if(dad) { - if(!kids[dad]) { + if (dad) { + if (!kids[dad]) { kids[dad] = {}; } kids[dad].father = true; } } - for(let i = 0; i < charList.length; i++) { + for (let i = 0; i < charList.length; i++) { var character = charList[i]; - if(character.mother === 0 && character.father === 0 && !kids[character.ID]) { + if (character.mother === 0 && character.father === 0 && !kids[character.ID]) { continue; } let mom = character.mother; - if(mom < -6) { + if (mom < -6) { if (mom in State.variables.missingTable && State.variables.showMissingSlaves) { node_lookup[mom] = family_graph.nodes.length; var missing = State.variables.missingTable[mom]; charList.push({ID: mom, mother: 0, father: 0, is_mother: true, dick: missing.dick, vagina: missing.vagina, slaveName: missing.slaveName}); } else { - if(typeof outmoms[mom] === 'undefined') { + if (typeof outmoms[mom] === 'undefined') { outmoms[mom] = []; } outmoms[mom].push(character.slaveName); } - } else if(mom < 0 && typeof node_lookup[mom] === 'undefined' && typeof preset_lookup[mom] !== 'undefined') { + } else if (mom < 0 && typeof node_lookup[mom] === 'undefined' && typeof preset_lookup[mom] !== 'undefined') { node_lookup[mom] = family_graph.nodes.length; charList.push({ID: mom, mother: 0, father: 0, is_father: true, dick: 0, vagina: 1, slaveName: preset_lookup[mom]}); } let dad = character.father; - if(dad < -6) { + if (dad < -6) { if (dad in State.variables.missingTable && State.variables.showMissingSlaves) { node_lookup[dad] = family_graph.nodes.length; let missing = State.variables.missingTable[dad]; charList.push({ID: dad, mother: 0, father: 0, is_father: true, dick: missing.dick, vagina: missing.vagina, slaveName: missing.slaveName}); } else { - if(typeof outdads[dad] === 'undefined') { + if (typeof outdads[dad] === 'undefined') { outdads[dad] = []; } outdads[dad].push(character.slaveName); } - } else if(dad < 0 && typeof node_lookup[dad] === 'undefined' && typeof preset_lookup[dad] !== 'undefined') { + } else if (dad < 0 && typeof node_lookup[dad] === 'undefined' && typeof preset_lookup[dad] !== 'undefined') { node_lookup[dad] = family_graph.nodes.length; charList.push({ID: dad, mother: 0, father: 0, is_father: true, dick: 1, vagina: -1, slaveName: preset_lookup[dad]}); } } var mkeys = Object.keys(outmoms); - for(let i = 0; i < mkeys.length; i++) { + for (let i = 0; i < mkeys.length; i++) { var name; var key = mkeys[i]; var names = outmoms[key]; - if(names.length === 1) { + if (names.length === 1) { name = names[0]; - } else if(names.length === 2) { + } else if (names.length === 2) { name = names.join(' and '); } else { names[-1] = `and ${names[-1]}`; @@ -320,13 +319,13 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { } var dkeys = Object.keys(outdads); - for(let i = 0; i < dkeys.length; i++) { + for (let i = 0; i < dkeys.length; i++) { let name; let key = dkeys[i]; let names = outdads[key]; - if(names.length === 1) { + if (names.length === 1) { name = names[0]; - } else if(names.length === 2) { + } else if (names.length === 2) { name = names.join(' and '); } else { names[-1] = `and ${names[-1]}`; @@ -338,7 +337,7 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { } var charHash = {}; - for(let i = 0; i < charList.length; i++) { + for (let i = 0; i < charList.length; i++) { charHash[charList[i].ID] = charList[i]; } @@ -347,43 +346,43 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { var saveTree = {}; function relatedTo(character, targetID, relIDs = {tree: {}, related: false}) { relIDs.tree[character.ID] = true; - if(related[character.ID]) { + if (related[character.ID]) { relIDs.related = true; return relIDs; } - if(character.ID === targetID) { + if (character.ID === targetID) { relIDs.related = true; } - if(seen[character.ID]) { + if (seen[character.ID]) { return relIDs; } seen[character.ID] = true; - if(character.mother !== 0) { - if(charHash[character.mother]) { + if (character.mother !== 0) { + if (charHash[character.mother]) { relatedTo(charHash[character.mother], targetID, relIDs); } } - if(character.father !== 0) { - if(charHash[character.father]) { + if (character.father !== 0) { + if (charHash[character.father]) { relatedTo(charHash[character.father], targetID, relIDs); } } return relIDs; } - if(filterID) { - if(charHash[filterID]) { + if (filterID) { + if (charHash[filterID]) { var relIDs = relatedTo(charHash[filterID], filterID); - for(let k in relIDs.tree) { + for (let k in relIDs.tree) { related[k] = true; } - for(let i = 0; i < charList.length; i++) { - if(charHash[charList[i].ID]) { + for (let i = 0; i < charList.length; i++) { + if (charHash[charList[i].ID]) { var pRelIDs = relatedTo(charHash[charList[i].ID], filterID); - if(pRelIDs.related) { - for(let k in pRelIDs.tree) { + if (pRelIDs.related) { + for (let k in pRelIDs.tree) { related[k] = true; - if(saveTree[k]) { - for(let k2 in saveTree[k].tree) { + if (saveTree[k]) { + for (let k2 in saveTree[k].tree) { related[k2] = true; } } @@ -395,13 +394,13 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { } } - for(let i = 0; i < charList.length; i++) { + for (let i = 0; i < charList.length; i++) { let character = charList[i]; let char_id = character.ID; - if(character.mother === 0 && character.father === 0 && !kids[char_id]) { + if (character.mother === 0 && character.father === 0 && !kids[char_id]) { continue; } - if(filterID && !related[char_id]) { + if (filterID && !related[char_id]) { continue; } node_lookup[char_id] = family_graph.nodes.length; @@ -412,7 +411,7 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { unborn: !!unborn[char_id], vagina: character.vagina }; - if(kids[char_id]) { + if (kids[char_id]) { char_obj.is_mother = !!kids[char_id].mother; char_obj.is_father = !!kids[char_id].father; } else { @@ -422,24 +421,24 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { family_graph.nodes.push(char_obj); } - for(let i = 0; i < charList.length; i++) { + for (let i = 0; i < charList.length; i++) { let character = charList[i]; let char_id = character.ID; - if(character.mother === 0 && character.father === 0 && !kids[char_id]) { + if (character.mother === 0 && character.father === 0 && !kids[char_id]) { continue; } - if(filterID && !related[char_id]) { - if(related[character.mother]) { + if (filterID && !related[char_id]) { + if (related[character.mother]) { console.log('wtf, mom'); } - if(related[character.father]) { + if (related[character.father]) { console.log('wtf, dad'); } continue; } - if(typeof node_lookup[character.mother] !== 'undefined') { + if (typeof node_lookup[character.mother] !== 'undefined') { var ltype; - if(character.mother === character.father) { + if (character.mother === character.father) { ltype = 'homologous'; } else { ltype = 'maternal'; @@ -450,10 +449,10 @@ window.buildFamilyTree = function(slaves = State.variables.slaves, filterID) { source: node_lookup[character.mother]*1 }); } - if(character.mother === character.father) { + if (character.mother === character.father) { continue; } - if(typeof node_lookup[character.father] !== 'undefined') { + if (typeof node_lookup[character.father] !== 'undefined') { family_graph.links.push({ type: 'paternal', target: node_lookup[char_id]*1, @@ -487,7 +486,7 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS var numTreeNodes = 0; var graphElement = document.getElementById("graph"); - if(!graphElement) + if (!graphElement) return; graphElement.innerHTML = ""; @@ -497,17 +496,17 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS */ function getSlave(id, expectedGenes) { - if(id === -1) { + if (id === -1) { return {"slaveName": "YOU", "ID": id, "physicalAge": PC.physicalAge, "genes": PC.genes, "father": PC.father, "mother": PC.mother}; } - if(id === 0) { + if (id === 0) { return {"slaveName": "-", "ID": id, "genes": expectedGenes}; } - if(id === activeSlave.ID) { + if (id === activeSlave.ID) { return activeSlave; } - for(let i = 0; i < slaves.length; ++i) { - if(slaves[i].ID === id) + for (let i = 0; i < slaves.length; ++i) { + if (slaves[i].ID === id) return slaves[i]; } return {"slaveName": "-", "ID": id, "genes": expectedGenes}; @@ -516,23 +515,23 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS function slaveInfo(slave, activeSlaveId, recursionProtectSlaveId = {}) { numTreeNodes = 0; treeDepth = 0; - if(recursionProtectSlaveId[slave.ID]) { + if (recursionProtectSlaveId[slave.ID]) { console.log("Recursion protection"); return slaveInfo_(slave, activeSlaveId); } recursionProtectSlaveId[slave.ID] = true; - if(typeof slave.father === "undefined" || typeof slave.mother === "undefined") + if (typeof slave.father === "undefined" || typeof slave.mother === "undefined") return slaveInfo_(slave, activeSlaveId); - if(slave.father === -1 || slave.mother === -1) { + if (slave.father === -1 || slave.mother === -1) { return slaveInfo(getSlave(-1), activeSlaveId, recursionProtectSlaveId); } - if(slave.father !== 0) { + if (slave.father !== 0) { return slaveInfo(getSlave(slave.father, "unknownXY"), activeSlaveId, recursionProtectSlaveId); } - if(slave.mother !== 0) { + if (slave.mother !== 0) { return slaveInfo(getSlave(slave.mother, "unknownXX"), activeSlaveId, recursionProtectSlaveId); } return slaveInfo_(slave, activeSlaveId); @@ -541,7 +540,7 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS numTreeNodes += 1; treeDepth = Math.max(treeDepth, depth); var shouldAddChildren = false; - if(!slavesAdded[slave.ID]) { + if (!slavesAdded[slave.ID]) { shouldAddChildren = true; slavesAdded[slave.ID] = true; } @@ -555,33 +554,33 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS var spouseToChild = {}; function maybeAddSpouseToChild(child) { - if(child.ID === slave.ID) + if (child.ID === slave.ID) return; if (child.father === slave.ID) { - if(!spouseToChild[child.mother]) { + if (!spouseToChild[child.mother]) { spouseToChild[child.mother] = []; } spouseToChild[child.mother].push(child); } else if (child.mother === slave.ID) { - if(!spouseToChild[child.father]) { + if (!spouseToChild[child.father]) { spouseToChild[child.father] = []; } spouseToChild[child.father].push(child); } } - if(activeSlave.ID !== PC.ID) + if (activeSlave.ID !== PC.ID) maybeAddSpouseToChild(activeSlave); maybeAddSpouseToChild(getSlave(-1)); - for(let i = 0; i < slaves.length; ++i) { + for (let i = 0; i < slaves.length; ++i) { var child = slaves[i]; - if(child.ID !== activeSlave.ID) + if (child.ID !== activeSlave.ID) maybeAddSpouseToChild(child); } - for(let key in spouseToChild) { - if(spouseToChild.hasOwnProperty(key)) { + for (let key in spouseToChild) { + if (spouseToChild.hasOwnProperty(key)) { var children = shouldAddChildren?spouseToChild[key]:[]; var spouse = getSlave(key, (slaves.genes === "XX")?"unknownXY":(slaves.genes === "XY")?"unknownXX":"unknown"); var spouseName; @@ -608,7 +607,7 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS var parentWidth = document.getElementById('editFamily').offsetWidth; console.log(parentWidth, document.getElementById('passages').offsetWidth); - if(!parentWidth) + if (!parentWidth) parentWidth = document.body.offsetWidth - 483; console.log(parentWidth, Math.min(200 + 40*numTreeNodes, parentWidth-200) + 200); @@ -624,5 +623,4 @@ window.updateFamilyTree = function(activeSlave = lastActiveSlave, slaves = lastS } } }); - };