visavi/rotor

View on GitHub
public/assets/js/chartist-plugin-tooltip.min.js

Summary

Maintainability
A
0 mins
Test Coverage
!function(l,y,h){"use strict";var t={currency:void 0,currencyFormatCallback:void 0,tooltipOffset:{x:0,y:-20},anchorToPoint:!1,appendToBody:!1,class:void 0,pointClass:"ct-point"};function o(t){var e=new RegExp("tooltip-show\\s*","gi");t.className=t.className.replace(e,"").trim()}function x(t,e){return-1<(" "+t.getAttribute("class")+" ").indexOf(" "+e+" ")}h.plugins=h.plugins||{},h.plugins.tooltip=function(v){return v=h.extend({},t,v),function(f){var t=v.pointClass;f.constructor.name instanceof h.Bar?t="ct-bar":f.constructor.name instanceof h.Pie&&(t=f.options.donut?"ct-slice-donut":"ct-slice-pie");var c=f.container,u=c.querySelector(".chartist-tooltip");u||((u=y.createElement("div")).className=v.class?"chartist-tooltip "+v.class:"chartist-tooltip",v.appendToBody?y.body.appendChild(u):c.appendChild(u));var d=u.offsetHeight,g=u.offsetWidth;function e(t,e,o){c.addEventListener(t,function(t){e&&!x(t.target,e)||o(t)})}function m(t){d=d||u.offsetHeight;var e,o,n=-(g=g||u.offsetWidth)/2+v.tooltipOffset.x,a=-d+v.tooltipOffset.y;if(v.appendToBody)u.style.top=t.pageY+a+"px",u.style.left=t.pageX+n+"px";else{var i=c.getBoundingClientRect(),r=t.pageX-i.left-l.pageXOffset,s=t.pageY-i.top-l.pageYOffset;!0===v.anchorToPoint&&t.target.x2&&t.target.y2&&(e=parseInt(t.target.x2.baseVal.value),o=parseInt(t.target.y2.baseVal.value)),u.style.top=(o||s)+a+"px",u.style.left=(e||r)+n+"px"}}o(u),e("mouseover",t,function(t){var e,o,n=t.target,a="",i=(f instanceof h.Pie?n:n.parentNode)?n.parentNode.getAttribute("ct:meta")||n.parentNode.getAttribute("ct:series-name"):"",r=n.getAttribute("ct:meta")||i||"",s=!!r,c=n.getAttribute("ct:value");if(v.transformTooltipTextFnc&&"function"==typeof v.transformTooltipTextFnc&&(c=v.transformTooltipTextFnc(c)),v.tooltipFnc&&"function"==typeof v.tooltipFnc)a=v.tooltipFnc(r,c);else{if(v.metaIsHTML){var l=y.createElement("textarea");l.innerHTML=r,r=l.value}if(r='<span class="chartist-tooltip-meta">'+r+"</span>",s)a+=r+"<br>";else if(f instanceof h.Pie){var p=function(t,e){for(;t=t.nextSibling,t&&!x(t,e););return t}(n,"ct-label");p&&(a+=((e=p).innerText||e.textContent)+"<br>")}c&&(v.currency&&(c=null!=v.currencyFormatCallback?v.currencyFormatCallback(c,v):v.currency+c.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g,"$1,")),a+=c='<span class="chartist-tooltip-value">'+c+"</span>")}a&&(u.innerHTML=a,m(t),x(o=u,"tooltip-show")||(o.className=o.className+" tooltip-show"),d=u.offsetHeight,g=u.offsetWidth)}),e("mouseout",t,function(){o(u)}),e("mousemove",null,function(t){!1===v.anchorToPoint&&m(t)})}}}(window,document,Chartist);