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
},g=0;g<a.length;g++){if(c(t)||!Be(a[g].x,t))s+=" "+p(a[g])+" "+q(a[g]);else{j=V(a[g-1].x,a[g].x),k=W(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;var u=2*o;for(h=o;1>=h;h+=u)s+=i(a[g-1],a[g],h,o)}r=a[g].x}return s}function df(b){var c,d,e;if(wj=Hf.select(Kf),wj.empty())throw new Error('Bind element not found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');if(wj.html("").classed("c3",!0),If.data.xs={},If.data.targets=wc(b),Ug&&Mc(Ug===!0?Dc(If.data.targets):Ug),p(),T(),vg.domain(Hf.extent(ac(If.data.targets))),wg.domain(Yb(If.data.targets,"y")),xg.domain(Yb(If.data.targets,"y2")),yg.domain(vg.domain()),zg.domain(wg.domain()),Ag.domain(xg.domain()),xj=vg.domain(),lj.scale(yg),Rf&&pj.scale(vg),qj=wj.append("svg").on("mouseenter",Uf).on("mouseleave",Vf),rj=qj.append("defs"),rj.append("clipPath").attr("id",Gi).append("rect"),rj.append("clipPath").attr("id",Hi).append("rect"),rj.append("clipPath").attr("id",Ii).append("rect"),qf(),sj=qj.append("g").attr("transform",cj.main),tj=qj.append("g").attr("transform",cj.context),uj=qj.append("g").attr("transform",cj.legend),eh||tj.style("visibility","hidden"),hh||(uj.style("visibility","hidden"),Zi=Dc(If.data.targets)),vj=Hf.select(Kf).style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),Cf(Dc(If.data.targets),{withTransform:!1,withTransitionForTransform:!1}),d=sj.append("g").attr("clip-path",Ji).attr("class",g.grid),Yh&&d.append("g").attr("class",g.xgrids),De($h)&&d.append("g").attr("class",g.xgridLines),ei&&d.append("g").attr("class",g.xgridFocus).append("line").attr("class",g.xgridFocus),_h&&d.append("g").attr("class",g.ygrids),De(ai)&&d.append("g").attr("class",g.ygridLines),sj.append("g").attr("clip-path",Ji).attr("class",g.regions),sj.append("g").attr("clip-path",Ji).attr("class",g.chart),c=sj.select("."+g.chart).append("g").attr("class",g.eventRects).style("fill-opacity",0).style("cursor",Rf?nh?"ns-resize":"ew-resize":null),sj.select("."+g.chart).append("g").attr("class",g.chartBars),sj.select("."+g.chart).append("g").attr("class",g.chartLines),sj.select("."+g.chart).append("g").attr("class",g.chartArcs).attr("transform",cj.arc).append("text").attr("class",g.chartArcsTitle).style("text-anchor","middle").text(Sb()),sj.select("."+g.chart).append("g").attr("class",g.chartTexts),Rf&&sj.insert("rect",Tf?null:"g."+g.grid).attr("class",g.zoomRect).attr("width",ag).attr("height",cg).style("opacity",0).style("cursor",nh?"ns-resize":"ew-resize").call(pj).on("dblclick.zoom",null),Eh&&lj.extent("function"!=typeof Eh?Eh:Eh(ac())),oh&&sj.append("g").attr("class",g.axisX).attr("clip-path",Ki).attr("transform",cj.x).append("text").attr("class",g.axisXLabel).attr("transform",nh?"rotate(-90)":"").style("text-anchor",Bb),Gh&&sj.append("g").attr("class",g.axisY).attr("clip-path",Li).attr("transform",cj.y).append("text").attr("class",g.axisYLabel).attr("transform",nh?"":"rotate(-90)").style("text-anchor",Cb),Ph&&sj.append("g").attr("class",g.axisY2).attr("transform",cj.y2).append("text").attr("class",g.axisY2Label).attr("transform",nh?"":"rotate(-90)").style("text-anchor",Db),tj.append("g").attr("clip-path",Ji).attr("class",g.chart),tj.select("."+g.chart).append("g").attr("class",g.chartBars),tj.select("."+g.chart).append("g").attr("class",g.chartLines),tj.append("g").attr("clip-path",Ji).attr("class",g.brush).call(lj).selectAll("rect").attr(nh?"width":"height",nh?bg:dg),tj.append("g").attr("class",g.axisX).attr("transform",cj.subx).attr("clip-path",nh?"":Ki),sf(If.data.targets),nh?sj.select("."+g.axisX).style("opacity",0).call(Bg):(sj.select("."+g.axisY).style("opacity",0).call(Cg),sj.select("."+g.axisY2).style("opacity",0).call(Dg)),p(),T(),qf(),o(!1),mf({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransitionForAxis:!1}),Di){if(Mi&&"string"==typeof Ei){for(Ei=ye(Ei),e=0;e<If.data.targets[0].values.length&&If.data.targets[0].values[e].x-Ei!==0
}},dj="right"===ih,ej=0,fj=0,gj=0,hj=.15,ij=30,jj=nh&&!oh?0:30,kj=5;mg=Hf.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)});var lj,mj=function(){var a=Hf.svg.line().x(nh?function(a){return X(a.id)(a.value)}:Gd).y(nh?Gd:function(a){return X(a.id)(a.value)});return ii||(a=a.defined(function(a){return null!=a.value})),function(b){var c,d,e=ii?Pe(b.values):b.values;return ke(b)?(a.interpolate(le(b)?"cardinal":"linear"),Rg[b.id]?cf(e,vg,X(b.id),Rg[b.id]):a(e)):(c=e[0]?vg(e[0].x):0,d=e[0]?X(b.id)(e[0].value):0,nh?"M "+d+" "+c:"M "+c+" "+d)}}(),nj=function(){var a;return a=nh?Hf.svg.area().x0(function(a){return X(a.id)(0)}).x1(function(a){return X(a.id)(a.value)}).y(Gd):Hf.svg.area().x(Gd).y0(function(a){return X(a.id)(0)}).y1(function(a){return X(a.id)(a.value)}),function(b){var c,d,e=Pe(b.values);return ee([b],"area")||ee([b],"area-spline")?(a.interpolate(le(b)?"cardinal":"linear"),a(e)):(c=e[0]?vg(e[0].x):0,d=e[0]?X(b.id)(e[0].value):0,nh?"M "+d+" "+c:"M "+c+" "+d)}}(),oj=function(){var a=Hf.svg.line().x(nh?function(a){return Y(a.id)(a.value)}:Jd).y(nh?Jd:function(a){return Y(a.id)(a.value)});return function(b){var c=Pe(b.values);return ke(b)?a(c):"M "+yg(c[0].x)+" "+Y(b.id)(c[0].value)}}(),pj=function(){};lj=Hf.svg.brush().on("brush",nf),lj.update=function(){return tj&&tj.select("."+g.brush).call(this),this},lj.scale=function(a){return nh?this.y(a):this.x(a)},Rf&&(pj=Hf.behavior.zoom().on("zoomstart",function(){pj.altDomain=Hf.event.sourceEvent.altKey?vg.orgDomain():null}).on("zoom",Rf?of:null),pj.scale=function(a){return nh?this.y(a):this.x(a)},pj.orgScaleExtent=function(){var a=Sf?Sf:[1,10];return[a[0],Math.max(Ac()/a[1],a[1])]},pj.updateScaleExtent=function(){var a=bc(vg.orgDomain())/bc(xj),b=this.orgScaleExtent();return this.scaleExtent([b[0]*a,b[1]*a]),this});var qj,rj,sj,tj,uj,vj,wj,xj,yj,zj={};if(If.focus=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",1)}var c=qj.selectAll(qd(a)),d=c.filter(Df),e=c.filter(Ef);If.revert(),If.defocus(),b(d.classed(g.focused,!0)),b(e),je(If.data.targets)&&Ob(a,!0),yf(a,!0)},If.defocus=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",.3)}var c=qj.selectAll(qd(a)),d=c.filter(Df),e=c.filter(Ef);If.revert(),b(d.classed(g.focused,!1)),b(e),je(If.data.targets)&&Pb(a),yf(a,!1)},If.revert=function(a){function b(a){Jc(a).transition().duration(100).style("opacity",1)}var c=qj.selectAll(qd(a)),d=c.filter(Df),e=c.filter(Ef);b(d.classed(g.focused,!1)),b(e),je(If.data.targets)&&Pb(a),zf()},If.show=function(a,b){a=Ec(a),b=b||{},Nc(a),qj.selectAll(rd(a)).transition().style("opacity",1),b.withLegend&&Af(a),mf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},If.hide=function(a,b){a=Ec(a),b=b||{},Mc(a),qj.selectAll(rd(a)).transition().style("opacity",0),b.withLegend&&Bf(a),mf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},If.toggle=function(a){Hc(a)?If.hide(a):If.show(a)},If.unzoom=function(){lj.clear().update(),mf({withUpdateXDomain:!0})},If.load=function(a){return a.xs&&oc(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){Kg[b]=a.classes[b]}),"categories"in a&&Ni&&(rh=a.categories,Bg.categories(rh)),"cacheIds"in a&&cc(a.cacheIds)?void tf(ec(a.cacheIds),a.done):void("unload"in a?vf(Ec("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){uf(a)}):uf(a))},If.unload=function(a,b){vf(Ec(a),function(){mf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),"function"==typeof b&&b()})},If.selected=function(a){return Hf.merge(sj.selectAll("."+g.shapes+pd(a)).selectAll("."+g.shape).filter(function(){return Hf.select(this).classed(g.SELECTED)}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},If.select=function(a,b,c){Vg&&sj.selectAll("."+g.shapes).selectAll("."+g.shape).each(function(e,f){var h=Hf.select(this),i=e.data?e.data.id:e.id,j=Oe(this),k=Wg||!a||a.indexOf(i)>=0,l=!b||b.indexOf(f)>=0,m=h.classed(g.SELECTED);"path"!==this.nodeName&&(k&&l?Xg(e)&&!m&&j(!0,h.classed(g.SELECTED,!0),e,f):d(c)&&c&&m&&j(!1,h.classed(g.S