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.73 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_ES6 */ zingchart.setModule("color-scale"),zingchart.plugins.colorscale={},zingchart.plugins.colorscale.info={},zingchart.plugins.colorscale.defaults={box:{},item:{placement:"default","font-size":10,color:"#33"},label:{"font-size":10,color:"#33"},guide:{"line-color":"#fff","line-width":1},cursor:{type:"diamond",size:4,"background-color":"#000"}},zingchart.bind(null,"complete",function(a){zingchart.plugins.colorscale.paint(a)}),zingchart.plugins.colorscale.paint=function(a){var e=zingchart.getLoader(a.id),i=zingchart.getModules(e);if(-1!==ZC.AV(i,"color-scale"))for(var l=0,r=e.AG.length;l<r;l++){var t=e.AG[l];if(t.o["color-scale"]){var c=zingchart.plugins.colorscale.defaults,o=t.o["color-scale"]||{};o.guide=o.guide||{};var n,s=o.aspect||"gradient",h=o.intervals||4,g=o.layout||"v",p=o.color||"#369",u=o["max-percent"]||50,_=o.effect||"lighten",d=o.progression||"lin",f=ZC._f_(o["min-value"]||"0"),C=ZC._f_(o["max-value"]||"10"),Z=o.steps||[],z=o.colors||[],m=o[ZC._[10]]||[],v=ZC._b_(o.mirrored);ZC._b_(o.map)&&(n=zingchart.maps.getMapByGraphIndex(a.id,t.L)._INFO_.choropleth)&&(s=n.aspect,h=n.intervals,p=n.color,u=n.maxPercent,_=n.effect,d=n.progression,f=n.minValue,C=n.maxValue,Z=n.steps,z=n.colors,m=n[ZC._[10]],v=n.mirrored),"v"===g?(o.margin=o.margin||"auto 10 auto auto",o[ZC._[19]]=o[ZC._[19]]||15,o[ZC._[20]]=o[ZC._[20]]||200,o["fill-angle"]=270):(o.margin=o.margin||"auto auto 35 auto",o[ZC._[19]]=o[ZC._[19]]||200,o[ZC._[20]]=o[ZC._[20]]||15,o["fill-angle"]=0);var x=zingchart.getInstance(t,"box");x.append(c.box),x.append(o),x.parse();var y,b,F,I,M,A="v"===g?x.F:x.I,X=[],Y=null;if("gradient"===s){var L=Math.max(2,Math.ceil(A/("v"===g?30:60)));if("log"===d){for((I=Math.floor(ZC.FU(f,10)))===(M=Math.ceil(ZC.FU(C,10)))&&M++,y=I;y<=M;y+=1)X.push(Math.pow(10,y));if(X.length>L&&X.length%2==1)for(y=X.length-1;y>=0;y--)y%2==1&&X.splice(y,1)}else{F=ZC.AP.X2(f,C);for(var U=0;(F[1]-C)/F[2]>.5&&U<10;)F=ZC.AP.X2(f,C,Math.round(F[2]/2)),U++;for(Y=F[3]<0?-F[3]:null,0===F[3]&&F[2]<1&&(Y=1),y=F[0];y<=F[1];y+=F[2])X.push(y);if(X.length>1.5*L){if(X.length%2==1)for(y=X.length-1;y>=0;y--)y%2==1&&X.splice(y,1);if(X.length>1.5*L)for(var k=!1;!k;){for(k=!0,X=[],y=(F=ZC.AP.X2(f,C,2*F[2]))[0];y<=F[1];y+=F[2])X.push(y);X.length>1.5*L&&(k=!1)}}}}else{var w;if(Z.length)h=Z.length-1;else if("lin"===d){var P=(C-f)/h;for(b=0;b<h;b+=1)Z.push(f+b*P);Z.push(C)}else{for((I=Math.floor(ZC.FU(f,10)))===(M=Math.ceil(ZC.FU(C,10)))&&M++,h=Math.max(1,M-I-1),b=I;b<=M;b+=1)Z.push(Math.pow(10,b));w=u/h}if(!z.length)for(b=0;b<=h;b+=1)z.push("lighten"===_?ZC.AR.RC(p,b*w):ZC.AR.JU(p,b*w));X=[].concat(Z)}var G=a.id+"_"+t.L;zingchart.plugins.colorscale.info[G]={aspect:s,min:X[0],max:X[X.length-1],progression:d,layout:g,x:x.iX,y:x.iY,width:x.I,height:x.F,steps:Z};var K=0,j=0,R=zingchart.getInstance(t,"textbox");for(y=0;y<X.length;y++)R.append(c.item),R.append(o.item),R.o.text=X[y],R.parse(),K=Math.max(K,R.I),j=Math.max(j,R.F);var V,J,N=[],B=[];if(zingchart.exec(a.id,"removeobject",{graphid:t.K,type:"shape",cls:"zc-colorscale"}),zingchart.exec(a.id,"removeobject",{graphid:t.K,type:"label",cls:"zc-colorscale"}),"gradient"===s){V={flat:!0,cls:"zc-colorscale"};var O=p,q="lighten"===_?ZC.AR.RC(p,u):ZC.AR.JU(p,u);V[ZC._[0]]=O+" "+q,v&&(V[ZC._[0]]=q+" "+O),ZC._cp_(x.o,V),V.id="colorscale_box",N.push(V)}else for(b=0;b<h;b+=1)V={flat:!0,cls:"zc-colorscale"},ZC._cp_(x.o,V),V[ZC._[0]]=z[b],V.id="colorscale_box_"+b,"h"===g?(V.x=x.iX+b*x.I/h,V.y=x.iY,V[ZC._[19]]=x.I/h,V[ZC._[20]]=x.F):(V.x=x.iX,V.y=x.iY+x.F-(b+1)*x.F/h,V[ZC._[19]]=x.I,V[ZC._[20]]=x.F/h),ZC._cp_(o.marker,V),0===b&&(zingchart.plugins.colorscale.info[G].marker=[V[ZC._[19]],V[ZC._[20]]]),V.margin=null,N.push(V),m[b]&&(J={flat:!0,cls:"zc-colorscale"},ZC._cp_(c.label,J),ZC._cp_(o.label,J),J.text=m[b],"h"===g?(J[ZC._[19]]=x.I/h,J.x=x.iX+b*x.I/h,J.y=x.iY):(J[ZC._[20]]=x.F/h,J.x=x.iX+x.I+5,J.y=x.iY+x.F-(b+1)*x.F/h),J.id="colorscale_label_"+b,N.push(J));var D,E,H,Q,S=A/(X.length-1),T=[];for(y=0;y<X.length;y++){if(E={flat:!0,cls:"zc-colorscale"},ZC._cp_(c.item,E),ZC._cp_(o.item,E),H={decimals:Y,short:!0,"thousands-separator":",","decimals-separator":"."},"log"===d){var W=Math.floor(ZC.FU(X[y],10));H.decimals=W<0?-W:0}ZC._cp_(o.item,H),Q=zingchart.formatNumber(X[y],H);var $=ZC._i_(o.guide[ZC._[21]]||("v"===g?x.I:x.F));"v"===g?(D=x.iY+x.F-S*y,T.push([x.iX,D],[x.iX+$,D],null),ZC._cp_({anchor:"l",width:K,align:"right",x:x.iX-K-5,y:D,text:Q},E)):(D=x.iX+S*y,T.push([D,x.iY],[D,x.iY+$],null),ZC._cp_({anchor:"t",height:j,align:"center","vertical-align":"top",x:D,y:x.iY+x.F+5,text:Q},E)),E.x-=t.iX,E.y-=t.iY,E.id="colorscale_item_"+y,N.push(E)}var aa={type:"line",flat:!0,cls:"zc-colorscale"};ZC._cp_(c.guide,aa),ZC._cp_(o.guide,aa),aa.id="colorscale_guide",aa.points=T,B.push(aa);var ea={flat:!0,visible:!1,cls:"zc-colorscale"};ZC._cp_(c.cursor,ea),ZC._cp_(o.cursor,ea),ea.id="colorscale_cursor";var ia=zingchart.plugins.colorscale.info[G].marker?zingchart.plugins.colorscale.info[G].marker[0]:x.I,la=zingchart.plugins.colorscale.info[G].marker?zingchart.plugins.colorscale.info[G].marker[1]:x.F;ea.x=x.iX+ia/2-t.iX,ea.y=x.iY+la/2-t.iY,B.push(ea),zingchart.exec(a.id,"addobject",{graphid:t.K,type:"label",data:N,dynamic:!0,update:!1}),zingchart.exec(a.id,"addobject",{graphid:t.K,type:"shape",dynamic:!0,data:B})}}},zingchart.plugins.colorscale.clear=function(a,e){a=a||"zc";var i=zingchart.getLoader(a);if(i){var l=zingchart.getGraph(i,e[ZC._[3]]||"0");if(l){if(!zingchart.plugins.colorscale.info[a+"_"+l.L])return;zingchart.exec(a,"updateobject",{graphid:l.K,type:"shape",id:"colorscale_cursor",dynamic:!0,data:{visible:!1}})}}},zingchart.plugins.colorscale.AGM=function(a,e){if(null!==ZC._n_(e[ZC._[9]])){a=a||"zc";var i=zingchart.getLoader(a);if(i){var l=zingchart.getGraph(i,e[ZC._[3]]||"0");if(l){if(!zingchart.plugins.colorscale.info[a+"_"+l.L])return;var r,t,c,o=ZC._f_(e[ZC._[9]]),n=zingchart.plugins.colorscale.info[a+"_"+l.L];if("gradient"===n.aspect)"lin"===n.progression?(r=(o-n.min)/(n.max-n.min),t="h"===n.layout?n.x+r*n.width:n.y+n.height-r*n.height):(r=(ZC.FU(o,10)-ZC.FU(n.min,10))/(ZC.FU(n.max,10)-ZC.FU(n.min,10)),t="h"===n.layout?n.x+r*n.width:n.y+n.height-r*n.height);else{var s=0;if(o===n.steps[n.steps.length-1])s=n.steps.length-2;else for(var h=0;h<n.steps.length-1;h++)o>=n.steps[h]&&o<n.steps[h+1]&&(s=h);r=("h"===n.layout?n.width:n.height)/(n.steps.length-1),t=n.marker?"h"===n.layout?n.x+r/2+r*s:n.y+n.height-r*s-r+n.marker[1]/2:"h"===n.layout?n.x+r/2+r*s:n.y+n.height-r*s+n.marker[0]/2}(c="h"===n.layout?{x:t-l.iX}:{y:t-l.iY}).visible=!0,("h"===n.layout&&(t<n.x||t>n.x+n.width)||"v"===n.layout&&(t<n.y||t>n.y+n.height))&&(c.visible=!1),zingchart.exec(a,"updateobject",{graphid:l.K,type:"shape",id:"colorscale_cursor",dynamic:!0,data:c})}}}},zingchart.extendAPI("colorscale.setvalue",function(a,e){zingchart.plugins.colorscale.AGM(a,e)}),zingchart.extendAPI("colorscale.update",function(a,e){if(e.data){var i=zingchart.getLoader(a);if(i){var l=i.C9(e[ZC._[3]]);l&&l.o["color-scale"]&&(ZC._todash_(e.data),ZC._cp_(e.data,l.o["color-scale"]),zingchart.plugins.colorscale.paint({id:a,graphid:l.K}))}}}),zingchart.extendAPI("colorscale.clear",function(a,e){zingchart.plugins.colorscale.clear(a,e)}),zingchart.extendAPI("colorscale.getinfo",function(a,e){var i=zingchart.getLoader(a);if(i){var l=i.C9(e[ZC._[3]]);if(l)return zingchart.plugins.colorscale.info[a+"_"+l.L]}return null});