{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH-stable/components/bp2019-legend-widget.js"],"names":["Morph","ColorAction","LegendWidget","initialize","legendElementsContainer","get","setColorStore","colorStore","applyAction","action","_update","colorAction","attribute","_updateEmpty","_updateColored","_clearCurrentLegendElements","currentColorsByValue","getColorValuesForAttribute","_generateNewLegend","colorsByValue","_createNewLegend","legendElement","lastElementChild","removeChild","Object","keys","forEach","value","newLegendElement","_createLegendElement","appendChild","notSelected","getDeselectColor","color","singleElementParent","singleElementRow","valueDiv","colorDiv","style","backgroundColor","convertColorObjectToRGBAValue"],"mappings":";;;;;;;;;;;;;AAAOA,W;;AACEC,iB,kDAAAA,W;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,YAAMC,YAAN,SAA2BF,KAA3B,CAAiC;;AAE9C,cAAMG,UAAN,GAAmB;AACjB,eAAKC,uBAAL,GAA+B,KAAKC,GAAL,CAAS,4BAAT,CAA/B;AACD;;AAED;AACA;AACA;;AAEAC,sBAAcC,UAAd,EAA0B;AACxB,eAAKA,UAAL,GAAkBA,UAAlB;AACD;;AAED,cAAMC,WAAN,CAAkBC,MAAlB,EAA0B;AACxB,kBAAQ,IAAR;AACE,iBAAMA,kBAAkBR,WAAxB;AACE,mBAAKS,OAAL,CAAaD,MAAb;AACA;AACF;AACE;AALJ;AAOD;;AAED;AACA;AACA;;AAEAC,gBAAQC,WAAR,EAAqB;AACnB,cAAIA,YAAYC,SAAZ,KAA0B,MAA9B,EAAsC;AACpC,iBAAKC,YAAL;AACD,WAFD,MAEO;AACL,iBAAKC,cAAL,CAAoBH,WAApB;AACD;AACF;;AAEDE,uBAAe;AACb,eAAKE,2BAAL;AACD;;AAEDD,uBAAeH,WAAf,EAA4B;AAC1B,cAAIK,uBAAuB,KAAKT,UAAL,CAAgBU,0BAAhB,CAA2CN,YAAYC,SAAvD,CAA3B;AACA,eAAKM,kBAAL,CAAwBF,oBAAxB;AACD;;AAEDE,2BAAmBC,aAAnB,EAAiC;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A9C,CAAjC;;AAEAE,2BAAiBL,WAAjB,CAA6BO,QAA7B;AACAF,2BAAiBL,WAAjB,CAA6BM,QAA7B;;AAEAF,8BAAoBJ,WAApB,CAAgCK,gBAAhC;;AAEA,iBAAOD,mBAAP;AACD;;AAlF6C;;yBAA3BhC,Y","file":"bp2019-legend-widget.js","sourcesContent":["import Morph from 'src/components/widgets/lively-morph.js'\nimport { ColorAction } from '../src/internal/individuals-as-points/common/actions.js'\n\nexport default class LegendWidget extends Morph {\n  \n  async initialize() {\n    this.legendElementsContainer = this.get('#legend-elements-container')  \n  }\n  \n  // ------------------------------------------\n  // Public Methods\n  // ------------------------------------------\n  \n  setColorStore(colorStore) {\n    this.colorStore = colorStore\n  }\n  \n  async applyAction(action) {\n    switch (true){\n      case (action instanceof ColorAction):\n        this._update(action);\n        break;\n      default:\n        break;\n    }\n  }\n  \n  // ------------------------------------------\n  // Private Methods\n  // ------------------------------------------\n  \n  _update(colorAction) {\n    if (colorAction.attribute === \"none\") {\n      this._updateEmpty()\n    } else {\n      this._updateColored(colorAction)\n    }    \n  }\n  \n  _updateEmpty() {\n    this._clearCurrentLegendElements()\n  }\n  \n  _updateColored(colorAction) {\n    let currentColorsByValue = this.colorStore.getColorValuesForAttribute(colorAction.attribute);\n    this._generateNewLegend(currentColorsByValue);\n  }\n  \n  _generateNewLegend(colorsByValue){\n    this._clearCurrentLegendElements();\n    this._createNewLegend(colorsByValue);\n  }\n  \n  _clearCurrentLegendElements(){\n    var legendElement = this.legendElementsContainer.lastElementChild;\n    while (legendElement) { \n        this.legendElementsContainer.removeChild(legendElement); \n        legendElement = this.legendElementsContainer.lastElementChild; \n    } \n  }\n  \n  _createNewLegend(colorsByValue){\n    Object.keys(colorsByValue).forEach((value) => {\n      let newLegendElement = this._createLegendElement(value, colorsByValue[value]);\n      this.legendElementsContainer.appendChild(newLegendElement);\n    })\n    let notSelected = this._createLegendElement(\"not selected\", this.colorStore.getDeselectColor())\n    this.legendElementsContainer.appendChild(notSelected)\n  }\n  \n  _createLegendElement(value, color) {\n    let singleElementParent = <div class=\"col-2 p-2\"></div>;\n    \n    let singleElementRow = <div class=\"row\"></div>;\n    \n    let valueDiv = <div class=\"col-7\">{value}</div>\n    let colorDiv = <div class=\"col-5 dot\"></div>;\n    colorDiv.style.backgroundColor = this.colorStore.convertColorObjectToRGBAValue(color);\n    \n    singleElementRow.appendChild(colorDiv);\n    singleElementRow.appendChild(valueDiv);\n    \n    singleElementParent.appendChild(singleElementRow);\n    \n    return singleElementParent;\n  }\n  \n}\n"]}