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.

4 lines
110 KiB

!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(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){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]<b&&b<B[1]?o:0}var j,k,t=a.select(this),u=this.__chart__||m,v=this.__chart__=g(),w=r?r:f(v),x=t.selectAll(".tick").data(w,v),y=x.enter().insert("g",".domain").attr("class","tick").style("opacity",1e-6),z=x.exit().remove(),A=a.transition(x).style("opacity",1),B=m.rangeExtent?m.rangeExtent():e(m.range()),C=t.selectAll(".domain").data([0]),D=(C.enter().append("path").attr("class","domain"),a.transition(C));y.append("line"),y.append("text");var E=y.select("line"),F=A.select("line"),G=x.select("text").text(h),H=y.select("text"),I=A.select("text");switch(b?(s=Math.ceil((v(1)-v(0))/2),k=l?0:s):s=k=0,n){case"bottom":j=c,E.attr("y2",o),H.attr("y",Math.max(o,0)+q),F.attr("x1",k).attr("x2",k).attr("y2",i),I.attr("x",0).attr("y",Math.max(o,0)+q),G.attr("dy",".71em").style("text-anchor","middle"),D.attr("d","M"+B[0]+","+p+"V0H"+B[1]+"V"+p);break;case"top":j=c,E.attr("y2",-o),H.attr("y",-(Math.max(o,0)+q)),F.attr("x2",0).attr("y2",-o),I.attr("x",0).attr("y",-(Math.max(o,0)+q)),G.attr("dy","0em").style("text-anchor","middle"),D.attr("d","M"+B[0]+","+-p+"V0H"+B[1]+"V"+-p);break;case"left":j=d,E.attr("x2",-o),H.attr("x",-(Math.max(o,0)+q)),F.attr("x2",-o).attr("y2",0),I.attr("x",-(Math.max(o,0)+q)).attr("y",s),G.attr("dy",".32em").style("text-anchor","end"),D.attr("d","M"+-p+","+B[0]+"H0V"+B[1]+"H"+-p);break;case"right":j=d,E.attr("x2",o),H.attr("x",Math.max(o,0)+q),F.attr("x2",o).attr("y2",0),I.attr("x",Math.max(o,0)+q).attr("y",0),G.attr("dy",".32em").style("text-anchor","start"),D.attr("d","M"+p+","+B[0]+"H0V"+B[1]+"H"+p)}if(v.rangeBand){var J=v,K=J.rangeBand()/2;u=v=function(a){return J(a)+K}}else u.rangeBand?u=v:z.call(j,v);y.call(j,u),A.call(j,v)})}var j,k,l,m=a.scale.linear(),n="bottom",o=6,p=6,q=3,r=null,s=0,t=!0;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){if("function"==typeof a)r=function(){return a(m.domain())};else{if(!arguments.length)return r;r=a}return i},i}var e,f,g={version:"0.3.0"};g.generate=function(a){return new b(a)},g.chart={fn:b.prototype,internal:{fn:c.prototype}},e=g.chart.fn,f=g.chart.internal.fn,f.init=function(){var a=this,b=a.config;if(a.initParams(),b[_])a.convertUrlToData(b[_],b[db],b[eb],a.initWithData);else if(b[ab])a.initWithData(a.convertJsonToData(b[ab],b[eb]));else if(b[bb])a.initWithData(a.convertRowsToData(b[bb]));else{if(!b[cb])throw Error("url or json or rows or columns is required.");a.initWithData(a.convertColumnsToData(b[cb]))}},f.initParams=function(){var a=this,b=a.d3,c=a.config;a.clipId="c3-"+ +new Date+"-clip",a.clipIdForXAxis=a.clipId+"-xaxis",a.clipIdForYAxis=a.clipId+"-yaxis",a.clipPath=a.getClipPath(a.clipId),a.clipPathForXAxis=a.getClipPath(a.clipIdForXAxis),a.clipPathForYAxis=a.getClipPath(a.clipIdFo
f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var
},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"
11 years ago
},f.classText=function(a){return this.generateClass(pe[Nd],a.index)},f.classTexts=function(a){return this.generateClass(pe[Od],a.id)},f.classShape=function(a){return this.generateClass(pe[Ad],a.index)},f.classShapes=function(a){return this.generateClass(pe[Bd],a.id)},f.classLine=function(a){return this.classShape(a)+this.generateClass(pe[Cd],a.id)},f.classLines=function(a){return this.classShapes(a)+this.generateClass(pe[Dd],a.id)},f.classCircle=function(a){return this.classShape(a)+this.generateClass(pe[Gd],a.index)},f.classCircles=function(a){return this.classShapes(a)+this.generateClass(pe[Hd],a.id)},f.classBar=function(a){return this.classShape(a)+this.generateClass(pe[Ed],a.index)},f.classBars=function(a){return this.classShapes(a)+this.generateClass(pe[Fd],a.id)},f.classArc=function(a){return this.classShape(a.data)+this.generateClass(pe[Id],a.data.id)},f.classArcs=function(a){return this.classShapes(a.data)+this.generateClass(pe[Jd],a.data.id)},f.classArea=function(a){return this.classShape(a)+this.generateClass(pe[Kd],a.id)},f.classAreas=function(a){return this.classShapes(a)+this.generateClass(pe[Ld],a.id)},f.classRegion=function(a,b){return this.generateClass(pe[wd],b)+" "+("class"in a?a.class:"")},f.classEvent=function(a){return this.generateClass(pe[pd],a.index)},f.classTarget=function(a){var b=this,c=b.config[E][a],d="";return c&&(d=" "+pe[$c]+"-"+c),b.generateClass(pe[$c],a)+d},f.classChartText=function(a){return pe[ed]+this.classTarget(a.id)},f.classChartLine=function(a){return pe[ad]+this.classTarget(a.id)},f.classChartBar=function(a){return pe[cd]+this.classTarget(a.id)},f.classChartArc=function(a){return pe[gd]+this.classTarget(a.data.id)},f.getTargetSelectorSuffix=function(a){return a||0===a?"-"+(a.replace?a.replace(/([^a-zA-Z0-9-_])/g,"-"):a):""},f.selectorTarget=function(a){return"."+pe[$c]+this.getTargetSelectorSuffix(a)},f.selectorTargets=function(a){var b=this;return a.length?a.map(function(a){return b.selectorTarget(a)}):null},f.selectorLegend=function(a){return"."+pe[ge]+this.getTargetSelectorSuffix(a)},f.selectorLegends=function(a){var b=this;return a.length?a.map(function(a){return b.selectorLegend(a)}):null};var qe=f.isValue=function(a){return a||0===a},re=f.isFunction=function(a){return"function"==typeof a},se=f.isString=function(a){return"string"==typeof a},te=f.isUndefined=function(a){return"undefined"==typeof a},ue=f.isDefined=function(a){return"undefined"!=typeof a},ve=f.ceil10=function(a){return 10*Math.ceil(a/10)},we=f.asHalfPixel=function(a){return Math.ceil(a)+.5},xe=f.diffDomain=function(a){return a[1]-a[0]},ye=f.isEmpty=function(a){return!a||se(a)&&0===a.length||"object"==typeof a&&0===Object.keys(a).length},ze=f.notEmpty=function(a){return Object.keys(a).length>0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f