{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH1/components/legend-widget.js"],"names":["Morph","ColorAction","ColorStore","LegendWidget","initialize","legendElementsContainer","get","applyActionFromRootApplication","action","_update","colorAction","currentColorsByValue","getColorValuesForAttribute","attribute","_generateNewLegend","colorsByValue","_clearCurrentLegendElements","_createNewLegend","legendElement","lastElementChild","removeChild","Object","keys","forEach","value","newLegendElement","_createLegendElement","appendChild","color","singleElementParent","singleElementRow","valueDiv","colorDiv","style","backgroundColor"],"mappings":";;;;;;;;;;;;;AAAOA,W;;AACAC,iB;;AACAC,gB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEQ,YAAMC,YAAN,SAA2BH,KAA3B,CAAiC;;AAE9C,cAAMI,UAAN,GAAmB;AACjB,eAAKC,uBAAL,GAA+B,KAAKC,GAAL,CAAS,4BAAT,CAA/B;AACD;;AAED;AACA;AACA;;AAEAC,uCAA+BC,MAA/B,EAAuC;AACrC,kBAAQ,IAAR;AACE,iBAAMA,kBAAkBP,WAAxB;AACE,mBAAKQ,OAAL,CAAaD,MAAb;AACA;AACF;AACE;AALJ;AAOD;;AAGD;AACA;AACA;;AAEAC,gBAAQC,WAAR,EAAqB;AACnB,cAAIC,uBAAuBT,WAAWU,0BAAX,CAAsCF,YAAYG,SAAlD,CAA3B;AACA,eAAKC,kBAAL,CAAwBH,oBAAxB;AACD;;AAEDG,2BAAmBC,aAAnB,EAAiC;AAC/B,eAAKC,2BAAL;AACA,eAAKC,gBAAL,CAAsBF,aAAtB;AACD;;AAEDC,sCAA6B;AAC3B,cAAIE,gBAAgB,KAAKb,uBAAL,CAA6Bc,gBAAjD;AACA,iBAAOD,aAAP,EAAsB;AAClB,iBAAKb,uBAAL,CAA6Be,WAA7B,CAAyCF,aAAzC;AACAA,4BAAgB,KAAKb,uBAAL,CAA6Bc,gBAA7C;AACH;AACF;;AAEDF,yBAAiBF,aAAjB,EAA+B;AAC7BM,iBAAOC,IAAP,CAAYP,aAAZ,EAA2BQ,OAA3B,CAAoCC,KAAD,IAAW;AAC5C,gBAAIC,mBAAmB,KAAKC,oBAAL,CAA0BF,KAA1B,EAAiCT,cAAcS,KAAd,CAAjC,CAAvB;AACA,iBAAKnB,uBAAL,CAA6BsB,WAA7B,CAAyCF,gBAAzC;AACD,WAHD;AAID;;AAEDC,6BAAqBF,KAArB,EAA4BI,KAA5B,EAAmC;AACjC,cAAIC,mFAAiC,WAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAJ;;AAEA,cAAIC,gFAA8B,KAA9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAJ;;AAEA,cAAIC,wEAAsB,OAAtB,+BAA+BP,KAA/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAJ;AACA,cAAIQ,wEAAsB,WAAtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAJ;AACAA,mBAASC,KAAT,CAAeC,eAAf,GAAiCN,KAAjC;;AAEAE,2BAAiBH,WAAjB,CAA6BK,QAA7B;AACAF,2BAAiBH,WAAjB,CAA6BI,QAA7B;;AAEAF,8BAAoBF,WAApB,CAAgCG,gBAAhC;;AAEA,iBAAOD,mBAAP;AACD;;AAjE6C;;yBAA3B1B,Y","file":"legend-widget.js","sourcesContent":["import Morph from 'src/components/widgets/lively-morph.js'\nimport ColorAction from '../src/internal/individuals-as-points/common/actions/color-action.js'\nimport ColorStore from '../src/internal/individuals-as-points/common/color-store.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  applyActionFromRootApplication(action) {\n    switch (true){\n      case (action instanceof ColorAction):\n        this._update(action);\n        break;\n      default:\n        break;\n    }\n  }\n  \n  \n  // ------------------------------------------\n  // Private Methods\n  // ------------------------------------------\n  \n  _update(colorAction) {\n    let currentColorsByValue = 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  }\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 = color;\n    \n    singleElementRow.appendChild(colorDiv);\n    singleElementRow.appendChild(valueDiv);\n    \n    singleElementParent.appendChild(singleElementRow);\n    \n    return singleElementParent;\n  }\n  \n}\n"]}