zingchart
Version:
Our JavaScript charting library is a commercial product. But the full branded version is free to try, forever.
8 lines (7 loc) • 7.24 kB
JavaScript
/*
All of the code within the ZingChart software is developed and copyrighted by ZingChart, Inc., and may not be copied,
replicated, or used in any other software or application without prior permission from ZingChart. All usage must coincide with the
ZingChart End User License Agreement which can be requested by email at support@zingchart.com.
Build 2.9.16-hf1_ES6
*/
zingchart.setModule("zoom-buttons"),function(){var t,e,a={labels:["Zoom","From","To"],"adjust-layout":!0,style:{label:{"font-weight":"bold",color:"#000"},date:{width:100,height:20,"font-size":11,"border-width":1,"border-color":"#ccc"},button:{"data-active":!1,padding:3,"border-radius":3,"background-color":"#ddd","font-weight":"normal",color:"#000",shadow:!1,width:30,margin:5,"z-index":0,"hover-state":{"background-color":"#eee","font-weight":"normal",shadow:!0},"selected-state":{"z-index":1,"data-active":!0,"background-color":"#333",color:"#fff","font-weight":600,shadow:!0}}},buttons:[{text:"1m",type:"month",count:1},{text:"3m",type:"month",count:3},{text:"6m",type:"month",count:6},{text:"1y",type:"year",count:1},{type:"ytd",text:"YTD"},{type:"all",text:"All"}]},o=[],i=null,d=!1,n={},l={},r={},c={},m={};zingchart.bind(null,"dataparse",function(i,d){var u,h=zingchart.getLoader(i.id),b=zingchart.getModules(h);if(-1!==ZC.AV(b,"zoom-buttons")){o=[].concat(a.buttons);for(var p=0,_=d[ZC._[16]].length;p<_;p++){var s=zingchart.getGraphInfo(h,d,p),z=d[ZC._[16]][p];z[ZC._[10]]=z[ZC._[10]]||[];var g={};if(ZC._cp_(a,g),z.options){var Z=z.options["zoom-buttons"]||z.options;zingchart.normalize(Z),ZC._cp_(Z,g)}var C=s.graph.x+ZC._i_(g.x||20),f=s.graph.y+ZC._i_(g.y||10);for(g["adjust-layout"]&&(C=s.plotarea.x,f=s.plotarea.y-30),l[i.id]={},r[i.id]=!1,c[i.id]=[],m[i.id]=[],ZC._cp_(a.style,l[i.id]),g.style&&ZC._cp_(g.style,l[i.id]),g.buttons&&(o=[].concat(g.buttons)),u=0;u<o.length;u++){var x=o[u].type||"all",y=ZC._i_(o[u].count||1);switch(x){case"ytd":case"all":o[u].diff=-1;break;case"year":o[u].diff=ZC.YR*y;break;case"month":o[u].diff=ZC.MON*y;break;case"week":o[u].diff=7*ZC.DAY*y;break;case"day":o[u].diff=ZC.DAY*y;break;case"hour":o[u].diff=ZC.HR*y;break;case"minute":o[u].diff=ZC.MIN*y}o[u].text=o[u].text||y+o[u].type}for(u=z[ZC._[10]].length-1;u>=0;u--)z[ZC._[10]][u]["data-zoom-item"]&&z[ZC._[10]].splice(u,1);t=null!==ZC._n_(l[i.id].button[ZC._[19]])?ZC._i_(l[i.id].button[ZC._[19]]):30,e=null!==ZC._n_(l[i.id].button.margin)?ZC._i_(l[i.id].button.margin):5,n[i.id]={},n[i.id].iDateWidth=null!==ZC._n_(l[i.id].date[ZC._[19]])?ZC._i_(l[i.id].date[ZC._[19]]):100,n[i.id].iDateHeight=null!==ZC._n_(l[i.id].date[ZC._[20]])?ZC._i_(l[i.id].date[ZC._[20]]):20,n[i.id].iDateFontSize=null!==ZC._n_(l[i.id].date["font-size"])?ZC._i_(l[i.id].date["font-size"]):11,n[i.id].iDateBorderWidth=null!==ZC._n_(l[i.id].date[ZC._[62]])?ZC._i_(l[i.id].date[ZC._[62]]):1;var v=zingchart.getInstance(h,"textbox"),k=C,D={id:"zoomLabelZoom","data-zoom-item":!0,cls:"zoomLabel",flat:!0,x:C,y:f,text:g[ZC._[10]][0]||"Zoom"};for(ZC._cp_(l[i.id].label,D),v.o=D,v.parse(),z[ZC._[10]].push(D),k+=v.I+e,u=0;u<o.length;u++){var L=o[u].text||" ",w={id:"zoomLink"+u,"data-zoom-item":!0,"data-zoom-type":o[u].type,"data-zoom-diff":o[u].diff,cls:"zoomLink",x:k,y:f,width:t,text:L};ZC._cp_(l[i.id].button,w),z[ZC._[10]].push(w),k+=t+e}var A={id:"zoomLabelFrom","data-zoom-item":!0,cls:"zoomLabel",flat:!0,x:k+=t+e+30,y:f,text:g[ZC._[10]][1]||"From"};ZC._cp_(l[i.id].label,A),v.o=A,v.parse(),z[ZC._[10]].push(A);var V={id:"zoomLabelFromDate","data-zoom-item":!0,cls:"zoomLabel",x:k+=v.I+e,y:f,width:100,text:" "};ZC._cp_(l[i.id].date,V),z[ZC._[10]].push(V);var F={id:"zoomLabelTo","data-zoom-item":!0,cls:"zoomLabel",flat:!0,x:k+=n[i.id].iDateWidth+2*e,y:f,text:g[ZC._[10]][2]||"To"};ZC._cp_(l[i.id].label,F),v.o=F,v.parse(),z[ZC._[10]].push(F);var j={id:"zoomLabelToDate","data-zoom-item":!0,cls:"zoomLabel",x:k+=v.I+e,y:f,width:100,text:" "};ZC._cp_(l[i.id].date,j),z[ZC._[10]].push(j)}}return d});var u=function(t){var e=zingchart.exec(t.id,"getobjectinfo",{object:"scale",graphid:t.graphid,name:ZC._[50]});return e||(e=zingchart.exec(t.id,"getobjectinfo",{object:"scale",graphid:t.graphid,name:ZC._[50]})),e},h=function(t){var e=ZC.AP.Z0(c[t.id][0],"%M %d, %Y"),a=ZC.AP.Z0(c[t.id][1],"%M %d, %Y");zingchart.exec(t.id,"updateobject",{type:"label",data:[{id:"zoomLabelFromDate",text:e},{id:"zoomLabelToDate",text:a}]})},b=function(t){if(i){i=null;var e=ZC.AN(t);if(e){var a=e.getAttribute("data-chartid"),o=e.getAttribute("data-graphid"),d=e.value.split(/\-|\:/),n=-1;3===d.length&&(n=new Date(ZC._i_(d[0]),ZC._i_(d[1])-1,ZC._i_(d[2]),0,0,0).getTime()),-1!==n&&("zoomLabelFromDate"===e.id?n>m[a][0]&&n<m[a][1]&&(c[a][0]=n):n>m[a][0]&&n<m[a][1]&&(c[a][1]=n)),e.parentNode.removeChild(e),zingchart.exec(a,"zoomto",{kmin:c[a][0],kmax:c[a][1],graphid:o})}}};zingchart.bind(null,"complete",function(t){var e=zingchart.getLoader(t.id),a=zingchart.getModules(e);if(-1!==ZC.AV(a,"zoom-buttons")){d||(ZC.A4(document).bind(ZC._[47],function(t){"zoomLabelFromDate"!==t.target.id&&"zoomLabelToDate"!==t.target.id&&b(i)}),ZC.A4(".zoomInput").live("blur keydown",function(t){t.keyCode&&13!==t.keyCode||b(i)}),d=!0);var o=u(t);if(!o)return;c[t.id]=[o.minValue,o.maxValue],m[t.id]=[o.minValue,o.maxValue],h(t)}}),zingchart.bind(null,"zoom",function(t){var e=zingchart.getLoader(t.id),a=zingchart.getModules(e);if(-1!==ZC.AV(a,"zoom-buttons")){if(t.kmin&&t.kmax)c[t.id]=[t.kmin,t.kmax];else{var o=u(t);if(!o)return;c[t.id]=[o.minValue_,o.maxValue_]}h(t),t.zoomButtons||r[t.id]&&(r[t.id]=!1,zingchart.exec(t.id,"updateobject",{type:"label",cls:"zoomLink",data:l[t.id].button}))}}),zingchart.bind(null,"label_click",function(t){var e=zingchart.getLoader(t.id),a=zingchart.getModules(e);if(-1!==ZC.AV(a,"zoom-buttons")){var o=u(t);if(!o)return;if(r[t.id]=!0,t["data-zoom-type"])if("all"===t["data-zoom-type"])zingchart.exec(t.id,"viewall",{graphid:t.graphid,zoomButtons:!0});else if("ytd"===t["data-zoom-type"]){var d=new Date(o.maxValue_).getFullYear(),m=new Date(d+"-01-01 00:00:00").getTime();zingchart.exec(t.id,"zoomto",{kmin:m,kmax:o.maxValue_,graphid:t.graphid,zoomButtons:!0})}else zingchart.exec(t.id,"zoomto",{kmin:o.maxValue-t["data-zoom-diff"],kmax:o.maxValue,graphid:t.graphid,zoomButtons:!0});if("zoomLabelFromDate"===t.labelid||"zoomLabelToDate"===t.labelid){var h=ZC.A4("#"+t.id+"-top"),b=ZC.Q.F8("input");ZC.Q.G8(b,{type:"text",id:t.labelid,"class":"zoomInput","data-chartid":t.id,"data-graphid":t.graphid}),ZC.Q.P9(b,{"font-size":n[t.id].iDateFontSize+"px","text-align":"center",height:n[t.id].iDateHeight-2*n[t.id].iDateBorderWidth-2+"px",width:n[t.id].iDateWidth-2*n[t.id].iDateBorderWidth-2+"px",position:"absolute",border:"0px solid #ccc",padding:"1px","border-radius":"0px","box-shadow":"none",display:"block",color:"#000",left:h.offset().left+t.label.x+n[t.id].iDateBorderWidth+"px",top:h.offset().top+t.label.y+n[t.id].iDateBorderWidth+"px"}),document.body.appendChild(b),b.value=ZC.AP.Z0("zoomLabelFromDate"===t.labelid?c[t.id][0]:c[t.id][1],"%Y-%mm-%dd"),b.focus(),i=t.labelid}else zingchart.exec(t.id,"updateobject",{type:"label",cls:"zoomLink",data:l[t.id].button,update:!1}),zingchart.exec(t.id,"updateobject",{type:"label",id:t.labelid,data:l[t.id].button[ZC._[73]]||{}})}})}();