Вход Регистрация
Файл: public/assets/js/liteChart.min.js
Строк: 728
<?php
function liteChart(a,b){let c=document.getElementById(a);if(null!=c)throw new Error("DOM id "+a+" is already exist.");this.id=a,panel=document.createElementNS("http://www.w3.org/2000/svg","svg"),panel.setAttribute("id",a),panel.setAttribute("class",a);var d={animate:{show:!this.isIE,duration:.5},axisX:{show:!0,color:"#e9edf1",width:2,value:"",minValue:0,maxValue:0},axisY:{show:!0,color:"#e9edf1",width:2,value:"",minValue:0,maxValue:0},eventCoord:{x:0,y:0},fill:"gradient",gridX:{show:!0,interval:0,fill:1,label:{show:!0},stroke:"#e9edf1",width:2,dasharray:"0 10.04",linecap:"round"},gridY:{show:!0,interval:0,fill:1,label:{show:!0},stroke:"#e9edf1",width:2,dasharray:"0 10.04",linecap:"round"},isIE:!(("Netscape"!=navigator.appName||-1==navigator.userAgent.search("Trident"))&&-1==navigator.userAgent.toLowerCase().indexOf("msie")),labels:{show:!0,fontColor:"#c5c6d0",fontSize:12,fontFamily:"sans-serif",fontWeight:"normal",list:null},legends:{list:null,map:null,table:{show:!0,position:{x:"center",y:370},direction:"horizontal"},fill:"#c5c6d0"},line:{width:3,style:"curve",shadow:!0,dasharray:null},padding:{top:55,right:15,bottom:40,left:20},panel:panel,point:{show:!0,radius:5,strokeWidth:5,stroke:"#ffffff"},tooltip:{show:!0,backgroundColor:"rgba(255, 255, 255, 0.8)",fontColor:"#000000",object:null},type:"Line",valueOnliteChart:{show:!1}};Object.assign(this,d,b)}function createElement(a,b){for(var c in el=document.createElementNS("http://www.w3.org/2000/svg",a),b)el.setAttribute(c,b[c]);return el}function createText(a,b,c,d,e,f,g,h){navigator.userAgent.toLowerCase();chart.isIE&&("hanging"==f?c+=d:"middle"==f?c+=d/2:"baseline"==f);let j=createElement("text",{id:a,x:b.toFixed(0),y:c.toFixed(0),"font-size":d,"text-anchor":e,fill:g});return chart.isIE||j.setAttribute("alignment-baseline",f),j.innerHTML=h,j.textContent=h,j}function getPath(a,b){return i=0,path="","straight"===a.line.style?b.forEach(function(a){0===i&&(path+=" M "),path+=a.x1.toFixed(0)+" "+a.y1.toFixed(0)+" ",++i,b.length===i&&(path+=a.x2.toFixed(0)+" "+a.y2.toFixed(0))}):"curve"===a.line.style&&b.forEach(function(a){0===i&&(path+="M "+a.x1.toFixed(0)+" "+a.y1.toFixed(0)),path+=" C "+a.cx1.toFixed(0)+" "+a.cy1.toFixed(0)+" "+a.cx2.toFixed(0)+" "+a.cy2.toFixed(0)+" "+a.x2.toFixed(0)+" "+a.y2.toFixed(0),++i}),path}liteChart.prototype.getWidth=function(){return this.panel.getBoundingClientRect().width},liteChart.prototype.getHeight=function(){return this.panel.getBoundingClientRect().height},liteChart.prototype.setLabels=function(a){this.labels.list=a},liteChart.prototype.addLegend=function(a){let c=null,d=null,e=null;null==this.legends.list&&(this.legends.list=[]),null==a.fill&&(c=Math.floor(255*Math.random()),d=Math.floor(255*Math.random()),e=Math.floor(255*Math.random()),a.fill="rgba("+c+", "+d+", "+e+", 0.9)"),null==a.stroke&&(null!=c&&(c-=10,c=0>c?0:c,d-=10,d=0>d?0:d,e-=10,e=0>e?0:e),a.stroke="rgba("+c+", "+d+", "+e+", 1)"),this.legends.list.push(a),null==this.legends.map&&(this.legends.map=new Map),this.legends.map.set(a.name,a)},liteChart.prototype.removeLegend=function(a){let b=-1;if(null!=this.legends.list){for(let c=0;c<this.legends.list.length;c++)if(this.legends.list[c].name==a){b=c;break}-1<b&&(this.legends.list.splice(b,1),this.legends.map.delete(a))}},liteChart.prototype.getLegend=function(a){return this.legends.map.get(a)},liteChart.prototype.getMinValue=function(){let a=0,b=this.legends.list,c=this.values;return b.forEach(function(b){b.values.forEach(function(b){a>b&&(a=b)})}),a},liteChart.prototype.getMaxValue=function(){let a=0,b=this.legends.list,c=this.values;return b.forEach(function(b){b.values.forEach(function(b){a<b&&(a=b)})}),a},liteChart.prototype.showTooltip=function(a,b,c){let d=a.clientX,e=a.clientY;if(d==c.eventCoord.x&&e==c.eventCoord.y)return;c.eventCoord.x=d,c.eventCoord.y=e;let f=b.getAttribute("legend"),g=c.getLegend(f),h=b.getAttribute("value"),j=b.getAttribute("label"),k=c.labels.fontSize,l=.5*k,m=l,n=k+2*l,o=2*k+3*l,p=0,q=0,r=0,s=3*k+4*l,t=c.tooltip.object;if(d+=10,e+=10,null==t||null==t){t=document.createElementNS("http://www.w3.org/2000/svg","g"),c.isIE||t.classList.add("tooltips");let a=createElement("rect",{id:c.id+"-tooltip",x:d,y:e,width:0,height:s,fill:c.tooltip.backgroundColor,stroke:"transparent",rx:5,ry:5});t.appendChild(a);let b=createText(c.id+"-tooltip-label-text",d+l,e+m,k,"start","hanging",c.tooltip.fontColor,j);t.appendChild(b);let u=createElement("rect",{id:c.id+"-tooltip-legend-mark",x:d+l,y:e+n,width:k,height:k,fill:g.fill,stroke:g.stroke});t.appendChild(u);let v=createText(c.id+"-tooltip-legend-name",d+(2*l+k),e+n,k,"start","hanging",c.tooltip.fontColor,f+": ");t.appendChild(v);let w=createText(c.id+"-tooltip-value",d+l,e+o,k,"start","hanging",c.tooltip.fontColor,h);t.appendChild(w),c.tooltip.object=t,c.panel.appendChild(c.tooltip.object),q=1*u.getAttribute("width")+l+v.getBoundingClientRect().width,r=w.getBoundingClientRect().width,p=(q>r?q:r)+2*l,a.setAttribute("width",p)}else{t=c.tooltip.object;let a=t.childNodes[0],b=t.childNodes[1],u=t.childNodes[2],v=t.childNodes[3],w=t.childNodes[4];a.setAttribute("x",d),a.setAttribute("y",e),b.setAttribute("x",d+l),b.setAttribute("y",e+m),b.innerHTML=j,u.setAttribute("x",d+l),u.setAttribute("y",e+n),u.setAttribute("fill",g.fill),u.setAttribute("stroke",g.stroke),v.setAttribute("x",d+(2*l+k)),v.setAttribute("y",e+n),v.innerHTML=f,w.setAttribute("x",d+l),w.setAttribute("y",e+o),w.innerHTML=h,q=1*u.getAttribute("width")+l+v.getBoundingClientRect().width,r=w.getBoundingClientRect().width,p=(q>r?q:r)+2*l,a.setAttribute("width",p),(0>d||d+p>c.getWidth())&&(d=c.getWidth()-p,a.setAttribute("x",d),b.setAttribute("x",d+l),u.setAttribute("x",d+l),v.setAttribute("x",d+(2*l+k)),w.setAttribute("x",d+l)),(0>e||e+s>c.getHeight())&&(e=c.getHeight()-s,a.setAttribute("y",e),b.setAttribute("y",e+m),u.setAttribute("y",e+n),v.setAttribute("y",e+n),w.setAttribute("y",e+o))}},liteChart.prototype.hideTooltip=function(a,b){let c=a.clientX,d=a.clientY;if(c!=b.eventCoord.x||d!=b.eventCoord.y){b.eventCoord.x=c,b.eventCoord.y=d;let a=b.tooltip.object;if(null!=a){let c=b.getWidth()+10,d=b.getHeight()+10,e=null;for(let b=0;b<a.childNodes.length;b++)e=a.childNodes[b],e.setAttribute("x",c),e.setAttribute("y",d)}}},liteChart.prototype.inject=function(a){a.appendChild(this.panel);let b=this,c=this.panel;c.style.width=a.clientWidth,c.style.height=a.clientHeight,window.addEventListener("resize",function(){c.style.width=a.clientWidth,c.style.height=a.clientHeight,b.tooltip.object=null,b.draw(!1)})},liteChart.prototype.restartAnimation=function(){let a=this.panel.getElementsByTagName("animate");for(let b=0;b<a.length;b++)a[b].beginElement()},liteChart.prototype.draw=function(a){for(null==a&&(a=!0);this.panel.firstChild;)this.panel.removeChild(this.panel.firstChild),this.tooltip.object=null;let b=function(a,b,c,d,e,f,g,h){let j=null==h?1:h,k=createElement("line",{id:a,x1:b.toFixed(0),y1:c.toFixed(0),x2:d.toFixed(0),y2:e.toFixed(0),stroke:g,"stroke-width":j});return k},c=function(a,b,c,d,e,f){path=getPath(a,c),-1!==b.indexOf("area")&&(first=c[Object.keys(c)[0]],path=path+" V"+(v-65)+" H"+first.x1.toFixed(0)+" L "+first.x1.toFixed(0)+" "+first.y1.toFixed(0),e=0);let g=null==f?"transparent":f,h=createElement("path",{id:b,d:path,fill:g,stroke:d,"stroke-width":e});return h},d=function(a,b,c,d,e,f,g){let h=createElement("rect",{id:a,x:b,y:c,width:d,height:e,fill:f,stroke:g});return h},e=function(a,b,c,d,e,f,g){let h=createElement("circle",{id:a,cx:b,cy:c,r:d,fill:e,stroke:f,"stroke-width":g});return h},f=function(a,b){let c=createElement("linearGradient",{id:a,x1:"0%",y1:"0%",x2:"0%",y2:"100%"}),d=createElement("stop",{offset:"0%","stop-color":b,"stop-opacity":"0.1"}),e=createElement("stop",{offset:"100%","stop-color":b,"stop-opacity":"0"});return c.appendChild(d),c.appendChild(e),c},g=function(a,c,d,e,f){let h=document.createElementNS("http://www.w3.org/2000/svg","g");path=getPath(a,e);let g=createElement("path",{id:c,d:path,fill:"transparent",stroke:d,opacity:"0.5","stroke-width":a.line.width,filter:"url(#"+c+")"}),b=createElement("defs"),k=createElement("filter",{id:c,y:0,x:0}),l=createElement("feOffset",{result:"offOut",in:"SourceGraphic",dx:0,dy:7}),m=createElement("feGaussianBlur",{stdDeviation:5,in:"offOut"}),n=createElement("feBlend",{in:"SourceGraphic",in2:"blurOut",mode:"normal"});return h.appendChild(b),h.appendChild(g),a.animate.show&&(animation=j(a,g,f),g.appendChild(animation)),b.appendChild(k),k.appendChild(l),k.appendChild(m),k.appendChild(n),h},h=function(a,b,c,d,e){let f=createElement("animate",{attributeName:a,from:b,to:c,dur:d,fill:e});return f},j=function(a,b,c){return lineD0=getPath(a,c),lineD1=b.getAttribute("d"),b.setAttribute("d",lineD0),animation=h("d",lineD0,lineD1,a.animate.duration,"freeze"),animation},k=function(a){var b=/B(?=(d{3})+(?!d))/g;return a.toString().replace(b,",")},l=function(a){let b=0;if(!a.gridX.label.show)return;let c=a.labels.fontSize/3,d=null,e=null,f=0,g=0;return"Line"==a.type&&(d=createText("tempTextForCalculateWidth",0,0,a.labels.fontSize,"end","middle",a.labels.fontColor,k(a.getMaxValue())),a.panel.appendChild(d),f=d.getBoundingClientRect().width,e=createText("tempTextForCalculateWidth",0,0,a.labels.fontSize,"end","middle",a.labels.fontColor,k(a.getMinValue())),a.panel.appendChild(e),g=e.getBoundingClientRect().width,f=f>g?f:g,a.panel.removeChild(d),a.panel.removeChild(e)),b=c+f+10+c,b},m=function(a){let b=0;if(a.labels.show){let c=a.labels.fontSize/2;b=c+a.labels.fontSize+c}return b},n=function(a){let b=a.axisY.minValue,c=a.getMinValue();return 0==b&&0>c&&(b=c),b},o=function(a){let b=a.axisY.maxValue,c=a.getMaxValue();return 0==b&&0<c&&(b=c),b},p=function(a){let b=a.axisX.minValue,c=a.getMinValue();return 0==b&&0>c&&(b=c),b},q=function(a){let b=a.axisX.maxValue,c=a.getMaxValue();return 0==b&&0<c&&(b=c),b},r=function(a){let b=o(a)-n(a),c=a.getHeight()-a.padding.top-a.padding.bottom-m(a);return c/b},s=function(a){let b=q(a)-p(a),c=a.getWidth()-a.padding.left-a.padding.right-l(a);return c/b},t=function(a){let b=a.getHeight()-a.padding.bottom-m(a),c=o(a),d=n(a);return 0>c?b=a.padding.top:0>d&&(b=a.padding.top+c*r(a)),b},u=this.getWidth(),v=this.getHeight(),w=this.padding.top,x=this.padding.bottom+m(this),z=this.padding.left+l(this),A=this.padding.right,B=u-z-A,C=v-w-x,D=function(a){if(!a.axisX.show)return;let c=t(a),d=a.padding.left+l(a)-5,e=a.getWidth()-a.padding.right,f=b(a.id+"-axis-x",d,c,e,c,a.axisX.color,a.axisX.color,a.axisX.width);return a.isIE||f.classList.add("axis-x"),f},E=function(a){if(!a.axisY.show)return;let c=z,d=a.padding.top,e=a.getHeight()-a.padding.bottom-m(a)+5,f=b(a.id+"-axis-y",c,d,c,e,a.axisY.color,a.axisY.color,a.axisY.width);return a.isIE||f.classList.add("axis-y"),f};"Line"==this.type&&(function(a){if(!a.gridX.show)return;let b=n(a),c=o(a),d=a.gridX.interval;if(0==d){let a=Math.round((c-b)/5),e=(""+a).length,f=Math.pow(10,e-1);d=Math.floor(a/f)*f}let e=Math.ceil(b/d)*d,f=e,h=0,j=0,l=null,p=null,q=a.labels.fontSize,s=a.labels.fontFamily,t=a.labels.fontWeight,v=document.createElementNS("http://www.w3.org/2000/svg","g");for(a.panel.appendChild(v);f<=c;){if(f<b){f+=d;continue}h=a.getHeight()-a.padding.bottom-m(a)-(f-b)*r(a),l=createElement("line",{id:a.id+"-grid-x-"+j,x1:z-5,y1:h,x2:u-A,y2:h,stroke:a.gridX.stroke,"stroke-width":a.gridX.width,"stroke-dasharray":a.gridX.dasharray,"stroke-linecap":a.gridX.linecap}),a.isIE||(l.classList.add("grid"),l.classList.add("grid-x")),v.appendChild(l),val=k(f),a.axisX.value&&(val+=" "+a.axisX.value),a.gridX.label.show&&h>=q/2&&(id=a.id+"-grid-x-"+j+"-label",p=createText(id,z-10,h,q,"end","middle",a.labels.fontColor,val),!a.isIE&&p.classList.add("label"),v.appendChild(p)),f+=d,++j}}(this),function(a){if(!a.gridY.show)return;let b=a.labels.list.length,c=2*1+1,d=B/(c*b+1),e=null,f=0,h=a.padding.top,j=a.padding.top+C+5,k=document.createElementNS("http://www.w3.org/2000/svg","g");a.panel.appendChild(k);for(let g=0;g<b;g++)f=z+c*d/2+c*d*g+d/2,e=createElement("line",{id:a.id+"-grid-y-"+g,x1:f,y1:h,x2:f,y2:j,stroke:a.gridY.stroke,"stroke-width":a.gridY.width,"stroke-dasharray":a.gridY.dasharray,"stroke-linecap":a.gridY.linecap}),a.isIE||(e.classList.add("grid"),e.classList.add("grid-y")),k.appendChild(e)}(this),function(a){if(!a.labels.show)return;let b=a.labels.list.length,c=1,d=2*c+1,e=0;e=B/(d*b+1);let f=0,h=a.labels.list,j="",k="",l=0,m=0;l=0,m=a.padding.top+C+a.labels.fontSize/2,j="middle",k="hanging";let n=document.createElementNS("http://www.w3.org/2000/svg","g");a.isIE||n.classList.add("labels"),a.panel.appendChild(n),h.forEach(function(b){l=z+(d*f+c+1)*e,val=b,a.axisY.value&&(val+=" "+a.axisY.value),b=createText(a.id+"-label-"+f,l,m,a.labels.fontSize,j,k,a.labels.fontColor,val),a.isIE||b.classList.add("label"),n.appendChild(b),++f})}(this),function(a){let b=document.createElementNS("http://www.w3.org/2000/svg","g");a.isIE||b.classList.add("axes"),a.panel.appendChild(b),b.appendChild(D(a)),b.appendChild(E(a))}(this),function(a){if(null==a.labels.list)return;let b=a.labels.list.length,d=3,e=B/(d*b+1),h=0;a.legends.list.forEach(function(k){let l=0,m=0,o=0,p=0,q=null,s=0,u=null,v=null;var w=[],x=[];if(k.values.forEach(function(c){var f=0;if(b>l){if(o=z+e/2+d*e/2+d*e*l,s=a.padding.top+C-(c-n(a))*r(a),null!=q&&s>=a.padding.top-.1&&s<=a.padding.top+C+.1){a.id+"-line-"+h+"-"+l;var g={x1:m,y1:q,cx1:(m+o)/2,cy1:q,x2:o,y2:s,cx2:(m+o)/2,cy2:s};if(w.push(g),a.animate.show){var j={x1:m,y1:t(a),cx1:(m+o)/2,cy1:t(a),x2:o,y2:t(a),cx2:(m+o)/2,cy2:t(a)};x.push(j)}}m=o,p=q,q=s,++l}f++}),u=c(a,"line-"+h,w,k.stroke,a.line.width,"transparent"),null!==a.line.dasharray&&u.setAttribute("stroke-dasharray",a.line.dasharray),a.isIE||(u.classList.add("line"),u.classList.add("line-"+h)),a.animate.show&&(v=j(a,u,x),u.appendChild(v)),a.panel.appendChild(u),"gradient"===a.fill||"origin"===a.fill){let b=document.createElementNS("http://www.w3.org/2000/svg","g");a.panel.appendChild(b),"gradient"===a.fill&&(linear=f(k.stroke,k.stroke),b.appendChild(linear)),fill="origin"===a.fill?k.stroke:"url(#"+k.stroke+")",grad=c(a,"area-"+h,w,k.stroke,a.line.width,fill),a.isIE||(grad.classList.add("gradient"),grad.classList.add("gradient-"+h)),a.animate.show&&(grads=c(a,"area-"+h,w,k.stroke,a.line.width,fill),v=j(a,grads,x),grad.appendChild(v)),b.appendChild(grad)}!0==a.line.shadow&&(blur=g(a,"elem-"+h+"-blur",k.stroke,w,x),a.panel.appendChild(blur)),++h})}(this),function(a){if(null==a.labels.list)return;let b=a.labels.list.length,c=3,d=B/(c*b+1),f="",j=0;a.legends.list.forEach(function(l){let m=0,o=0,p=0,q=null,s=null,u=0,v=a.padding.top+C-a.labels.fontSize/3,w=document.createElementNS("http://www.w3.org/2000/svg","g");a.panel.appendChild(w),l.values.forEach(function(g){b>m&&(o=z+d/2+c*d/2+c*d*m,p=a.padding.top+C-(g-n(a))*r(a),a.point.show&&p>=a.padding.top-.1&&p<=a.padding.top+C+.1&&(f=a.id+"-line-point-"+j+"-"+m,stroke=null===a.point.stroke?l.stroke:a.point.stroke,q=e(f,o,p,a.point.radius,l.stroke,stroke,a.point.strokeWidth),q.style.cursor="pointer",!a.isIE&&q.classList.add("point"),a.animate.show&&(q.setAttribute("cy",t(a)),pointMove=h("cy",t(a),p,a.animate.duration,"freeze"),q.appendChild(pointMove),q.setAttribute("r",0),pointMove=h("r",0,a.point.radius,a.animate.duration,"freeze"),q.appendChild(pointMove)),w.appendChild(q),a.tooltip.show&&(q.setAttribute("legend",l.name),q.setAttribute("value",k(g)),q.setAttribute("label",a.labels.list[m]),q.addEventListener("mouseover",function(b){a.showTooltip(b,this,a)}),q.addEventListener("mousemove",function(b){a.showTooltip(b,this,a)}),q.addEventListener("mouseout",function(b){a.hideTooltip(b,a)}))),a.valueOnliteChart.show&&(f=a.id+"-line-"+j+"-"+m+"-value",u=p-a.point.radius-a.labels.fontSize/3,u=v<u?v:u,u>a.labels.fontSize&&(s=createText(f,o,u,a.labels.fontSize,"middle","baseline",a.labels.fontColor,k(g)),!a.isIE&&(s.classList.add("line-value"),s.classList.add("line-value-"+j)),a.animate.show&&(s.setAttribute("y",t(a)),pointMove=h("y",t(a),u,a.animate.duration,"freeze"),s.appendChild(pointMove),s.setAttribute("font-size",0),pointMove=h("font-size",0,a.labels.fontSize,a.animate.duration,"freeze"),s.appendChild(pointMove)),w.appendChild(s))),++m)}),++j})}(this),function(a){if(!a.legends.table.show)return;let c=a.legends.table.position.x,e=!1,f=!1;"center"==c?(e=!0,c=0):"right"==c&&(f=!0,c=0);let h=a.legends.table.position.y,j=null,k=null,l=0,m=0,n=0,o=.5*a.labels.fontSize,p=0,q=0,r=0,s=[];c+=o;let t=a.panel,u=a.labels,v=a.legends.table,w=document.createElementNS("http://www.w3.org/2000/svg","g");if(a.isIE||w.classList.add("legends"),t.appendChild(w),a.legends.list.forEach(function(e){"vertical"==v.direction?(m=h+o+3*o*l,j=d(id+"-mark-"+l,c,m,u.fontSize,u.fontSize,e.fill,e.stroke),w.appendChild(j),s.push(j),k=createText(id+"-text-"+l,c+o+u.fontSize,m,u.fontSize,"start","hanging",v.fontColor,e.name),w.appendChild(k),s.push(k),!a.isIE&&k.classList.add("legend"),p=o+u.fontSize+o+k.getBoundingClientRect().width,q=q>p?q:p,r+=o+u.fontSize):"horizontal"==v.direction&&(m=h+o+3*o*n,j=b(id+"-mark-"+l,c,m+6,c+12,m+6,e.fill,e.stroke,4),w.appendChild(j),s.push(j),c+=u.fontSize+o,k=createText(id+"-text-"+l,c,m,u.fontSize,"start","hanging",v.fontColor,e.name),w.appendChild(k),s.push(k),!a.isIE&&k.classList.add("legend"),c+=k.getBoundingClientRect().width+o,p+=o+u.fontSize+o+k.getBoundingClientRect().width,q=q>p?q:p,r=(o+u.fontSize)*(1+n)),++l}),e){let b=(a.getWidth()-q-o)/2;i=0,s.forEach(function(a){if("line"===a.nodeName){let c=1*a.getAttribute("x1")+b+i,d=1*a.getAttribute("x2")+b+i;a.setAttribute("x1",Math.round(c)),a.setAttribute("x2",Math.round(d))}else if("text"===a.nodeName){let c=1*a.getAttribute("x");a.setAttribute("x",c+b+i),i+=20}})}else if(f){let b=a.getWidth()-q-2*o;s.forEach(function(a){let c=1*a.getAttribute("x");a.setAttribute("x",c+b)})}}(this)),a&&this.restartAnimation(this)};
?>
Онлайн: 2
Реклама