{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH1/scratch/3d-graph/graph-structurer.js"],"names":["generateUUID","GraphStructurer","constructor","individuals","graph","nodes","links","getGraph","_buildGraphStructure","_buildNodes","_buildLinks","forEach","individual","_enrichWithNodeInformation","push","_buildNodesForThemes","themes","_getThemes","theme","themeNode","id","name","value","_buildLinksForIndividual","Set","map","individualThemes","L3","otherIndividual","otherIndividualThemes","themeIntersection","_getThemeIntersection","length","_addLinkToGraph","_addLinkToThemeNode","link","source","target","themesA","themesB","filter","includes"],"mappings":";;;;;;AAASA,kB,gDAAAA,Y;;;;;;;;;;;;;;;;;;AAEM,YAAMC,eAAN,CAAsB;AACnCC,oBAAYC,WAAZ,EAAyB;AACvB,eAAKA,WAAL,GAAmBA,WAAnB;AACA,eAAKC,KAAL,GAAa;AACXC,mBAAO,EADI;AAEXC,mBAAO;AAFI,WAAb;AAID;;AAEDC,mBAAW;AACT,eAAKC,oBAAL;AACA,iBAAO,KAAKJ,KAAZ;AACD;;AAEDI,+BAAuB;AACrB,eAAKC,WAAL;AACA,eAAKC,WAAL;AACD;;AAEDD,sBAAc;AACZ,eAAKN,WAAL,CAAiBQ,OAAjB,CAA0BC,cAAc;AACtC,iBAAKC,0BAAL,CAAgCD,UAAhC;AACA,iBAAKR,KAAL,CAAWC,KAAX,CAAiBS,IAAjB,CAAsBF,UAAtB;AACD,WAHD;AAIA,eAAKG,oBAAL;AACD;;AAEDA,+BAAuB;AACrB,cAAIC,SAAS,KAAKC,UAAL,EAAb;AACAD,iBAAOL,OAAP,CAAeO,SAAS;AACtB,gBAAIC,YAAY,EAACC,IAAIF,KAAL,EAAYG,MAAMH,KAAlB,EAAyBI,OAAO,CAAhC,EAAhB;AACA,iBAAKlB,KAAL,CAAWC,KAAX,CAAiBS,IAAjB,CAAsBK,SAAtB;AACD,WAHD;AAID;;AAEDT,sBAAc;AACZ,eAAKP,WAAL,CAAiBQ,OAAjB,CAAyBC,cAAc;AACrC,iBAAKW,wBAAL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GAAmB,CAAnB;AACAV,qBAAWS,IAAX,GAAkBT,WAAWQ,EAA7B;AACD;AA1EkC;;yBAAhBnB,e","file":"graph-structurer.js","sourcesContent":["import { generateUUID } from '../../src/internal/individuals-as-points/common/utils.js'\n\nexport default class GraphStructurer {\n  constructor(individuals) {\n    this.individuals = individuals\n    this.graph = {\n      nodes: [],\n      links: []\n    }\n  }\n  \n  getGraph() {\n    this._buildGraphStructure()\n    return this.graph\n  }\n  \n  _buildGraphStructure() {\n    this._buildNodes()\n    this._buildLinks()\n  }\n  \n  _buildNodes() {\n    this.individuals.forEach( individual => {\n      this._enrichWithNodeInformation(individual)\n      this.graph.nodes.push(individual)\n    })\n    this._buildNodesForThemes()\n  }\n  \n  _buildNodesForThemes() {\n    let themes = this._getThemes()\n    themes.forEach(theme => {\n      let themeNode = {id: theme, name: theme, value: 1}\n      this.graph.nodes.push(themeNode)\n    })\n  }\n  \n  _buildLinks() {\n    this.individuals.forEach(individual => {\n      this._buildLinksForIndividual(individual)\n    })\n  }\n  \n  _getThemes() {\n    return [...new Set(this.individuals.map( individual => individual.themes['L3']))]\n  }\n  \n  _buildLinksForIndividual(individual) {\n    let individualThemes = individual.themes.L3\n    this.individuals.forEach( otherIndividual => {\n      let otherIndividualThemes = otherIndividual.themes.L3\n      let themeIntersection = this._getThemeIntersection(individualThemes, otherIndividualThemes)\n      if(themeIntersection.length > 2) {\n        this._addLinkToGraph(individual, otherIndividual)\n      }\n    })\n  }\n  \n  _addLinkToThemeNode(individual, theme) {\n    let link = {source: individual, target: theme}\n    this.graph.links.push(link)\n  }\n  \n  _addLinkToGraph(individual, otherIndividual) {\n    let link = {source: individual.id, target: otherIndividual.id}\n    this.graph.links.push(link)\n  }\n  \n  _getThemeIntersection(themesA, themesB) {\n    return themesA.filter(value => themesB.includes(value))\n  }\n  \n  _enrichWithNodeInformation(individual) {\n    individual.id = generateUUID()\n    individual.value = 1\n    individual.name = individual.id\n  }\n}"]}