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.37"},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,Si),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(Dj=Jf.select(Mf),Dj.empty())throw new Error('Bind element not found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');if(Dj.html("").classed("c3",!0),Kf.data.xs={},Kf.data.targets=xc(b),$g&&(Kf.data.targets=Kf.data.targets.filter($g)),Zg&&Mc(Zg===!0?Ec(Kf.data.targets):Zg),p(),T(),Ag.domain(Jf.extent(bc(Kf.data.targets))),Bg.domain(Zb(Kf.data.targets,"y")),Cg.domain(Zb(Kf.data.targets,"y2")),Dg.domain(Ag.domain()),Eg.domain(Bg.domain()),Fg.domain(Cg.domain()),Ej=Ag.domain(),sj.scale(Dg),Tf&&wj.scale(Ag),xj=Dj.append("svg").on("mouseenter",Xf).on("mouseleave",Yf),yj=xj.append("defs"),yj.append("clipPath").attr("id",Mi).append("rect"),yj.append("clipPath").attr("id",Ni).append("rect"),yj.append("clipPath").attr("id",Oi).append("rect"),rf(),zj=xj.append("g").attr("transform",jj.main),Aj=xj.append("g").attr("transform",jj.context),Bj=xj.append("g").attr("transform",jj.legend),kh||Aj.style("visibility","hidden"),nh||(Bj.style("visibility","hidden"),dj=Ec(Kf.data.targets)),Cj=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=zj.append("g").attr("clip-path",Pi).attr("class",g.grid),ci&&d.append("g").attr("class",g.xgrids),De(ei)&&d.append("g").attr("class",g.xgridLines),ki&&d.append("g").attr("class",g.xgridFocus).append("line").attr("class",g.xgridFocus),fi&&d.append("g").attr("class",g.ygrids),De(gi)&&d.append("g").attr("class",g.ygridLines),zj.append("g").attr("clip-path",Pi).attr("class",g.regions),zj.append("g").attr("clip-path",Pi).attr("class",g.chart),c=zj.select("."+g.chart).append("g").attr("class",g.eventRects).style("fill-opacity",0).style("cursor",Tf?th?"ns-resize":"ew-resize":null),zj.select("."+g.chart).append("g").attr("class",g.chartBars),zj.select("."+g.chart).append("g").attr("class",g.chartLines),zj.select("."+g.chart).append("g").attr("class",g.chartArcs).attr("transform",jj.arc).append("text").attr("class",g.chartArcsTitle).style("text-anchor","middle").text(Tb()),zj.select("."+g.chart).append("g").attr("class",g.chartTexts),Tf&&zj.insert("rect",Vf?null:"g."+g.grid).attr("class",g.zoomRect).attr("width",dg).attr("height",fg).style("opacity",0).style("cursor",th?"ns-resize":"ew-resize").call(wj).on("dblclick.zoom",null),Kh&&sj.extent("function"!=typeof Kh?Kh:Kh(bc())),ej.x=zj.append("g").attr("class",g.axisX).attr("clip-path",Qi).attr("transform",jj.x).style("visibility",uh?"visible":"hidden"),ej.x.append("text").attr("class",g.axisXLabel).attr("transform",th?"rotate(-90)":"").style("text-anchor",Cb),ej.y=zj.append("g").attr("class",g.axisY).attr("clip-path",Ri).attr("transform",jj.y).style("visibility",Mh?"visible":"hidden"),ej.y.append("text").attr("class",g.axisYLabel).attr("transform",th?"":"rotate(-90)").style("text-anchor",Db),ej.y2=zj.append("g").attr("class",g.axisY2).attr("transform",jj.y2).style("visibility",Vh?"visible":"hidden"),ej.y2.append("text").attr("class",g.axisY2Label).attr("transform",th?"":"rotate(-90)").style("text-anchor",Eb),Aj.append("g").attr("clip-path",Pi).attr("class",g.chart),Aj.select("."+g.chart).append("g").attr("class",g.chartBars),Aj.select("."+g.chart).append("g").attr("class",g.chartLines),Aj.append("g").attr("clip-path",Pi).attr("class",g.brush).call(sj).selectAll("rect").attr(th?"width":"height",th?eg:gg),ej.subx=Aj.append("g").attr("class",g.axisX).attr("transform",jj.subx).attr("clip-path",th?"":Qi),uf(Kf.data.targets),th?zj.select("."+g.axisX).style("opacity",0).call(Gg):(zj.se
},y2:function(){return"translate("+(th?0:dg)+","+(th?1:0)+")"},subx:function(){return"translate(0,"+(th?0:gg)+")"},arc:function(){return"translate("+mg/2+","+ng/2+")"}},kj="right"===oh,lj=0,mj=0,nj=0,oj=.15,pj=30,qj=th&&!uh?0:30,rj=5;rg=Jf.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)});var sj,tj=function(){var a=Jf.svg.line().x(th?function(a){return Y(a.id)(a.value)}:Gd).y(th?Gd:function(a){return Y(a.id)(a.value)});return oi||(a=a.defined(function(a){return null!=a.value})),function(b){var c,d,e=oi?Qe(b.values):b.values;return ke(b)?(a.interpolate(le(b)?"cardinal":"linear"),Wg[b.id]?df(e,Ag,Y(b.id),Wg[b.id]):a(e)):(c=e[0]?Ag(e[0].x):0,d=e[0]?Y(b.id)(e[0].value):0,th?"M "+d+" "+c:"M "+c+" "+d)}}(),uj=function(){var a;return a=th?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]?Ag(e[0].x):0,d=e[0]?Y(b.id)(e[0].value):0,th?"M "+d+" "+c:"M "+c+" "+d)}}(),vj=function(){var a=Jf.svg.line().x(th?function(a){return Z(a.id)(a.value)}:Jd).y(th?Jd:function(a){return Z(a.id)(a.value)});return function(b){var c=Qe(b.values);return ke(b)?a(c):"M "+Dg(c[0].x)+" "+Z(b.id)(c[0].value)}}(),wj=function(){};sj=Jf.svg.brush().on("brush",of),sj.update=function(){return Aj&&Aj.select("."+g.brush).call(this),this},sj.scale=function(a){return th?this.y(a):this.x(a)},Tf&&(wj=Jf.behavior.zoom().on("zoomstart",function(){wj.altDomain=Jf.event.sourceEvent.altKey?Ag.orgDomain():null}).on("zoom",Tf?pf:null),wj.scale=function(a){return th?this.y(a):this.x(a)},wj.orgScaleExtent=function(){var a=Uf?Uf:[1,10];return[a[0],Math.max(Bc()/a[1],a[1])]},wj.updateScaleExtent=function(){var a=cc(Ag.orgDomain())/cc(Ej),b=this.orgScaleExtent();return this.scaleExtent([b[0]*a,b[1]*a]),this});var xj,yj,zj,Aj,Bj,Cj,Dj,Ej,Fj,Gj={};if(Kf.focus=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",1)}var c=xj.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=xj.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=xj.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),xj.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),xj.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(){sj.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){Pg[b]=a.classes[b]}),"categories"in a&&Ti&&(xh=a.categories,Gg.categories(xh)),"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(zj.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&&zj.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=ah||!a||a.