function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_toPropertyKey(n.key),n)}}function _createClass(t,e,i){return e&&_defineProperties(t.prototype,e),i&&_defineProperties(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:e+""}function _toPrimitive(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0===i)return("string"===e?String:Number)(t);i=i.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}var EspoFunnel={};window.EspoFunnel=EspoFunnel;!function(t){t.Funnel=(()=>_createClass(function t(e,i,n){_classCallCheck(this,t);this.params=Object.assign({},i||{});this.dataList=n||[];this.element=document.createElementNS("http://www.w3.org/2000/svg","svg");e&&e.appendChild(this.element);this.trapElementList=[];this.element.setAttribute("width","100%");this.element.setAttribute("height","100%");var s,o={padding:10,colors:["#b770e0","#63a7c2","#c96947","#ccc058","#ab414a"],outlineColor:"red",strokeWidth:1,gapWidth:.01,events:{},showTooltip:!0,tooltipClassName:"",tooltipStyleString:"display:block;position:absolute;white-space:nowrap;",callbacks:{}};for(s in o)s in this.params||(this.params[s]=o[s]);this.draw()},[{key:"getMaxValue",value:function(){var t,e=0;for(t of this.dataList)t.value>e&&(e=t.value);return e}},{key:"draw",value:function(){var t=this.element.getBoundingClientRect().width,e=this.element.getBoundingClientRect().height,i=this.params.padding,r=e*this.params.gapWidth,n=this.dataList.length,s=(this.cWidth=t,this.getMaxValue()),a=this.centerX=t/2,l=i,t=t-2*i,e=e-2*i,h=(e-r*n)/n,u=this.ratio=t/s;this.trapElementList.forEach(function(t){this.element.removeChild(t)},this);this.trapElementList=[];this.positionList=[];this.dataList.forEach(function(t,e){var i=t.value,n=i/2*u,s=l+h*e+r*e,o=s+h,i=(i=e===this.dataList.length-1?i:(i=this.dataList[e+1],i.value),i/2*u),s=(this.positionList.push([s,o,a,n,i]),this.drawTrapElement(s,o,a,n,i,this.getItemColor(e)));this.trapElementList.push(s);this.registerMouseEvents(s,e);this.element.appendChild(s)},this)}},{key:"getItemColor",value:function(t){var e=this.params.colors[t]||"#AAA";return e}},{key:"drawTrapElement",value:function(t,e,i,n,s,o){var r=document.createElementNS("http://www.w3.org/2000/svg","path"),a="M"+(i+n)+","+t+" ";a+="L"+(i-n)+","+t+" ";a+="L"+(i-s)+","+e+" ";a+="L"+(i+s)+","+e+" ";a+="L"+(i+n)+","+t;r.setAttribute("d",a);r.setAttribute("fill",o);r.setAttribute("stroke-width",this.params.strokeWidth);r.setAttribute("stroke",o);return r}},{key:"showTooltip",value:function(t){var e=this.params.tooltipStyleString,i=this.params.tooltipClassName,n=document.createElement("div");n.setAttribute("style",e);n.setAttribute("class",i);e=this.params.callbacks.tooltipHtml;if(e){var i=e(t),e=this.positionList[t],s=e[2]+e[3],o=e[0],e=e[3]>this.cWidth/5,r=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop,a=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft,a=a+this.element.getBoundingClientRect().left,r=r+this.element.getBoundingClientRect().top;s+=a;o+=r;n.innerHTML=i;n.style.top=o+"px";n.style.left=s+"px";n.style.pointerEvents="none";e&&(n.style.transform="translate(-100%, 0)");this.tooltipElement=n;document.body.appendChild(n)}}},{key:"hideTooltip",value:function(t){document.body.removeChild(this.tooltipElement)}},{key:"outlineItem",value:function(t){var e=this.trapElementList[t];e&&e.setAttribute("stroke",this.params.outlineColor)}},{key:"cancelOutlineItem",value:function(t){var e=this.trapElementList[t];e&&e.setAttribute("stroke",this.getItemColor(t))}},{key:"registerMouseEvents",value:function(t,e){t.onclick=function(t){1===t.which?this.triggerEvent("leftClick",{index:e,originalEvent:t}):2===t.which&&this.triggerEvent("rightClick",{index:e,originalEvent:t})}.bind(this);t.onmouseover=function(t){this.outlineItem(e);this.params.showTooltip&&this.showTooltip(e)}.bind(this);t.onmouseout=function(t){this.cancelOutlineItem(e);this.params.showTooltip&&this.hideTooltip(e)}.bind(this)}},{key:"triggerEvent",value:function(t,e){var i=this.params.events[t];i&&i.call(this,e)}}]))()}.call(this,EspoFunnel);
//# sourceMappingURL=espo-funnel-chart.js.map