{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH1/components/bp2019-y-axis-group-widget.js"],"names":["Morph","assertListenerInterface","GroupAction","Bp2019YAxisGroupWidget","initialize","name","isGlobal","axis","listeners","valuesByAttribute","attributeSelect","get","addEventListener","_applyGrouping","addListener","listener","push","initializeWithData","attributes","themeString","includes","splice","indexOf","_setSelectionOptions","appendChild","Option","_clearSelectOptions","forEach","attribute","select","options","length","remove","groupAction","_createGroupAction","applyAction","selectedGroupingAttribute","_getSelectedGroupAttribute","selectedIndex","value"],"mappings":"AAAA;;;;;;;;AAEOA,W;;AACEC,6B,qDAAAA,uB;;AACAC,iB,kDAAAA,W;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,YAAMC,sBAAN,SAAqCH,KAArC,CAA2C;AACxD,cAAMI,UAAN,GAAmB;AACjB,eAAKC,IAAL,GAAY,OAAZ;AACA,eAAKC,QAAL,GAAgB,KAAhB;AACA,eAAKC,IAAL,GAAY,GAAZ;;AAEA,eAAKC,SAAL,GAAiB,EAAjB;AACA,eAAKC,iBAAL,GAAyB,EAAzB;;AAEA,eAAKC,eAAL,GAAuB,KAAKC,GAAL,CAAS,kBAAT,CAAvB;AACA,eAAKD,eAAL,CAAqBE,gBAArB,CAAsC,QAAtC,EAAgD,MAAM;AACpD,iBAAKC,cAAL;AACD,WAFD;AAGD;;AAED;AACA;AACA;;AAEAC,oBAAYC,QAAZ,EAAsB;AACpBd,kCAAwBc,QAAxB;AACA,eAAKP,SAAL,CAAeQ,IAAf,CAAoBD,QAApB;AACD;;AAEDE,2BAAmBC,UAAnB,EAA+B;AAC7B,cAAIC,cAAc,QAAlB;AACA,cAAID,WAAWE,QAAX,CAAoBD,WAApB,CAAJ,EAAsC;AACpCD,uBAAWG,MAAX,CAAkBH,WAAWI,OAAX,CAAmBH,WAAnB,CAAlB,EAAmD,CAAnD;AACD;AACD,eAAKI,oBAAL,CAA0BL,UAA1B;AACA,eAAKR,eAAL,CAAqBc,WAArB,CAAiC,IAAIC,MAAJ,CAAW,QAAX,CAAjC;AACD;;AAED;AACA;AACA;;;AAGAF,6BAAqBL,UAArB,EAAiC;AAC/B,eAAKQ,mBAAL,CAAyB,KAAKhB,eAA9B;AACA,eAAKA,eAAL,CAAqBc,WAArB,CAAiC,IAAIC,MAAJ,CAAW,MAAX,CAAjC;AACAP,qBAAWS,OAAX,CAAmBC,aAAa;AAC9B,iBAAKlB,eAAL,CAAqBc,WAArB,CAAiC,IAAIC,MAAJ,CAAWG,SAAX,CAAjC;AACD,WAFD;AAGD;;AAEAF,4BAAoBG,MAApB,EAA4B;AAC3B,iBAAMA,OAAOC,OAAP,CAAeC,MAAf,GAAwB,CAA9B,EAAiC;AAC/BF,mBAAOC,OAAP,CAAeE,MAAf,CAAsB,CAAtB;AACD;AACF;;AAEDnB,yBAAiB;AACf,cAAIoB,cAAc,KAAKC,kBAAL,EAAlB;AACA,eAAK1B,SAAL,CAAemB,OAAf,CAAuBZ,YAAY;AACjCA,qBAASoB,WAAT,CAAqBF,WAArB;AACD,WAFD;AAGD;;AAEDC,6BAAoB;AAClB,cAAIE,4BAA4B,KAAKC,0BAAL,EAAhC;AACA,iBAAO,IAAInC,WAAJ,CAAgBkC,yBAAhB,EAA2C,KAAK9B,QAAhD,EAA0D,KAAKC,IAA/D,EAAqE,CAAC,QAAD,CAArE,CAAP;AACD;;AAED8B,qCAA6B;AAC3B,iBAAO,KAAK3B,eAAL,CAAqBoB,OAArB,CAA6B,KAAKpB,eAAL,CAAqB4B,aAAlD,EAAiEC,KAAxE;AACD;AAlEuD;;yBAArCpC,sB","file":"bp2019-y-axis-group-widget.js","sourcesContent":["\"enable aexpr\";\n\nimport Morph from 'src/components/widgets/lively-morph.js'\nimport { assertListenerInterface } from '../src/internal/individuals-as-points/common/interfaces.js'\nimport { GroupAction } from '../src/internal/individuals-as-points/common/actions.js'\n\nexport default class Bp2019YAxisGroupWidget extends Morph {\n  async initialize() {\n    this.name = \"group\";\n    this.isGlobal = false;\n    this.axis = \"x\";\n    \n    this.listeners = [];\n    this.valuesByAttribute = {};\n    \n    this.attributeSelect = this.get(\"#attributeSelect\");\n    this.attributeSelect.addEventListener(\"change\", () => {\n      this._applyGrouping()\n    })\n  }\n  \n  // ------------------------------------------\n  // Public Methods\n  // ------------------------------------------\n  \n  addListener(listener) {\n    assertListenerInterface(listener);\n    this.listeners.push(listener);\n  }\n  \n  initializeWithData(attributes) {\n    let themeString = \"themes\"\n    if (attributes.includes(themeString)) {\n      attributes.splice(attributes.indexOf(themeString), 1)\n    }\n    this._setSelectionOptions(attributes);\n    this.attributeSelect.appendChild(new Option(\"amount\"));\n  }\n   \n  // ------------------------------------------\n  // Private Methods\n  // ------------------------------------------\n  \n  \n  _setSelectionOptions(attributes) {\n    this._clearSelectOptions(this.attributeSelect);\n    this.attributeSelect.appendChild(new Option(\"none\"))\n    attributes.forEach(attribute => {\n      this.attributeSelect.appendChild(new Option(attribute));\n    });\n  }\n  \n   _clearSelectOptions(select) {\n    while(select.options.length > 0) {\n      select.options.remove(0);\n    }\n  }\n  \n  _applyGrouping() {\n    let groupAction = this._createGroupAction();\n    this.listeners.forEach(listener => {\n      listener.applyAction(groupAction);\n    });\n  }\n  \n  _createGroupAction(){\n    let selectedGroupingAttribute = this._getSelectedGroupAttribute();\n    return new GroupAction(selectedGroupingAttribute, this.isGlobal, this.axis, [\"themes\"]);\n  }\n  \n  _getSelectedGroupAttribute() {\n    return this.attributeSelect.options[this.attributeSelect.selectedIndex].value\n  }\n}"]}