zingchart
Version:
Our JavaScript charting library is a commercial product. But the full branded version is free to try, forever.
8 lines (7 loc) • 14 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.11
*/
ZC.A87={},ZC.WG.push("export"),ZC.AQ.A3W=function(e,t,a,n){"jpg"===(n=n||"png")&&(n="jpeg");var o=document.createElement("canvas");o.width=t,o.height=a,o.style.width=t+"px",o.style.height=a+"px";var r,i=o.getContext("2d");e instanceof Array||(e=[e]);for(var l=0,s=e.length;l<s;l++)if(-1===e[l].className.indexOf("zc-no-print")){var c=!1;try{e[l].toDataURL("image/"+n)}catch(p){c=!0}if(!c)if(r=e[l].getAttribute("data-clip")){var d=r.split(",");i.drawImage(e[l],ZC.BQ(0,d[0]),ZC.BQ(0,d[1]),ZC.CY(d[2],e[l].width),ZC.CY(d[3],e[l].height),ZC.BQ(0,d[0]),ZC.BQ(0,d[1]),ZC.CY(d[2],e[l].width),ZC.CY(d[3],e[l].height))}else i.drawImage(e[l],0,0,e[l].width,e[l].height,0,0,t,a)}return o.toDataURL("image/"+n)},ZC.AQ.ABN=function(e,t,a,n,o){null===ZC._n_(o)&&(o=!1);var r=ZC.AQ.A3W(e,t,a,n);if(o){var i=document.createElement("img");return i.src=r,i}r=r.replace("image/"+n,"image/octet-stream"),document.location.href=r},ZC.Q4.prototype.AA5=function(){var e=this,t=[];if(!e.A7O){e.A7O=!0;var a=document.body.childNodes,n=ZC.A5(document.body).css("background-color"),o=ZC.A5(document.body).css("background-image");ZC.A5(document.body).css("background-color","#fff").css("background-image","none");for(var r=0,i=a.length;r<i;r++)1===a[r].nodeType&&(t[r]=a[r].style.display,a[r].style.display="none");document.body.appendChild(ZC.AL(e.K+"-wrapper")),window.setTimeout(function(){window.print(),window.setTimeout(function(){ZC.A5(document.body).css("background-color",n).css("background-image",o),ZC.AL(e.K+"-wrapper")&&ZC.AL(e.K).appendChild(ZC.AL(e.K+"-wrapper"));for(var r=0,i=a.length;r<i;r++)1===a[r].nodeType&&(a[r].style.display=t[r]);e.A7O=!1},1e3)},50)}},ZC.Q4.prototype.OH=function(e,t,a,n){var o=this;if(t=t||{},void 0===a&&(a=!1),!ZC.AL(o.K+"-viewimage")){e=e||"png";var r=t.download,i=t.fn||"";ZC.Q.IV(ZC.AL(o.K+"-guide-c"),o.AC,0,0,o.I,o.F),ZC.A5(".zc-guide-label").remove();var l,s,c=("canvas"===o.AC||zingchart.AJAXEXPORT||zingchart.DEV.LOCALSVGEXPORT)&&"pdf"!==e&&"svg"!==e;if(ZC.mobile||!c||a||r||(l=ZC.Q.I4({cls:"zc-abs zc-viewimage zc-style",id:o.K+"-viewimage",zidx:5,p:ZC.AL(o.K+"-top"),wh:o.I+"/"+o.F}),s=ZC.Q.I4({id:o.K+"-viewimage-close",p:l,zidx:10,tl:"5/"+(o.I-15),html:ZC.HL["viewimage-close"]}),ZC.A5(s).css("cursor","pointer").css("left",o.I-15-ZC.A5(s).width()+"px"),ZC.A5(s).bind("click",function(){ZC.A5(l).remove()})),ZC.mobile&&(r=!0),!zingchart.DEV.LOCALSVGEXPORT||r||"svg"!==o.AC||"png"!==e&&"jpeg"!==e){var d;if("canvas"===o.AC&&"pdf"!==e&&"svg"!==e){var p,u,h=document.createElement("canvas");for(h.width=o.I,h.height=o.F,p=0,u=o.AG.length;p<u;p++)o.AG[p].BE&&o.AG[p].BE.EM(h);var g=[];ZC.A5("#"+o.K+" canvas").each(function(){-1===ZC.AV([o.K+"-guide-c",o.K+"-trigger-c"],this.id)&&g.push(this)}),g.push(h),g.push(o.createPreviewMasks());var C=ZC.AQ.ABN(g,o.I,o.F,e,!0);C.id=o.K+"-print-"+e,l.appendChild(C)}else if(a||o.A8G(ZC.HL["export-wait"]),"vml"===o.AC||"canvas"===o.AC&&("pdf"===e||"svg"===e)){var m=document.createElement("div"),f="zc-export-svg-"+o.K;m.id=f,m.style.display="none",document.body.appendChild(m),zingchart.render({id:f,output:"!svg",imggen:!0,width:o.I,height:o.F,data:o.E.json,defaults:o.MN,theme:o.LK,hideprogresslogo:!0,events:{load:function(){window.setTimeout(function(){var e=zingchart.getLoader(f);if(e.E["dynamic-objects"])var t=window.setInterval(function(){"ready"===e.E["dynamic-objects"]&&(window.clearInterval(t),e.togglePreviewMasks(!0),d=ZC.AL(f+"-top").innerHTML,e.togglePreviewMasks(!1),zingchart.exec(f,"destroy",{skipfs:!0}),v())},100);else e.togglePreviewMasks(!0),d=ZC.AL(f+"-top").innerHTML,e.togglePreviewMasks(!1),zingchart.exec(f,"destroy",{skipfs:!0}),v()},100)}}})}else"svg"===o.AC&&(o.togglePreviewMasks(!0),d=ZC.AL(o.K+"-top").innerHTML,v(),o.togglePreviewMasks(!1));c&&!a&&(ZC.A5(s).css("cursor","pointer").css("left",o.I-15-ZC.A5(s).width()+"px"),ZC.A5(s).bind("click",function(){ZC.A5(l).remove()}))}else zingchart.exec(o.K,"getimagedata",{callback:function(r){if(-1!==r){var i=document.createElement("img");i.id=o.K+"-print-"+e,i.src=r,l.appendChild(i)}else ZC.Q.EV(o.K+"-viewimage"),zingchart.DEV.LOCALSVGEXPORT=0,o.OH(e,t,a,n)}})}function v(){var s,c,p={svg:d=(d=d.replace(/<foreignObject(.+?)<\/foreignObject>/g,"")).replace(' xmlns="http://www.w3.org/2000/svg"',""),w:o.I,h:o.F,t:e,fn:i};if(ZC._cp_(t,p),zingchart.AJAXEXPORT&&"pdf"!==e&&"svg"!==e&&!r){var u="base64=1&";for(c in p)u+=c+"="+encodeURIComponent(p[c])+"&";ZC.A5.ajax({type:"post",url:zingchart.EXPORTURL,data:u,success:function(t,r,i){if(o.A48(),a)n&&n(t,r,i);else{var s=document.createElement("img");s.src=t,s.id=o.K+"-print-"+e,l.appendChild(s)}}})}else{ZC.AL(o.K+"-export")&&ZC.Q.EV(o.K+"-export");var h=ZC.Q.I4({cls:"zc-abs zc-style",id:o.K+"-export",p:ZC.AL(o.K+"-top"),display:"none"}),g=(s=null!==ZC._n_(p.uid)&&null!==ZC._n_(p.page)?ZC.Q.ABB(ZC.AL(o.K+"-export")):document).createElement("FORM");for(c in g.action=zingchart.EXPORTURL,g.method="post",g.enctype="multipart/form-data",null!==ZC._n_(p.uid)&&null!==ZC._n_(p.page)?s.body.appendChild(g):h.appendChild(g),g.style.display="none",p){var C=s.createElement("INPUT");C.type="hidden",C.name=c,C.value=p[c],g.appendChild(C)}g.submit(),g=null,null!==ZC._n_(p.uid)&&null!==ZC._n_(p.page)&&window.setTimeout(function(){ZC.A5("#"+o.K+"-export").remove()},6e4),window.setTimeout(function(){o.A48()},1e3)}}},ZC.Q4.prototype.Z6=function(e){var t=this;e=e||"png";var a,n,o=[],r=document.createElement("canvas");for(r.width=t.I,r.height=t.F,a=0,n=t.AG.length;a<n;a++)t.AG[a].BE&&t.AG[a].BE.EM(r);return ZC.A5("#"+t.K+" canvas").each(function(){-1===ZC.AV([t.K+"-guide-c",t.K+"-tooltip-c"],this.id)&&o.push(this)}),o.push(r),o.push(t.createPreviewMasks()),ZC.AQ.A3W(o,t.I,t.F,e)},ZC.AQ.downloadFile=function(e,t,a){if(!ZC.ie678){a=a||"application/octet-stream";var n=document.createElement("a");navigator.msSaveBlob?navigator.msSaveBlob(new Blob([e],{type:a}),t):URL&&"download"in n?(n.href=URL.createObjectURL(new Blob([e],{type:a})),n.setAttribute("download",t),document.body.appendChild(n),n.click(),document.body.removeChild(n)):location.href="data:application/octet-stream,"+encodeURIComponent(e)}},ZC.AQ.XW=function(e,t){var a,n,o,r,i,l,s,c,d,p,u,h,g,C=[],m="",f=[];for("xls"===(t=t||"csv")&&C.push('<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',"<head>","\x3c!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>[ZC]</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--\x3e",'<style>td{border:none;font-family:Calibri,sans-serif} .number{mso-number-format:"0.00";} .text{mso-number-format:"@";}</style>',"<meta name=ProgId content=Excel.Sheet>","<meta charset=UTF-8>","</head>","<body>"),a=0,n=e.AG.length;a<n;a++){var v=e.AG[a],A=v.AZ.A3;e.E.fastlinedata&&(A=e.E.fastlinedata);var Z={},w=[],x=v.BW("k")[0];"html"!==t&&"xls"!==t&&"raw"!==t||(C.push("<table>"),v.IR&&""!==v.IR.AM&&(f.push([v.IR.AM]),C.push("<caption>"+v.IR.AM+"</caption>")),C.push("<thead>"),C.push("<tr>")),u=[],g=[];var b="Category",y=!1,k="%Y-%mm-%dd %H:%i:%s";for(x&&(x.F6&&"date"===x.F6.o.type&&(b="Date",y=!0,x.F6.o["export-format"]&&(k=x.F6.o["export-format"])),x.M&&x.M.AM&&(b=x.M.AM.replace(/\"|\'/g,""))),"csv"===t?u.push('"'+b+'"'):"raw"===t?g.push(b):"html"!==t&&"xls"!==t||u.push("<th>"+b+"</th>"),o=0,r=A.length;o<r;o++)(null===ZC._n_(A[o].o["export"])||ZC._b_(A[o].o["export"]))&&(h=(h=null!==ZC._n_(A[o].AM)?A[o].AM+"":"Series "+o).replace(/\"|\'/g,""),"csv"===t?u.push('"'+h+'"'):"raw"===t?g.push(h):"html"!==t&&"xls"!==t||u.push("<th"+("xls"===t?' scope="col" class="text"':"")+">"+h+"</th>"),w.push(""));if("csv"===t?C.push(u.join(",")):"raw"===t?f.push(g):"html"!==t&&"xls"!==t||C.push(u.join("")),"html"!==t&&"xls"!==t||(C.push("</tr>"),C.push("</thead>"),C.push("<tbody>")),x){for(s=0,c=x.V.length;s<c;s++)Z[s+""]={hasData:!1,nodes:[].concat(w)};var _=[];for(o=0,r=A.length;o<r;o++)if(null===ZC._n_(A[o].o["export"])||ZC._b_(A[o].o["export"]))for(i=0,l=A[o].R.length;i<l;i++){var L=A[o].R[i];L&&(Z[s=null!==ZC._n_(L.BV)?""+L.BV:""+i]=Z[s]||{hasData:!0,nodes:[].concat(w)},Z[s].nodes[o]=L.AD,Z[s].hasData=!0,null!==ZC._n_(L.BV)&&_.push(""+L.BV))}var E=[];for(s in Z)Z[s].hasData&&E.push([s,Z[s].nodes]);E.sort(function(e,t){return e[0]-t[0]});var K=null;for(d=0,p=E.length;d<p;d++){if("html"!==t&&"xls"!==t||C.push("<tr>"),"pie"!==v.AF&&"pie3d"!==v.AF&&"nestedpie"!==v.AF||x.V[E[d][0]]&&(E[d][0]=x.V[E[d][0]]),x.BY[E[d][0]]&&(E[d][0]=x.BY[E[d][0]]),x.V[E[d][0]]&&-1===ZC.AV(_,E[d][0])&&(E[d][0]=x.V[E[d][0]]),(K=v.A.FF()).row=d,K.col=0,K.value=E[d][0],E[d][0]=ZC.AQ.C0("dataexport",v.A,K,E[d][0],null),ZC._n_(E[d][1]))for(var R=0;R<E[d][1].length;R++)(K=v.A.FF()).row=d,K.col=R+1,K.value=E[d][1][R],E[d][1][R]=ZC.AQ.C0("dataexport",v.A,K,E[d][1][R],null);y&&(E[d][0]=ZC.AQ.YE(E[d][0],k,v.UF,v.NC),"csv"===t&&(E[d][0]='"'+E[d][0]+'"')),"csv"===t?C.push([].concat(E[d][0]).concat(E[d][1]).join(",")):"raw"===t?f.push([].concat(E[d][0]).concat(E[d][1])):"html"!==t&&"xls"!==t||C.push("<td"+("xls"===t?' scope="row"':"")+">"+[].concat(E[d][0]).concat(E[d][1]).join("</td><td>")+"</td>"),"html"!==t&&"xls"!==t||C.push("</tr>")}}"html"!==t&&"xls"!==t||(C.push("</tbody>"),C.push("</table>")),n>1&&a<n-1&&("csv"===t?C.push("","",""):"html"!==t&&"xls"!==t||C.push("<p> </p>"))}return"xls"===t&&C.push("</body>","</html>"),"raw"===t?f:("csv"===t?m=C.join("\n"):"html"!==t&&"xls"!==t||(m=C.join("")),m)},zingchart.ABD=function(e,t,a){var n,o,r,i,l,s="",c="";function d(e){ZC.A5.ajax({type:"post",url:o,data:e,success:function(e,t,a){r&&r(e,t,a)}})}document.getElementById("zc-fullscreen")&&(e="zc-fullscreen"),"string"==typeof(a=a||{})&&(a=JSON.parse(a));var p=zingchart.getLoader(e);if(p)switch(t){case"getimagedata":if(i="png",null!==ZC._n_(n=a.format)&&(i=n),null!==ZC._n_(n=a.filetype)&&(i=n),"jpg"===i&&(i="jpeg"),zingchart.DEV.LOCALSVGEXPORT&&"svg"===p.AC&&("png"===i||"jpeg"===i)){p.togglePreviewMasks(!0);var u=ZC.AL(p.K+"-svg").parentNode.innerHTML,h=u.indexOf(">"),g=u.indexOf("</svg>");u=(u='<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1" width="'+p.I+'" height="'+p.F+'">[CSS]'+u.substring(h+1,g+6)).replace(/<foreignObject(.+?)<\/foreignObject>/g,"");var C=function(){var e,t=window.URL||window.webkitURL||window,n=!1;navigator&&navigator.userAgent&&-1!==navigator.userAgent.indexOf("Safari")&&-1===navigator.userAgent.indexOf("Chrome")&&(n=!0),e=t.createObjectURL&&window.Blob&&!n?t.createObjectURL(new window.Blob([u],{type:"image/svg+xml;charset-utf-16"})):"data:image/svg+xml;charset=UTF-8,"+encodeURIComponent(u),p.togglePreviewMasks(!1);var o=new window.Image;o.crossOrigin="anonymous",o.src=e,o.onload=function(){var t=document.createElement("canvas"),n=t.getContext("2d");if(t.width=o.width,t.height=o.height,n.drawImage(o,0,0,t.width,t.height),a.callback&&"function"==typeof a.callback)try{a.callback(t.toDataURL("image/"+i))}catch(r){a.callback(e)}}},m=0,f=function(){var e=new XMLHttpRequest;e.open("get",p.A27[m]),e.responseType="text",e.onloadend=function(e){var t=e.target.response,a=t.match(/https?:\/\/[^ \)]+/g),n=0;a.forEach(function(e){var o=new XMLHttpRequest;o.open("get",e),o.responseType="blob",o.onloadend=function(o){var r=new FileReader;r.onloadend=function(o){t=t.replace(new RegExp(e),o.target.result),++n===a.length&&(u=u.replace("[CSS]","[CSS]<style><![CDATA["+t+"]]></style>"),++m===p.A27.length?(u=u.replace("[CSS]",""),C()):f())},r.readAsDataURL(o.target.response)},o.send()})},e.send()};p.A27.length?f():(u=u.replace("[CSS]",""),C())}if("canvas"!==p.AC&&!zingchart.AJAXEXPORT)return-1;if("canvas"===p.AC){if(!a.callback||"function"!=typeof a.callback)return p.Z6(i);try{a.callback(p.Z6(i))}catch(w){a.callback(-1)}}else p.OH(i,{},!0,a.callback);break;case"exportimage":case"saveasimage":if(!a.download&&"canvas"!==p.AC&&!zingchart.AJAXEXPORT)return-1;if(i="png",l={},null!==ZC._n_(n=a.options)&&(l=n),null!==ZC._n_(n=a.uid)&&(l.uid=n),null!==ZC._n_(n=a.page)&&(l.page=n),null!==ZC._n_(n=a.format)&&(i=n),null!==ZC._n_(n=a.filetype)&&(i=n),null!==ZC._n_(n=a.filename)&&(s=n),o=p.E.exportimageurl||"",null!==ZC._n_(n=a.url)&&(o=n),r=null,null!==ZC._n_(n=a.callback)&&(r=n),"jpg"===i&&(i="jpeg"),a.download&&("canvas"!==p.AC||"pdf"===i))return l.download=!0,""!==s&&(l.fn=s),void p.OH(i,l);if(""!==o){if("canvas"===p.AC)return d(p.Z6(i));p.OH(i,l,!0,function(e){return d(e)})}break;case"exportdata":if(o=p.E.exportdataurl||"",null!==ZC._n_(n=a.url)&&(o=n),c=ZC.AQ.XW(p,"csv"),""===o)return c;r=null,null!==ZC._n_(n=a.callback)&&(r=n),ZC.A5.ajax({type:"post",url:o,data:c,success:function(e,t,a){r&&r(e,t,a)}});break;case"downloadCSV":c=ZC.AQ.XW(p,"csv"),ZC.AQ.downloadFile(c,(a.fn||p.K)+".csv","text/csv;encoding:utf-8");break;case"downloadXLS":c=ZC.AQ.XW(p,"xls");var v=a.sn||"ZingChart";c=c.replace("<x:Name>[ZC]</x:Name>","<x:Name>"+v+"</x:Name>"),ZC.AQ.downloadFile(c,(a.fn||p.K)+".xls","application/vnd.ms-excel;encoding:utf-8");break;case"downloadRAW":var A=ZC.AQ.XW(p,"raw");if(!a.callback||"function"!=typeof a.callback)return A;try{a.callback(A,a.fn||p.K)}catch(w){a.callback(-1)}break;case"viewDataTable":if("viewdatatable"===a.menuid)if(c=ZC.AQ.XW(p,"html"),ZC.AL(p.K+"-data-table"))ZC.AL(p.K+"-data-table").innerHTML=c;else{var Z=ZC.Q.I4({id:p.K+"-data-table",cls:"zc-data-table "+p.K+"-data-table"});ZC.Q.PL(Z,{width:p.I+"px","max-height":"400px",overflow:"auto"}),Z.innerHTML=c,ZC.AL(p.K).parentNode.insertBefore(Z,ZC.AL(p.K).nextSibling)}else"hidedatatable"===a.menuid&&ZC.Q.EV(p.K+"-data-table")}return null};