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.25 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
*/
zingchart.setModule("boxplot"),ZC.ZCBoxPlot={getDefaults:function(e,t,l){var i={},o=zingchart.getLoader(e);if(null===ZC._n_(o))return{};ZC._cp_({palette:o.B6.B6.palette||[]},i),ZC._cp_(ZC.ZCBoxPlot.B6,i),ZC.ZCBoxPlot.NT[l]&&ZC._cp_(ZC.ZCBoxPlot.NT[l],i);var a=i.palette[t%i.palette.length];return i.box["background-color"]=a[1],i.box["border-color"]=a[2],i.outlier.marker["background-color"]=a[2],i.outlier.marker["border-color"]=a[1],i.level["line-color"]=a[1],i["line-median-level"]["line-color"]=a[0],i.connector["line-color"]=a[1],ZC._cp_(o.B6.B6.boxplot,i),i},B6:{box:{"border-width":1,"hover-state":{visible:!1}},outlier:{marker:{"border-width":1,size:6}},level:{"line-width":2,"line-style":"solid"},"line-median-level":{"line-width":2},connector:{"line-width":1,"line-style":"solid"}},NT:{light:{box:{"border-width":1},outlier:{marker:{"border-width":1,size:4}},level:{"line-width":2,"line-style":"solid"},"line-median-level":{"line-width":2},connector:{"line-width":1,"line-style":"solid"}},dark:{box:{"border-width":1},outlier:{marker:{"border-width":1,size:4}},level:{"line-width":2,"line-style":"solid"},"line-median-level":{"line-width":2},connector:{"line-width":1,"line-style":"solid"}}}},zingchart.bind(null,"dataparse",function(e,t){for(var l=e.theme,i=e.id,o=0,a=t.graphset.length;o<a;o++)if(t.graphset[o].type&&("boxplot"===t.graphset[o].type||"hboxplot"===t.graphset[o].type)){var n=t.graphset[o].type;t.graphset[o]["plugin-type"]=n;var p=t.graphset[o];ZC._todash_(p);var r,s,d,h={};p.options&&(h=p.options[n]||p.options),ZC._todash_(h),p["scale-x"]=p["scale-x"]||{},p["scale-x"].values=p["scale-x"].values||[],p["scale-y"]=p["scale-y"]||{},p["scale-y"]["min-value"]=null!==ZC._n_(p["scale-y"]["min-value"])?p["scale-y"]["min-value"]:"auto",p.series=p.series||[],p.series[0]=p.series[0]||{},p.series[0].values=p.series[0].values||[],p.type="boxplot"===n?"mixed":"hmixed",p.plot=p.plot||{},p.plot.mode="normal",p.tooltip=p.tooltip||{};var c=p.series;ZC._todash_(c);var x=0,_="";for(r=0;r<c.length;r++)if(null===ZC._n_(c[r].type)||"boxplot"===c[r].type){var u=c[r]["data-box"]||[],b=c[r]["data-outlier"]||[],g=c[r].options||{},v=ZC.ZCBoxPlot.getDefaults(i,x,l),y={id:"boxplot-bar-"+r,type:"boxplot"===n?"vbar":"hbar",mode:"normal",scales:c[r].scales,options:g,"tooltip-text":"Maximum:<b>%data-max</b><br>Upper Quartile:<b>%data-upper-quartile</b><br>Median:<b>%data-median</b><br>Lower Quartile:<b>%data-lower-quartile</b><br>Minimum:<b>%data-min</b>"};for(_ in ZC._cp_(v.box,y),ZC._cp_(c[r],y),c[r])0===_.indexOf("data-")&&"data-box"!==_&&"data-outlier"!==_&&(y[_]=c[r][_]);var C=[],Z=[],m=[],f=[],w=[],A=[],z=[];for(s=0,d=u.length;s<d;s++){var B=s,k=0;6===u[s].length&&(B=u[s][0],k=1);var j=u[s][0+k],L=u[s][1+k],R=u[s][2+k],O=u[s][3+k],P=u[s][4+k];C.push([B,O-L,j-L,P-L,R-L]),Z.push(L),m.push(j),f.push(P),w.push(R),z.push(L),A.push(O)}y.values=C,y["extra-values"]=3,y["offset-values"]=Z,y["data-min"]=m,y["data-max"]=f,y["data-median"]=w,y["data-lower-quartile"]=z,y["data-upper-quartile"]=A,ZC._cp_(h.box,y),ZC._cp_(g.box,y);var M={id:"boxplot-scatter"+r,type:"boxplot"===n?"scatter":"hscatter",mode:"normal",scales:c[r].scales,options:g,text:"Outliers","tooltip-text":"Outlier:%node-value",values:b};for(_ in ZC._cp_(v.outlier,M),ZC._cp_(h.outlier,M),ZC._cp_(g.outlier,M),c[r])0===_.indexOf("data-")&&"data-box"!==_&&"data-outlier"!==_&&(M[_]=c[r][_]);c.push(y),b.length&&c.push(M),x++}for(r=c.length-1;r>=0;r--)null!==ZC._n_(c[r].type)&&"boxplot"!==c[r].type||c.splice(r,1)}return t}),zingchart.bind(null,"legend_item_click",function(e){var t,l,i=zingchart.getLoader(e.id),o=zingchart.getGraph(i,e.graphid).o;if(o["plugin-type"]=o["plugin-type"]||"","boxplot"===o["plugin-type"]||"hboxplot"===o["plugin-type"]){var a=zingchart.exec(e.id,"getobjectsbyclass",{type:"shape",graphid:e.graphid,cls:"boxplot-line-"+e.plotindex});for(t=0,l=a.length;t<l;t++)zingchart.exec(e.id,"updateobject",{type:"shape",graphid:e.graphid,id:a[t],data:{alpha:e.visible?0:1}})}}),zingchart.bind(null,"objectsinit",function(e){var t,l=e.loader.id,i=zingchart.getLoader(l),o=zingchart.getGraph(i,e.graphid),a=o.o,n=i.L2;if(a["plugin-type"]=a["plugin-type"]||"","boxplot"===a["plugin-type"]||"hboxplot"===a["plugin-type"]){var p={};a.options&&(p=a.options[a["plugin-type"]]||a.options),ZC._todash_(p);var r=a.shapes||[];for(t=r.length-1;t>=0;t--)null!==ZC._n_(r[t]["class"])&&-1!==r[t]["class"].indexOf("boxplot-line-")&&r.splice(t,1);var s,d=[];for(t=0;t<o.AY.A3.length;t++)-1!==o.AY.A3[t].HA.indexOf("boxplot-bar")&&d.push(t);var h=a.series;ZC._todash_(h);for(var c=0,x=0;x<d.length;x++){s=d[x];var _=zingchart.exec(e.loader.id,"getobjectinfo",{object:"plot",graphid:o.L,plotindex:s}),u=o.BM(_.scales[1]),b=h[s].options||{},g=ZC.ZCBoxPlot.getDefaults(l,c,n);for(t=0;t<o.AY.A3[s].R.length;t++){var v,y,C,Z,m,f,w=zingchart.exec(e.loader.id,"getobjectinfo",{object:"node",graphid:o.L,plotindex:s,nodeindex:t});if(w.onviewport&&w.visible){"boxplot"===a["plugin-type"]?(v=ZC._i_(u.AR(w.xdata.min)),y=ZC._i_(u.AR(w.xdata.median)),C=ZC._i_(u.AR(w.xdata.max))):(Z=ZC._i_(u.AR(w.xdata.min)),m=ZC._i_(u.AR(w.xdata.median)),f=ZC._i_(u.AR(w.xdata.max)));var A={type:"line",id:"boxplot-line-max-connector-"+s+"-"+t,"class":"boxplot-line-"+s,flat:!1,points:"boxplot"===a["plugin-type"]?[[w.x+w.width/2,u.AX?w.y+w.height:w.y],[w.x+w.width/2,C]]:[[u.AX?w.x:w.x+w.width,w.y+w.height/2],[f,w.y+w.height/2]]};ZC._cp_(g.connector,A),ZC._cp_(p.line,A),ZC._cp_(p["line-max-connector"],A),ZC._cp_(b["line-max-connector"],A),r.push(A);var z={type:"line",id:"boxplot-line-max-level-"+s+"-"+t,"class":"boxplot-line-"+s,flat:!1,points:"boxplot"===a["plugin-type"]?[[w.x+.25*w.width,C],[w.x+.75*w.width,C]]:[[f,w.y+.25*w.height],[f,w.y+.75*w.height]]};ZC._cp_(g.level,z),ZC._cp_(p.line,z),ZC._cp_(p["line-max-level"],z),ZC._cp_(b["line-max-level"],z),r.push(z);var B={type:"line",id:"boxplot-line-min-connector-"+s+"-"+t,"class":"boxplot-line-"+s,flat:!1,points:"boxplot"===a["plugin-type"]?[[w.x+w.width/2,u.AX?w.y:w.y+w.height],[w.x+w.width/2,v]]:[[u.AX?w.x+w.width:w.x,w.y+w.height/2],[Z,w.y+w.height/2]]};ZC._cp_(g.connector,B),ZC._cp_(p.line,B),ZC._cp_(p["line-min-connector"],B),ZC._cp_(b["line-min-connector"],B),r.push(B);var k={type:"line",id:"boxplot-line-min-level-"+s+"-"+t,"class":"boxplot-line-"+s,flat:!1,points:"boxplot"===a["plugin-type"]?[[w.x+.25*w.width,v],[w.x+.75*w.width,v]]:[[Z,w.y+.25*w.height],[Z,w.y+.75*w.height]]};ZC._cp_(g.level,k),ZC._cp_(p.line,k),ZC._cp_(p["line-min-level"],k),ZC._cp_(b["line-min-level"],k),r.push(k);var j={type:"line",id:"boxplot-line-median-level-"+s+"-"+t,"class":"boxplot-line-"+s,flat:!1,points:"boxplot"===a["plugin-type"]?[[w.x,y],[w.x+w.width-.5,y]]:[[m,w.y],[m,w.y+w.height-.5]]};ZC._cp_(g.level,j),ZC._cp_(g["line-median-level"],j),ZC._cp_(p.line,j),ZC._cp_(p["line-median-level"],j),ZC._cp_(b["line-median-level"],j),r.push(j)}}c++}a.shapes=r}});