{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH1/src/internal/individuals-as-points/venn/force-center-manager.js"],"names":["ForceCenter","ThemeGroup","ForceCenterLayouter","getRandomInteger","generateUUID","FORCE_CENTER_SIZE","FORCE_CENTER_COLOR","ForceCenterManager","constructor","canvas","vennDiagramm","canvasWidth","width","canvasHeight","height","forceCenters","noMatchThemeGroup","themeGroups","forceCenterLayouter","setDataProcessor","dataProcessor","setColorStore","colorStore","getForceCenters","updateLayout","layoutForceCenters","setCanvasExtent","newCanvasWidth","newCanvasHeight","getForceCenterAnnotations","map","forceCenter","getAnnotation","setInitialForceCenter","_createNoMatchThemeGroup","push","getThemeGroups","allThemeGroups","addThemeGroup","uuid","name","themes","color","newThemeGroup","newForceCenterGroupPermutations","_createGroupPermutationsWithNewGroup","_addNewForceCentersForGroups","_sortForceCentersDescendingByGroupCount","_addThemeGroup","updateThemeGroup","forEach","themeGroup","setColor","setThemes","setName","removeThemeGroup","_removeForceCentersContainingGroup","filter","combinedThemeGroups","permutations","reduce","subsets","value","concat","set","permutationsWithNewGroup","permutation","includes","forceCenterGroupPermutations","groupPermutation","sort","forceCenter1","forceCenter2","length","_putNoMatchAtTheEnd","noMatchForceCenter","splice","indexOf","remainingForceCenters","includesGroup","removeInnerContent"],"mappings":";;;;;;AAAOA,iB;;AACAC,gB;;AACAC,yB;;AAEEC,sB,kBAAAA,gB;AAAkBC,kB,kBAAAA,Y;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEpB,YAAMC,oBAAoB,EAA1B;;;;;;;;;;;;;;;;;;AACA,YAAMC,qBAAqB,wBAA3B;;;;;;;;;;;;;;;;;;AAEA,YAAMC,kBAAN,CAAyB;AAC9BC,oBAAYC,MAAZ,EAAoBC,YAApB,EAAkC;AAChC,eAAKA,YAAL,GAAoBA,YAApB;AACA,eAAKD,MAAL,GAAcA,MAAd;AACA,eAAKE,WAAL,GAAmBF,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;AACvC,cAAIuC,wBAAwB,EAA5B;AACA,eAAK/D,YAAL,CAAkBmC,OAAlB,CAA0BnB,eAAe;AACvC,gBAAGA,YAAYgD,aAAZ,CAA0BxC,IAA1B,CAAH,EAAmC;AACjCR,0BAAYiD,kBAAZ;AACD,aAFD,MAEO;AACLF,oCAAsB3C,IAAtB,CAA2BJ,WAA3B;AACD;AACF,WAND;;AAQA,eAAKhB,YAAL,GAAoB+D,qBAApB;AACD;AAlJ6B","file":"force-center-manager.js","sourcesContent":["import ForceCenter from \"./force-center.js\"\nimport ThemeGroup from \"./theme-group.js\"\nimport ForceCenterLayouter from './force-center-layouter.js'\n\nimport { getRandomInteger, generateUUID } from \"../common/utils.js\"\n\nexport const FORCE_CENTER_SIZE = 20\nexport const FORCE_CENTER_COLOR = \"rgba(255, 82, 82, 0.4)\"\n\nexport class ForceCenterManager {\n  constructor(canvas, vennDiagramm) {\n    this.vennDiagramm = vennDiagramm\n    this.canvas = canvas\n    this.canvasWidth = canvas.width\n    this.canvasHeight = canvas.height\n    this.forceCenters = []\n    this.noMatchThemeGroup = null\n    this.themeGroups = []\n    this.forceCenterLayouter = new ForceCenterLayouter(this.canvasWidth, this.canvasHeight, this.vennDiagramm)\n  }\n  \n  // ------------------------------------------\n  // Public Methods\n  // ------------------------------------------\n  \n  setDataProcessor(dataProcessor) {\n    this.dataProcessor = dataProcessor\n  } \n  \n  setColorStore(colorStore) {\n    this.colorStore = colorStore\n  }\n  \n  getForceCenters(){\n    return this.forceCenters\n  }\n  \n  async updateLayout() {\n    await this.forceCenterLayouter.layoutForceCenters(this.forceCenters)\n  }\n  \n  setCanvasExtent(newCanvasWidth, newCanvasHeight) {\n    this.forceCenterLayouter.setCanvasExtent(newCanvasWidth, newCanvasHeight)\n  }\n  \n  getForceCenterAnnotations() {\n    return this.forceCenters.map(forceCenter => forceCenter.getAnnotation())\n  }\n  \n  setInitialForceCenter() {\n    this.forceCenters = []\n    this._createNoMatchThemeGroup()\n    let forceCenter = new ForceCenter([this.noMatchThemeGroup])\n    forceCenter.setDataProcessor(this.dataProcessor)\n    forceCenter.setColorStore(this.colorStore)\n    this.forceCenters.push(forceCenter)\n  } \n  \n  getThemeGroups() {\n    let allThemeGroups = [this.noMatchThemeGroup]\n    allThemeGroups.push(...this.themeGroups)\n    \n    return allThemeGroups\n  }\n  \n  addThemeGroup(uuid, name, themes, color){\n    let newThemeGroup = new ThemeGroup(uuid, name, themes, color)\n    let newForceCenterGroupPermutations = this._createGroupPermutationsWithNewGroup(newThemeGroup)\n    this._addNewForceCentersForGroups(newForceCenterGroupPermutations)\n    this._sortForceCentersDescendingByGroupCount()\n    this._addThemeGroup(newThemeGroup)\n  }\n  \n  updateThemeGroup(uuid, name, themes, color) {\n    this.themeGroups.forEach(themeGroup => {\n      if(themeGroup.uuid === uuid) {\n        themeGroup.setColor(color)\n        themeGroup.setThemes(themes)\n        themeGroup.setName(name)\n      }\n    })\n  }\n  \n  removeThemeGroup(uuid) {\n    this._removeForceCentersContainingGroup(uuid)\n    this.themeGroups = this.themeGroups.filter(themeGroup => !(themeGroup.uuid === uuid))\n  }\n  \n  // ------------------------------------------\n  // Private Methods\n  // ------------------------------------------\n  \n  _createNoMatchThemeGroup() {\n    let uuid = generateUUID()\n    this.noMatchThemeGroup = new ThemeGroup(uuid, \"no match\", [], '#00FF44')\n  }\n  \n  _createGroupPermutationsWithNewGroup(newThemeGroup){\n    let combinedThemeGroups = [...this.themeGroups]\n    combinedThemeGroups.push(newThemeGroup)\n    \n    let permutations = combinedThemeGroups.reduce(\n        (subsets, value) => subsets.concat(\n         subsets.map(set => [value,...set])\n        ),\n        [[]]\n      )\n    \n    let permutationsWithNewGroup = permutations.filter(\n      permutation => permutation.includes(newThemeGroup)\n    )\n    return permutationsWithNewGroup\n  }\n  \n  _addNewForceCentersForGroups(forceCenterGroupPermutations) {\n    forceCenterGroupPermutations.forEach(groupPermutation => {\n      let forceCenter = new ForceCenter(groupPermutation)\n      forceCenter.setDataProcessor(this.dataProcessor)\n      forceCenter.setColorStore(this.colorStore)\n      this.forceCenters.push(forceCenter)\n    })\n  }\n  \n  _sortForceCentersDescendingByGroupCount() {\n    this.forceCenters.sort((forceCenter1, forceCenter2) => {\n      return forceCenter2.themeGroups.length - forceCenter1.themeGroups.length\n    })\n    \n    this._putNoMatchAtTheEnd()\n  }\n  \n  _putNoMatchAtTheEnd() {\n    let noMatchForceCenter = this.forceCenters.filter(\n      forceCenter => forceCenter.themeGroups.includes(this.noMatchThemeGroup)\n    )[0]\n    this.forceCenters.push(\n      this.forceCenters.splice(this.forceCenters.indexOf(noMatchForceCenter), 1)[0]\n    );\n  }\n  \n  _addThemeGroup(themeGroup) {\n    this.themeGroups.push(themeGroup)\n  }\n  \n  _removeForceCentersContainingGroup(uuid) {\n    let remainingForceCenters = []\n    this.forceCenters.forEach(forceCenter => {\n      if(forceCenter.includesGroup(uuid)){\n        forceCenter.removeInnerContent()\n      } else {\n        remainingForceCenters.push(forceCenter)\n      }\n    })\n    \n    this.forceCenters = remainingForceCenters\n  }\n}"]}