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 s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function _createClass(t,e,i){return e&&_defineProperties(t.prototype,e),i&&_defineProperties(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}var EspoFunnel={};window.EspoFunnel=EspoFunnel,function(t){t.Funnel=(()=>{function o(t,e,i){_classCallCheck(this,o),this.params=Object.assign({},e||{}),this.dataList=i||[],this.element=document.createElementNS("http://www.w3.org/2000/svg","svg"),t&&t.appendChild(this.element),this.trapElementList=[],this.element.setAttribute("width","100%"),this.element.setAttribute("height","100%");var s,n={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 n)s in this.params||(this.params[s]=n[s]);this.draw()}return _createClass(o,[{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,o=e*this.params.gapWidth,s=this.dataList.length,n=(this.cWidth=t,this.getMaxValue()),l=this.centerX=t/2,a=i,r=(e-2*i-o*s)/s,h=this.ratio=(t-2*i)/n;this.trapElementList.forEach(function(t){this.element.removeChild(t)},this),this.trapElementList=[],this.positionList=[],this.dataList.forEach(function(t,e){var t=t.value,i=t/2*h,s=a+r*e+o*e,n=s+r,t=(e===this.dataList.length-1?t:this.dataList[e+1].value)/2*h,s=(this.positionList.push([s,n,l,i,t]),this.drawTrapElement(s,n,l,i,t,this.getItemColor(e)));this.trapElementList.push(s),this.registerMouseEvents(s,e),this.element.appendChild(s)},this)}},{key:"getItemColor",value:function(t){return this.params.colors[t]||"#AAA"}},{key:"drawTrapElement",value:function(t,e,i,s,n,o){var l=document.createElementNS("http://www.w3.org/2000/svg","path"),a="M"+(i+s)+","+t+" ";return l.setAttribute("d",a+("L"+(i-s)+","+t+" ")+("L"+(i-n)+","+e+" ")+("L"+(i+n)+","+e+" ")+("L"+(i+s)+","+t)),l.setAttribute("fill",o),l.setAttribute("stroke-width",this.params.strokeWidth),l.setAttribute("stroke",o),l}},{key:"showTooltip",value:function(t){var e,i,s=this.params.tooltipStyleString,n=this.params.tooltipClassName,o=document.createElement("div"),s=(o.setAttribute("style",s),o.setAttribute("class",n),this.params.callbacks.tooltipHtml);s&&(n=s(t),t=(s=this.positionList[t])[2]+s[3],e=s[0],s=s[3]>this.cWidth/5,i=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop,t+=(window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft)+this.element.getBoundingClientRect().left,e+=i+this.element.getBoundingClientRect().top,o.innerHTML=n,o.style.top=e+"px",o.style.left=t+"px",o.style.pointerEvents="none",s&&(o.style.transform="translate(-100%, 0)"),this.tooltipElement=o,document.body.appendChild(o))}},{key:"hideTooltip",value:function(t){document.body.removeChild(this.tooltipElement)}},{key:"outlineItem",value:function(t){t=this.trapElementList[t];t&&t.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){t=this.params.events[t];t&&t.call(this,e)}}]),o})()}.call(this,EspoFunnel);
//# sourceMappingURL=espo-funnel-chart.js.map