main.js
// Only call this once (for effiencency & correctness)
Only call this once (for effiencency & correctness)
Only call this once ( for effiencency & correctness )
function createNodes() {
  if (createNodesCalled) return;
  createNodesCalled = true;
  var oldLength = brothers.length;
  var newIdx = oldLength;
  var familyToNode = {};
  for (var i = 0; i < oldLength; i++) {
    var bro = brothers[i];
    bro.id = i;
    var lowerCaseFamily = (bro.familystarted || '').toLowerCase();
    if (lowerCaseFamily && !familyColor[lowerCaseFamily]) {
      familyColor[lowerCaseFamily] = getNewFamilyColor();
      var newNode = {
        id: newIdx++, 
        name: lowerCaseFamily,
        label: bro.familystarted,
        family: lowerCaseFamily,
        inactive: true, 
        font: { size: 50 }, 
      };
      familyToNode[lowerCaseFamily] = newNode;
      nodes.push(newNode);
    }
    if (bro.big && lowerCaseFamily) {
      edges.push({ from: bro.big, to: newIdx });
      nodes.push(Object.assign({}, bro, {
        id: newIdx++, 
        name: '', 
        label: '[' + bro.name + ']',
        family: bro.familystarted.toLowerCase(),
      }));
      edges.push({ from: familyToNode[lowerCaseFamily].id, to: bro.id });
    } else if (!bro.big && !lowerCaseFamily) {
      bro.big = UNKNOWN_BIG_BRO.toLowerCase();
      if (!unknownNode) {
        familyColor[UNKNOWN_BIG_BRO.toLowerCase()] = getNewFamilyColor();
        unknownNode = {
          id: newIdx++, 
          name: UNKNOWN_BIG_BRO.toLowerCase(),
          label: UNKNOWN_BIG_BRO,
          family: UNKNOWN_BIG_BRO.toLowerCase(),
          inactive: true,
          font: { size: 50 }, 
        };
        familyToNode[UNKNOWN_BIG_BRO.toLowerCase()] = unknownNode;
        nodes.push(unknownNode);
      }
      edges.push({ from: unknownNode.id, to: bro.id });
    } else if (lowerCaseFamily) {
      edges.push({ from: familyToNode[lowerCaseFamily].id, to: bro.id });
    } else {
      edges.push({ from: bro.big, to: bro.id });
    }
    bro.big = bro.big || lowerCaseFamily;
    var lowerCaseClass = (bro.pledgeclass || '').toLowerCase();
    if (lowerCaseClass && !pledgeClassColor[lowerCaseClass]) {
      pledgeClassColor[lowerCaseClass] = getNewPledgeClassColor();
    }
    bro.label = bro.name; 
    nodes.push(bro); 
  }
  var nameToNode = {};
  nodes.forEach(function (member) {
    if (member.big) {
      if (nameToNode[member.big]) {
        member.big = nameToNode[member.big];
      } else {
        nodes.forEach(function (member2) {
          if (member.big === member2.name) {
            nameToNode[member.big] = member2;
            member.big = member2;
          }
        });
      }
    }
  });
  edges.forEach(function (edge) {
    if (typeof edge.from === 'string') {
      var name = edge.from;
      var node = nameToNode[name];
      if (!node) {
        var correctedName = didYouMeanWrapper(name);
        var msg = 'Unable to find ' + name + ', did you mean ' + correctedName
          + '?';
        throw new Error(msg);
      }
      edge.from = node.id;
    }
  });
  function getFamily(node) {
    node.family = node.family || node.familystarted;
    if (node.family) return node.family;
    try {
      node.family = getFamily(node.big);
    } catch (e) {
      node.family = 'unknown';
    }
    return node.family;
  }
  nodes.forEach(function (node) {
    getFamily(node);
    if (!node.inactive && !node.graduated) {
      familyToNode[node.family.toLowerCase()].inactive = false;
    }
  });
  nodesDataSet = new vis.DataSet(nodes);
  edgesDataSet = new vis.DataSet(edges);
}
function createNodes ( ) { if ( createNodesCalled ) return ; createNodesCalled = true ; var oldLength = brothers . length ; var newIdx = oldLength ; var familyToNode = { } ; for ( var i = 0 ; i < oldLength ; i ++ ) { var bro = brothers [ i ] ; bro . id = i ; var lowerCaseFamily = ( bro . familystarted || '' ) . toLowerCase ( ) ; if ( lowerCaseFamily && ! familyColor [ lowerCaseFamily ] ) { familyColor [ lowerCaseFamily ] = getNewFamilyColor ( ) ; var newNode = { id : newIdx ++ , name : lowerCaseFamily , label : bro . familystarted , family : lowerCaseFamily , inactive : true , font : { size : 50 } , } ; familyToNode [ lowerCaseFamily ] = newNode ; nodes . push ( newNode ) ; } if ( bro . big && lowerCaseFamily ) { edges . push ( { from : bro . big , to : newIdx } ) ; nodes . push ( Object . assign ( { } , bro , { id : newIdx ++ , name : '' , label : '[' + bro . name + ']' , family : bro . familystarted . toLowerCase ( ) , } ) ) ; edges . push ( { from : familyToNode [ lowerCaseFamily ] . id , to : bro . id } ) ; } else if ( ! bro . big && ! lowerCaseFamily ) { bro . big = UNKNOWN_BIG_BRO . toLowerCase ( ) ; if ( ! unknownNode ) { familyColor [ UNKNOWN_BIG_BRO . toLowerCase ( ) ] = getNewFamilyColor ( ) ; unknownNode = { id : newIdx ++ , name : UNKNOWN_BIG_BRO . toLowerCase ( ) , label : UNKNOWN_BIG_BRO , family : UNKNOWN_BIG_BRO . toLowerCase ( ) , inactive : true , font : { size : 50 } , } ; familyToNode [ UNKNOWN_BIG_BRO . toLowerCase ( ) ] = unknownNode ; nodes . push ( unknownNode ) ; } edges . push ( { from : unknownNode . id , to : bro . id } ) ; } else if ( lowerCaseFamily ) { edges . push ( { from : familyToNode [ lowerCaseFamily ] . id , to : bro . id } ) ; } else { edges . push ( { from : bro . big , to : bro . id } ) ; } bro . big = bro . big || lowerCaseFamily ; var lowerCaseClass = ( bro . pledgeclass || '' ) . toLowerCase ( ) ; if ( lowerCaseClass && ! pledgeClassColor [ lowerCaseClass ] ) { pledgeClassColor [ lowerCaseClass ] = getNewPledgeClassColor ( ) ; } bro . label = bro . name ; nodes . push ( bro ) ; } var nameToNode = { } ; nodes . forEach ( function ( member ) { if ( member . big ) { if ( nameToNode [ member . big ] ) { member . big = nameToNode [ member . big ] ; } else { nodes . forEach ( function ( member2 ) { if ( member . big === member2 . name ) { nameToNode [ member . big ] = member2 ; member . big = member2 ; } } ) ; } } } ) ; edges . forEach ( function ( edge ) { if ( typeof edge . from === 'string' ) { var name = edge . from ; var node = nameToNode [ name ] ; if ( ! node ) { var correctedName = didYouMeanWrapper ( name ) ; var msg = 'Unable to find ' + name + ', did you mean ' + correctedName + '?' ; throw new Error ( msg ) ; } edge . from = node . id ; } } ) ; function getFamily ( node ) { node . family = node . family || node . familystarted ; if ( node . family ) return node . family ; try { node . family = getFamily ( node . big ) ; } catch ( e ) { node . family = 'unknown' ; } return node . family ; } nodes . forEach ( function ( node ) { getFamily ( node ) ; if ( ! node . inactive && ! node . graduated ) { familyToNode [ node . family . toLowerCase ( ) ] . inactive = false ; } } ) ; nodesDataSet = new vis . DataSet ( nodes ) ; edgesDataSet = new vis . DataSet ( edges ) ; }
Only call this once (for effiencency & correctness)
Only call this once ( for effiencency & correctness )
// Add a new family // Create a root for that family // increment // a family does not count as an active undergraduate // super-size the font // This person has a big bro, but they also started a new family of their // own, so let's put them in both spots // Create a placeholder node under his big bro // increment // some non-existing name // Create the real node under his family // This is a data entry error: everyone should have a big bro, or should // have started a family. For now, just add some default value for both. // And add a placeholder family node // increment // super-size the font // This person founded a family, and has no big bro, so put his node // directly underneath the family node // This person is just a regular brother // Add a new Pledge Class // Display the name in the graph // Add this to the list of nodes to display // Change .big from a string to a link to the big brother node // Fix the edges (that point from strings instead of node IDs) // re-process the brothers // Color all the nodes (according to this color scheme) // Get the family information // Mark the family as active (if it has 1 or more active members)