Quite good looking graph derived from d3.js http://c3js.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
70 KiB

!function(a){"use strict";function b(a){return a||0===a}function c(a){return"undefined"==typeof a}function d(a){return"undefined"!=typeof a}function e(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b<c[1];b++)d.push(b);return d.length>0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){var c=b&&a<u.length?u[a]:a;return j?j(c):c}function i(i){i.each(function(){var i,j,k=a.select(this),t=this.__chart__||m,u=this.__chart__=g(),v=r?r:f(u),w=k.selectAll(".tick").data(v,u),x=w.enter().insert("g",".domain").attr("class","tick").style("opacity",1e-6),y=a.transition(w.exit()).style("opacity",1e-6).remove(),z=a.transition(w).style("opacity",1),A=m.rangeExtent?m.rangeExtent():e(m.range()),B=k.selectAll(".domain").data([0]),C=(B.enter().append("path").attr("class","domain"),a.transition(B));x.append("line"),x.append("text");var D=x.select("line"),E=z.select("line"),F=w.select("text").text(h),G=x.select("text"),H=z.select("text");switch(b?(s=Math.ceil((u(1)-u(0))/2),j=l?0:s):s=j=0,n){case"bottom":i=c,D.attr("y2",o),G.attr("y",Math.max(o,0)+q),E.attr("x1",j).attr("x2",j).attr("y2",o),H.attr("x",0).attr("y",Math.max(o,0)+q),F.attr("dy",".71em").style("text-anchor","middle"),C.attr("d","M"+A[0]+","+p+"V0H"+A[1]+"V"+p);break;case"top":i=c,D.attr("y2",-o),G.attr("y",-(Math.max(o,0)+q)),E.attr("x2",0).attr("y2",-o),H.attr("x",0).attr("y",-(Math.max(o,0)+q)),F.attr("dy","0em").style("text-anchor","middle"),C.attr("d","M"+A[0]+","+-p+"V0H"+A[1]+"V"+-p);break;case"left":i=d,D.attr("x2",-o),G.attr("x",-(Math.max(o,0)+q)),E.attr("x2",-o).attr("y2",0),H.attr("x",-(Math.max(o,0)+q)).attr("y",s),F.attr("dy",".32em").style("text-anchor","end"),C.attr("d","M"+-p+","+A[0]+"H0V"+A[1]+"H"+-p);break;case"right":i=d,D.attr("x2",o),G.attr("x",Math.max(o,0)+q),E.attr("x2",o).attr("y2",0),H.attr("x",Math.max(o,0)+q).attr("y",0),F.attr("dy",".32em").style("text-anchor","start"),C.attr("d","M"+p+","+A[0]+"H0V"+A[1]+"H"+p)}if(u.rangeBand){var I=u,J=I.rangeBand()/2;t=u=function(a){return I(a)+J}}else t.rangeBand?t=u:y.call(i,u);x.call(i,t),z.call(i,u)})}var j,k,l,m=a.scale.linear(),n="bottom",o=6,p=6,q=3,r=null,s=0,t=!0,u=[];return i.scale=function(a){return arguments.length?(m=a,i):m},i.orient=function(a){return arguments.length?(n=a in{top:1,right:1,bottom:1,left:1}?a+"":"bottom",i):n},i.tickFormat=function(a){return arguments.length?(j=a,i):j},i.tickCentered=function(a){return arguments.length?(l=a,i):l},i.tickOffset=function(){return s},i.ticks=function(){return arguments.length?(k=arguments,i):k},i.tickCulling=function(a){return arguments.length?(t=a,i):t},i.tickValues=function(a){return arguments.length?(r=a,i):r},i.categories=function(a){return arguments.length?(u=a,i):u},i}var f={version:"0.1.36"},g={target:"c3-target",chart:"c3-chart",chartLine:"c3-chart-line",chartLines:"c3-chart-lines",chartBar:"c3-chart-bar",chartBars:"c3-chart-bars",chartText:"c3-chart-text",chartTexts:"c3-chart-texts",chartArc:"c3-chart-arc",chartArcs:"c3-chart-arcs",chartArcsTitle:"c3-chart-arcs-title",selectedCircle:"c3-selected-circle",selectedCircles:"c3-selected-circles",eventRect:"c3-event-rect",eventRects:"c3-event-rects",eventRectsSingle:"c3-event-rects-single",eventRectsMultiple:"c3-event-rects-multiple",zoomRect:"c3-zoom-rect",brush:"c3-brush",focused:"c3-focused",region:"c3-region",regions:"c3-regions",tooltip:"c3-tooltip",tooltipName:"c3-tooltip-name",shape:"c3-shape",shapes:"c3-shapes",line:"c3-line",lines:"c3-lines",bar:"c3-bar",bars:"c3-bars",circle:"c3-circle",circles:"c3-circles",arc:"c3-arc",arcs:"c3-arcs",area:"c3-area",areas:"c3-areas",text:"c3-text",texts:"c3-texts",grid:"c3-grid",xgrid:"c3-xgrid",xgrids:"c3-xgrids",xgridLine:"c3-xgrid-line",xgridLines:"c3-xgrid-lines",xgridFocu
return"M"+b(i)+" "+e(k(d))+" "+b(j)+" "+e(k(d+f))}:function(a,c,d,f){return"M"+b(j(d),!0)+" "+e(k(d))+" "+b(j(d+f),!0)+" "+e(k(d+f))},g=0;g<a.length;g++){if(c(u)||!Be(a[g].x,u))t+=" "+q(a[g])+" "+r(a[g]);else for(j=V(a[g-1].x,a[g].x,Ri),k=V(a[g-1].value,a[g].value),l=b(a[g].x)-b(a[g-1].x),m=e(a[g].value)-e(a[g-1].value),n=Math.sqrt(Math.pow(l,2)+Math.pow(m,2)),o=2/n,p=2*o,h=o;1>=h;h+=p)t+=i(a[g-1],a[g],h,o);s=a[g].x}return t}function ef(b){var c,d,e;if(Cj=Jf.select(Mf),Cj.empty())throw new Error('Bind element not found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');if(Cj.html("").classed("c3",!0),Kf.data.xs={},Kf.data.targets=xc(b),Zg&&(Kf.data.targets=Kf.data.targets.filter(Zg)),Yg&&Mc(Yg===!0?Ec(Kf.data.targets):Yg),p(),T(),zg.domain(Jf.extent(bc(Kf.data.targets))),Ag.domain(Zb(Kf.data.targets,"y")),Bg.domain(Zb(Kf.data.targets,"y2")),Cg.domain(zg.domain()),Dg.domain(Ag.domain()),Eg.domain(Bg.domain()),Dj=zg.domain(),rj.scale(Cg),Tf&&vj.scale(zg),wj=Cj.append("svg").on("mouseenter",Wf).on("mouseleave",Xf),xj=wj.append("defs"),xj.append("clipPath").attr("id",Li).append("rect"),xj.append("clipPath").attr("id",Mi).append("rect"),xj.append("clipPath").attr("id",Ni).append("rect"),rf(),yj=wj.append("g").attr("transform",ij.main),zj=wj.append("g").attr("transform",ij.context),Aj=wj.append("g").attr("transform",ij.legend),jh||zj.style("visibility","hidden"),mh||(Aj.style("visibility","hidden"),cj=Ec(Kf.data.targets)),Bj=Jf.select(Mf).style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),Ef(Ec(Kf.data.targets),{withTransform:!1,withTransitionForTransform:!1}),d=yj.append("g").attr("clip-path",Oi).attr("class",g.grid),bi&&d.append("g").attr("class",g.xgrids),De(di)&&d.append("g").attr("class",g.xgridLines),ji&&d.append("g").attr("class",g.xgridFocus).append("line").attr("class",g.xgridFocus),ei&&d.append("g").attr("class",g.ygrids),De(fi)&&d.append("g").attr("class",g.ygridLines),yj.append("g").attr("clip-path",Oi).attr("class",g.regions),yj.append("g").attr("clip-path",Oi).attr("class",g.chart),c=yj.select("."+g.chart).append("g").attr("class",g.eventRects).style("fill-opacity",0).style("cursor",Tf?sh?"ns-resize":"ew-resize":null),yj.select("."+g.chart).append("g").attr("class",g.chartBars),yj.select("."+g.chart).append("g").attr("class",g.chartLines),yj.select("."+g.chart).append("g").attr("class",g.chartArcs).attr("transform",ij.arc).append("text").attr("class",g.chartArcsTitle).style("text-anchor","middle").text(Tb()),yj.select("."+g.chart).append("g").attr("class",g.chartTexts),Tf&&yj.insert("rect",Vf?null:"g."+g.grid).attr("class",g.zoomRect).attr("width",cg).attr("height",eg).style("opacity",0).style("cursor",sh?"ns-resize":"ew-resize").call(vj).on("dblclick.zoom",null),Jh&&rj.extent("function"!=typeof Jh?Jh:Jh(bc())),dj.x=yj.append("g").attr("class",g.axisX).attr("clip-path",Pi).attr("transform",ij.x).style("visibility",th?"visible":"hidden"),dj.x.append("text").attr("class",g.axisXLabel).attr("transform",sh?"rotate(-90)":"").style("text-anchor",Cb),dj.y=yj.append("g").attr("class",g.axisY).attr("clip-path",Qi).attr("transform",ij.y).style("visibility",Lh?"visible":"hidden"),dj.y.append("text").attr("class",g.axisYLabel).attr("transform",sh?"":"rotate(-90)").style("text-anchor",Db),dj.y2=yj.append("g").attr("class",g.axisY2).attr("transform",ij.y2).style("visibility",Uh?"visible":"hidden"),dj.y2.append("text").attr("class",g.axisY2Label).attr("transform",sh?"":"rotate(-90)").style("text-anchor",Eb),zj.append("g").attr("clip-path",Oi).attr("class",g.chart),zj.select("."+g.chart).append("g").attr("class",g.chartBars),zj.select("."+g.chart).append("g").attr("class",g.chartLines),zj.append("g").attr("clip-path",Oi).attr("class",g.brush).call(rj).selectAll("rect").attr(sh?"width":"height",sh?dg:fg),dj.subx=zj.append("g").attr("class",g.axisX).attr("transform",ij.subx).attr("clip-path",sh?"":Pi),uf(Kf.data.targets),sh?yj.select("."+g.axisX).style("opacity",0).call(Fg):(yj.se
11 years ago
},subx:function(){return"translate(0,"+(sh?0:fg)+")"},arc:function(){return"translate("+lg/2+","+mg/2+")"}},jj="right"===nh,kj=0,lj=0,mj=0,nj=.15,oj=30,pj=sh&&!th?0:30,qj=5;qg=Jf.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)});var rj,sj=function(){var a=Jf.svg.line().x(sh?function(a){return Y(a.id)(a.value)}:Gd).y(sh?Gd:function(a){return Y(a.id)(a.value)});return ni||(a=a.defined(function(a){return null!=a.value})),function(b){var c,d,e=ni?Qe(b.values):b.values;return ke(b)?(a.interpolate(le(b)?"cardinal":"linear"),Vg[b.id]?df(e,zg,Y(b.id),Vg[b.id]):a(e)):(c=e[0]?zg(e[0].x):0,d=e[0]?Y(b.id)(e[0].value):0,sh?"M "+d+" "+c:"M "+c+" "+d)}}(),tj=function(){var a;return a=sh?Jf.svg.area().x0(function(a){return Y(a.id)(0)}).x1(function(a){return Y(a.id)(a.value)}).y(Gd):Jf.svg.area().x(Gd).y0(function(a){return Y(a.id)(0)}).y1(function(a){return Y(a.id)(a.value)}),function(b){var c,d,e=Qe(b.values);return ee([b],"area")||ee([b],"area-spline")?(a.interpolate(le(b)?"cardinal":"linear"),a(e)):(c=e[0]?zg(e[0].x):0,d=e[0]?Y(b.id)(e[0].value):0,sh?"M "+d+" "+c:"M "+c+" "+d)}}(),uj=function(){var a=Jf.svg.line().x(sh?function(a){return Z(a.id)(a.value)}:Jd).y(sh?Jd:function(a){return Z(a.id)(a.value)});return function(b){var c=Qe(b.values);return ke(b)?a(c):"M "+Cg(c[0].x)+" "+Z(b.id)(c[0].value)}}(),vj=function(){};rj=Jf.svg.brush().on("brush",of),rj.update=function(){return zj&&zj.select("."+g.brush).call(this),this},rj.scale=function(a){return sh?this.y(a):this.x(a)},Tf&&(vj=Jf.behavior.zoom().on("zoomstart",function(){vj.altDomain=Jf.event.sourceEvent.altKey?zg.orgDomain():null}).on("zoom",Tf?pf:null),vj.scale=function(a){return sh?this.y(a):this.x(a)},vj.orgScaleExtent=function(){var a=Uf?Uf:[1,10];return[a[0],Math.max(Bc()/a[1],a[1])]},vj.updateScaleExtent=function(){var a=cc(zg.orgDomain())/cc(Dj),b=this.orgScaleExtent();return this.scaleExtent([b[0]*a,b[1]*a]),this});var wj,xj,yj,zj,Aj,Bj,Cj,Dj,Ej,Fj={};if(Kf.focus=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",1)}var c=wj.selectAll(qd(a)),d=c.filter(Ff),e=c.filter(Gf);Kf.revert(),Kf.defocus(),b(d.classed(g.focused,!0)),b(e),je(Kf.data.targets)&&Pb(a,!0),Af(a,!0)},Kf.defocus=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",.3)}var c=wj.selectAll(qd(a)),d=c.filter(Ff),e=c.filter(Gf);Kf.revert(),b(d.classed(g.focused,!1)),b(e),je(Kf.data.targets)&&Qb(a),Af(a,!1)},Kf.revert=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",1)}var c=wj.selectAll(qd(a)),d=c.filter(Ff),e=c.filter(Gf);b(d.classed(g.focused,!1)),b(e),je(Kf.data.targets)&&Qb(a),Bf()},Kf.show=function(a,b){a=Fc(a),b=b||{},Nc(a),wj.selectAll(rd(a)).transition().style("opacity",1),b.withLegend&&Cf(a),nf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},Kf.hide=function(a,b){a=Fc(a),b=b||{},Mc(a),wj.selectAll(rd(a)).transition().style("opacity",0),b.withLegend&&Df(a),nf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},Kf.toggle=function(a){Hc(a)?Kf.hide(a):Kf.show(a)},Kf.unzoom=function(){rj.clear().update(),nf({withUpdateXDomain:!0})},Kf.load=function(a){return a.xs&&pc(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){Og[b]=a.classes[b]}),"categories"in a&&Si&&(wh=a.categories,Fg.categories(wh)),"cacheIds"in a&&dc(a.cacheIds)?void vf(fc(a.cacheIds),a.done):void("unload"in a?xf(Fc("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){wf(a)}):wf(a))},Kf.unload=function(a,b){xf(Fc(a),function(){nf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),"function"==typeof b&&b()})},Kf.selected=function(a){return Jf.merge(yj.selectAll("."+g.shapes+pd(a)).selectAll("."+g.shape).filter(function(){return Jf.select(this).classed(g.SELECTED)}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},Kf.select=function(a,b,c){$g&&yj.selectAll("."+g.shapes).selectAll("."+g.shape).each(function(e,f){var h=Jf.select(this),i=e.data?e.data.id:e.id,j=Pe(this),k=_g||!a||a.indexOf(i)>=0,l=!b||b.indexOf(f)>=0,m=h.classed(g.SELECTED);"