UNPKG

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.19 kB
/* 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.11 */ 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,l={},n={},r={},c={},m={};zingchart.bind(null,"dataparse",function(i,d){var s,b=zingchart.getLoader(i.id),h=zingchart.getModules(b);if(-1!==ZC.AV(h,"zoom-buttons")){o=[].concat(a.buttons);for(var u=0,p=d.graphset.length;u<p;u++){var g=zingchart.getGraphInfo(b,d,u),z=d.graphset[u];z.labels=z.labels||[];var f={};if(ZC._cp_(a,f),z.options){var x=z.options["zoom-buttons"]||z.options;zingchart.normalize(x),ZC._cp_(x,f)}var _=g.graph.x+ZC._i_(f.x||20),C=g.graph.y+ZC._i_(f.y||10);for(f["adjust-layout"]&&(_=g.plotarea.x,C=g.plotarea.y-30),n[i.id]={},r[i.id]=!1,c[i.id]=[],m[i.id]=[],ZC._cp_(a.style,n[i.id]),f.style&&ZC._cp_(f.style,n[i.id]),f.buttons&&(o=[].concat(f.buttons)),s=0;s<o.length;s++){var Z=o[s].type||"all",y=ZC._i_(o[s].count||1);switch(Z){case"ytd":case"all":o[s].diff=-1;break;case"year":o[s].diff=ZC.YR*y;break;case"month":o[s].diff=ZC.MON*y;break;case"week":o[s].diff=7*ZC.DAY*y;break;case"day":o[s].diff=ZC.DAY*y;break;case"hour":o[s].diff=ZC.HR*y;break;case"minute":o[s].diff=ZC.MIN*y}o[s].text=o[s].text||y+o[s].type}for(s=z.labels.length-1;s>=0;s--)z.labels[s]["data-zoom-item"]&&z.labels.splice(s,1);t=null!==ZC._n_(n[i.id].button.width)?ZC._i_(n[i.id].button.width):30,e=null!==ZC._n_(n[i.id].button.margin)?ZC._i_(n[i.id].button.margin):5,l[i.id]={},l[i.id].iDateWidth=null!==ZC._n_(n[i.id].date.width)?ZC._i_(n[i.id].date.width):100,l[i.id].iDateHeight=null!==ZC._n_(n[i.id].date.height)?ZC._i_(n[i.id].date.height):20,l[i.id].iDateFontSize=null!==ZC._n_(n[i.id].date["font-size"])?ZC._i_(n[i.id].date["font-size"]):11,l[i.id].iDateBorderWidth=null!==ZC._n_(n[i.id].date["border-width"])?ZC._i_(n[i.id].date["border-width"]):1;var v=zingchart.getInstance(b,"textbox"),k=_,w={id:"zoomLabelZoom","data-zoom-item":!0,cls:"zoomLabel",flat:!0,x:_,y:C,text:f.labels[0]||"Zoom"};for(ZC._cp_(n[i.id].label,w),v.o=w,v.parse(),z.labels.push(w),k+=v.I+e,s=0;s<o.length;s++){var D=o[s].text||" ",L={id:"zoomLink"+s,"data-zoom-item":!0,"data-zoom-type":o[s].type,"data-zoom-diff":o[s].diff,cls:"zoomLink",x:k,y:C,width:t,text:D};ZC._cp_(n[i.id].button,L),z.labels.push(L),k+=t+e}var A={id:"zoomLabelFrom","data-zoom-item":!0,cls:"zoomLabel",flat:!0,x:k+=t+e+30,y:C,text:f.labels[1]||"From"};ZC._cp_(n[i.id].label,A),v.o=A,v.parse(),z.labels.push(A);var V={id:"zoomLabelFromDate","data-zoom-item":!0,cls:"zoomLabel",x:k+=v.I+e,y:C,width:100,text:" "};ZC._cp_(n[i.id].date,V),z.labels.push(V);var F={id:"zoomLabelTo","data-zoom-item":!0,cls:"zoomLabel",flat:!0,x:k+=l[i.id].iDateWidth+2*e,y:C,text:f.labels[2]||"To"};ZC._cp_(n[i.id].label,F),v.o=F,v.parse(),z.labels.push(F);var Y={id:"zoomLabelToDate","data-zoom-item":!0,cls:"zoomLabel",x:k+=v.I+e,y:C,width:100,text:" "};ZC._cp_(n[i.id].date,Y),z.labels.push(Y)}}return d});var s=function(t){var e=zingchart.exec(t.id,"getobjectinfo",{object:"scale",graphid:t.graphid,name:"scale-x"});return e||(e=zingchart.exec(t.id,"getobjectinfo",{object:"scale",graphid:t.graphid,name:"scale-x"})),e},b=function(t){var e=ZC.AQ.YE(c[t.id][0],"%M %d, %Y"),a=ZC.AQ.YE(c[t.id][1],"%M %d, %Y");zingchart.exec(t.id,"updateobject",{type:"label",data:[{id:"zoomLabelFromDate",text:e},{id:"zoomLabelToDate",text:a}]})},h=function(t){if(i){i=null;var e=ZC.AL(t);if(e){var a=e.getAttribute("data-chartid"),o=e.getAttribute("data-graphid"),d=e.value.split(/\-|\:/),l=-1;3===d.length&&(l=new Date(ZC._i_(d[0]),ZC._i_(d[1])-1,ZC._i_(d[2]),0,0,0).getTime()),-1!==l&&("zoomLabelFromDate"===e.id?l>m[a][0]&&l<m[a][1]&&(c[a][0]=l):l>m[a][0]&&l<m[a][1]&&(c[a][1]=l)),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.A5(document).bind("mousedown",function(t){"zoomLabelFromDate"!==t.target.id&&"zoomLabelToDate"!==t.target.id&&h(i)}),ZC.A5(".zoomInput").live("blur keydown",function(t){t.keyCode&&13!==t.keyCode||h(i)}),d=!0);var o=s(t);if(!o)return;c[t.id]=[o.minValue,o.maxValue],m[t.id]=[o.minValue,o.maxValue],b(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=s(t);if(!o)return;c[t.id]=[o.minValue_,o.maxValue_]}b(t),t.zoomButtons||r[t.id]&&(r[t.id]=!1,zingchart.exec(t.id,"updateobject",{type:"label",cls:"zoomLink",data:n[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=s(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 b=ZC.A5("#"+t.id+"-top"),h=ZC.Q.F7("input");ZC.Q.G5(h,{type:"text",id:t.labelid,"class":"zoomInput","data-chartid":t.id,"data-graphid":t.graphid}),ZC.Q.PL(h,{"font-size":l[t.id].iDateFontSize+"px","text-align":"center",height:l[t.id].iDateHeight-2*l[t.id].iDateBorderWidth-2+"px",width:l[t.id].iDateWidth-2*l[t.id].iDateBorderWidth-2+"px",position:"absolute",border:"0px solid #ccc",padding:"1px","border-radius":"0px","box-shadow":"none",display:"block",color:"#000",left:b.offset().left+t.label.x+l[t.id].iDateBorderWidth+"px",top:b.offset().top+t.label.y+l[t.id].iDateBorderWidth+"px"}),document.body.appendChild(h),h.value=ZC.AQ.YE("zoomLabelFromDate"===t.labelid?c[t.id][0]:c[t.id][1],"%Y-%mm-%dd"),h.focus(),i=t.labelid}else zingchart.exec(t.id,"updateobject",{type:"label",cls:"zoomLink",data:n[t.id].button,update:!1}),zingchart.exec(t.id,"updateobject",{type:"label",id:t.labelid,data:n[t.id].button["selected-state"]||{}})}})}();