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