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.34"},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
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 cf(b){var c,d,e;if(vj=Gf.select(Jf),vj.empty())throw new Error('Bind element not found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');if(vj.html("").classed("c3",!0),Hf.data.xs={},Hf.data.targets=vc(b),Tg&&Lc(Tg===!0?Cc(Hf.data.targets):Tg),o(),S(),ug.domain(Gf.extent(_b(Hf.data.targets))),vg.domain(Xb(Hf.data.targets,"y")),wg.domain(Xb(Hf.data.targets,"y2")),xg.domain(ug.domain()),yg.domain(vg.domain()),zg.domain(wg.domain()),wj=ug.domain(),kj.scale(xg),Qf&&oj.scale(ug),pj=vj.append("svg").on("mouseenter",Tf).on("mouseleave",Uf),qj=pj.append("defs"),qj.append("clipPath").attr("id",Fi).append("rect"),qj.append("clipPath").attr("id",Gi).append("rect"),qj.append("clipPath").attr("id",Hi).append("rect"),pf(),rj=pj.append("g").attr("transform",bj.main),sj=pj.append("g").attr("transform",bj.context),tj=pj.append("g").attr("transform",bj.legend),dh||sj.style("visibility","hidden"),gh||(tj.style("visibility","hidden"),Yi=Cc(Hf.data.targets)),uj=Gf.select(Jf).style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),Bf(Cc(Hf.data.targets),{withTransform:!1,withTransitionForTransform:!1}),d=rj.append("g").attr("clip-path",Ii).attr("class",g.grid),Xh&&d.append("g").attr("class",g.xgrids),Ce(Zh)&&d.append("g").attr("class",g.xgridLines),di&&d.append("g").attr("class",g.xgridFocus).append("line").attr("class",g.xgridFocus),$h&&d.append("g").attr("class",g.ygrids),Ce(_h)&&d.append("g").attr("class",g.ygridLines),nh&&rj.append("g").attr("class",g.axisX).attr("clip-path",Ji).attr("transform",bj.x).append("text").attr("class",g.axisXLabel).attr("transform",mh?"rotate(-90)":"").style("text-anchor",Ab),Fh&&rj.append("g").attr("class",g.axisY).attr("clip-path",Ki).attr("transform",bj.y).append("text").attr("class",g.axisYLabel).attr("transform",mh?"":"rotate(-90)").style("text-anchor",Bb),Oh&&rj.append("g").attr("class",g.axisY2).attr("transform",bj.y2).append("text").attr("class",g.axisY2Label).attr("transform",mh?"":"rotate(-90)").style("text-anchor",Cb),rj.append("g").attr("clip-path",Ii).attr("class",g.regions),rj.append("g").attr("clip-path",Ii).attr("class",g.chart),c=rj.select("."+g.chart).append("g").attr("class",g.eventRects).style("fill-opacity",0).style("cursor",Qf?mh?"ns-resize":"ew-resize":null),rj.select("."+g.chart).append("g").attr("class",g.chartBars),rj.select("."+g.chart).append("g").attr("class",g.chartLines),rj.select("."+g.chart).append("g").attr("class",g.chartArcs).attr("transform",bj.arc).append("text").attr("class",g.chartArcsTitle).style("text-anchor","middle").text(Rb()),rj.select("."+g.chart).append("g").attr("class",g.chartTexts),Qf&&rj.insert("rect",Sf?null:"g."+g.grid).attr("class",g.zoomRect).attr("width",_f).attr("height",bg).style("opacity",0).style("cursor",mh?"ns-resize":"ew-resize").call(oj).on("dblclick.zoom",null),Dh&&kj.extent("function"!=typeof Dh?Dh:Dh(_b())),sj.append("g").attr("clip-path",Ii).attr("class",g.chart),sj.select("."+g.chart).append("g").attr("class",g.chartBars),sj.select("."+g.chart).append("g").attr("class",g.chartLines),sj.append("g").attr("clip-path",Ii).attr("class",g.brush).call(kj).selectAll("rect").attr(mh?"width":"height",mh?ag:cg),sj.append("g").attr("class",g.axisX).attr("transform",bj.subx).attr("clip-path",mh?"":Ji),rf(Hf.data.targets),mh?rj.select("."+g.axisX).style("opacity",0).call(Ag):(rj.select("."+g.axisY).style("opacity",0).call(Bg),rj.select("."+g.axisY2).style("opacity",0).call(Cg)),o(),S(),pf(),n(!1),lf({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransitionForAxis:!1}),Ci){if(Li&&"string"==typeof Di){for(Di=xe(Di),e=0;e<Hf.data.targets[0].values.length&&Hf.data.targets[0].values[e].x-Di!==0;e++);Di=e}uj.html(Bi(Hf.data.targets.map(function(a){return pc(a.values[Di])}),_(),zd(ie(Hf.data.targets)),Ui)),uj.style("top",Ei.top).style("left",Ei.left).style("display","block")}null==a.onresize&&(a.onresize=of()),a.onresize.
}:Fd).y(mh?Fd:function(a){return W(a.id)(a.value)});return hi||(a=a.defined(function(a){return null!=a.value})),function(b){var c,d,e=hi?Oe(b.values):b.values;return je(b)?(a.interpolate(ke(b)?"cardinal":"linear"),Qg[b.id]?bf(e,ug,W(b.id),Qg[b.id]):a(e)):(c=e[0]?ug(e[0].x):0,d=e[0]?W(b.id)(e[0].value):0,mh?"M "+d+" "+c:"M "+c+" "+d)}}(),mj=function(){var a;return a=mh?Gf.svg.area().x0(function(a){return W(a.id)(0)}).x1(function(a){return W(a.id)(a.value)}).y(Fd):Gf.svg.area().x(Fd).y0(function(a){return W(a.id)(0)}).y1(function(a){return W(a.id)(a.value)}),function(b){var c,d,e=Oe(b.values);return de([b],"area")||de([b],"area-spline")?(a.interpolate(ke(b)?"cardinal":"linear"),a(e)):(c=e[0]?ug(e[0].x):0,d=e[0]?W(b.id)(e[0].value):0,mh?"M "+d+" "+c:"M "+c+" "+d)}}(),nj=function(){var a=Gf.svg.line().x(mh?function(a){return X(a.id)(a.value)}:Id).y(mh?Id:function(a){return X(a.id)(a.value)});return function(b){var c=Oe(b.values);return je(b)?a(c):"M "+xg(c[0].x)+" "+X(b.id)(c[0].value)}}(),oj=function(){};kj=Gf.svg.brush().on("brush",mf),kj.update=function(){return sj&&sj.select("."+g.brush).call(this),this},kj.scale=function(a){return mh?this.y(a):this.x(a)},Qf&&(oj=Gf.behavior.zoom().on("zoomstart",function(){oj.altDomain=Gf.event.sourceEvent.altKey?ug.orgDomain():null}).on("zoom",Qf?nf:null),oj.scale=function(a){return mh?this.y(a):this.x(a)},oj.orgScaleExtent=function(){var a=Rf?Rf:[1,10];return[a[0],Math.max(zc()/a[1],a[1])]},oj.updateScaleExtent=function(){var a=ac(ug.orgDomain())/ac(wj),b=this.orgScaleExtent();return this.scaleExtent([b[0]*a,b[1]*a]),this});var pj,qj,rj,sj,tj,uj,vj,wj,xj,yj={};if(Hf.focus=function(a){function b(a){Ic(a).transition().duration(100).style("opacity",1)}var c=pj.selectAll(pd(a)),d=c.filter(Cf),e=c.filter(Df);Hf.revert(),Hf.defocus(),b(d.classed(g.focused,!0)),b(e),ie(Hf.data.targets)&&Nb(a,!0),xf(a,!0)},Hf.defocus=function(a){function b(a){Ic(a).transition().duration(100).style("opacity",.3)}var c=pj.selectAll(pd(a)),d=c.filter(Cf),e=c.filter(Df);Hf.revert(),b(d.classed(g.focused,!1)),b(e),ie(Hf.data.targets)&&Ob(a),xf(a,!1)},Hf.revert=function(a){function b(a){Ic(a).transition().duration(100).style("opacity",1)}var c=pj.selectAll(pd(a)),d=c.filter(Cf),e=c.filter(Df);b(d.classed(g.focused,!1)),b(e),ie(Hf.data.targets)&&Ob(a),yf()},Hf.show=function(a,b){a=Dc(a),b=b||{},Mc(a),pj.selectAll(qd(a)).transition().style("opacity",1),b.withLegend&&zf(a),lf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},Hf.hide=function(a,b){a=Dc(a),b=b||{},Lc(a),pj.selectAll(qd(a)).transition().style("opacity",0),b.withLegend&&Af(a),lf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},Hf.toggle=function(a){Gc(a)?Hf.hide(a):Hf.show(a)},Hf.unzoom=function(){kj.clear().update(),lf({withUpdateXDomain:!0})},Hf.load=function(a){return a.xs&&nc(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){Jg[b]=a.classes[b]}),"categories"in a&&Mi&&(qh=a.categories,Ag.categories(qh)),"cacheIds"in a&&bc(a.cacheIds)?void sf(dc(a.cacheIds),a.done):void("unload"in a?uf(Dc("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){tf(a)}):tf(a))},Hf.unload=function(a,b){uf(Dc(a),function(){lf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),"function"==typeof b&&b()})},Hf.selected=function(a){return Gf.merge(rj.selectAll("."+g.shapes+od(a)).selectAll("."+g.shape).filter(function(){return Gf.select(this).classed(g.SELECTED)}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},Hf.select=function(a,b,c){Ug&&rj.selectAll("."+g.shapes).selectAll("."+g.shape).each(function(e,f){var h=Gf.select(this),i=e.data?e.data.id:e.id,j=Ne(this),k=Vg||!a||a.indexOf(i)>=0,l=!b||b.indexOf(f)>=0,m=h.classed(g.SELECTED);k&&l?Wg(e)&&!m&&j(!0,h.classed(g.SELECTED,!0),e,f):d(c)&&c&&m&&j(!1,h.classed(g.SELECTED,!1),e,f)})},Hf.unselect=function(a,b){Ug&&rj.selectAll("."+g.shapes).selectAll("."+g.shape).each(function(c,d){var e=Gf.select(this),f=c.data?c.data.id:c.id,h=Ne(this),i=Vg||!a||a.indexOf(f)>=0,j=!b||b.indexOf(d)>=0,k=e.classed(g.SELECTED);i&&j&&Wg(c)&&k&&h(!1,e.