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
108 KiB

!function(a){"use strict";function b(a){var b=this.internal=new c(a,this);b.loadConfig(a),b.init()}function c(b,c){var d=this;d.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,d.api=c,d.data={},d.cache={},d.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){return arguments.length?(r=a,i):r},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;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.clipIdForYAxis),a.dragStart=null,a.dragging=!1,a.cancelClick=!1,a.mouseover=!1,a.transiting=!1,a.color=a.generateColor(),a.levelColor=a.generateLevelColor(),a.dataTimeFormat=$c[B]?b.time.format:b.time.format.utc,a.axisTimeForm
$c[h]="#chart",$c[i]=void 0,$c[j]=void 0,$c[k]=void 0,$c[l]=void 0,$c[m]=void 0,$c[n]=void 0,$c[o]=!1,$c[p]=void 0,$c[q]=!1,$c[r]=function(){},$c[s]=!0,$c[t]=function(){},$c[u]=function(){},$c[v]=function(){},$c[w]=function(){},$c[x]=350,$c[y]=void 0,$c[z]={},$c[A]="%Y-%m-%d",$c[B]=!0,$c[C]=function(a){return a},$c[D]={},$c[E]={},$c[F]=[],$c[G]={},$c[H]=void 0,$c[I]={},$c[J]={},$c[K]="desc",$c[L]={},$c[M]=void 0,$c[N]={},$c[O]=!1,$c[P]=void 0,$c[Q]=!1,$c[R]=!1,$c[S]=function(){return!0},$c[T]=!0,$c[U]=function(){},$c[V]=function(){},$c[W]=function(){},$c[X]=function(){},$c[Y]=function(){},$c[Z]=function(){},$c[$]=function(){},$c[_]=void 0,$c[ab]=void 0,$c[bb]=void 0,$c[cb]=void 0,$c[db]=void 0,$c[eb]=void 0,$c[fb]="",$c[gb]=!1,$c[hb]=60,$c[ib]=function(){},$c[jb]=[],$c[kb]={},$c[lb]=!0,$c[mb]="bottom",$c[nb]="top-left",$c[ob]=10,$c[pb]=0,$c[qb]=void 0,$c[rb]=void 0,$c[sb]=void 0,$c[tb]=void 0,$c[ub]=!1,$c[vb]=!1,$c[wb]=!0,$c[xb]="indexed",$c[yb]=!0,$c[zb]=[],$c[Ab]=!1,$c[Bb]=void 0,$c[Cb]={},$c[Db]=10,$c[Eb]=void 0,$c[Fb]=!0,$c[Gb]=null,$c[Hb]=void 0,$c[Ib]=!0,$c[Jb]=null,$c[Kb]=null,$c[Lb]={},$c[Mb]=void 0,$c[Nb]=void 0,$c[Ob]={},$c[Pb]=!0,$c[Qb]=void 0,$c[Rb]=void 0,$c[Sb]=void 0,$c[Tb]={},$c[Ub]=void 0,$c[Vb]=!0,$c[Wb]=void 0,$c[Xb]=10,$c[Yb]=!1,$c[Zb]=void 0,$c[$b]=void 0,$c[_b]=void 0,$c[ac]={},$c[bc]=void 0,$c[cc]=!0,$c[dc]=void 0,$c[ec]=10,$c[fc]=!1,$c[gc]="tick",$c[hc]=[],$c[ic]=!1,$c[jc]=[],$c[kc]=10,$c[lc]=!0,$c[mc]=!0,$c[nc]=2.5,$c[oc]=!0,$c[pc]=void 0,$c[qc]=void 0,$c[rc]=!1,$c[sc]=void 0,$c[tc]=.6,$c[uc]=void 0,$c[vc]=!0,$c[wc]=!0,$c[xc]=!0,$c[yc]=void 0,$c[zc]=.05,$c[Ac]=!0,$c[Bc]=!0,$c[Cc]=!0,$c[Dc]=void 0,$c[Ec]=!0,$c[Fc]=0,$c[Gc]=100,$c[Hc]=void 0,$c[Ic]=void 0,$c[Jc]=!0,$c[Kc]=void 0,$c[Lc]=.05,$c[Mc]=void 0,$c[Nc]=!0,$c[Oc]=!0,$c[Pc]="",$c[Qc]=[],$c[Rc]=!0,$c[Sc]=!0,$c[Tc]=void 0,$c[Uc]=void 0,$c[Vc]=void 0,$c[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,c,c,d):""},$c[Xc]=!1,$c[Yc]=0,$c[Zc]={top:"0px",left:"50px"},f.loadConfig=function(a){function b(){var a=d.shift();return a&&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(),ve(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)),se(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config
},f.updateSizeForLegend=function(a,b){var c=this,d={top:c.isLegendTop?c.getCurrentPaddingTop()+$c[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-$c[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+$c[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-$c[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?d.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?d.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(qe[ke])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(qe[ke])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+qe[he]).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("."+qe[he]).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]&&ze(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-y-k)/2,x>f&&(f=(l-k)/2,y=0,F++)),E[a]=F,C[F]=r.isLegendInset?10:f,z[a]=y,y+=k}var f,g,h=r.getTextRect(b.textContent,qe[he]),i=10*Math.ceil((h.width+u)/10),j=10*Math.ceil((h.height+t)/10),k=r.isLegendRight||r.isLegendInset?j:i,l=r.isLegendRight||r.isLegendInset?r.getLegendHeight():r.getLegendWidth();return d&&(y=0,F=0,v=0,w=0),s[lb]&&!r.isLegendToShow(c)?void(A[c]=B[c]=E[c]=z[c]=0):(A[c]=i,B[c]=j,(!v||i>=v)&&(v=i),(!w||j>=w)&&(w=j),g=r.isLegendRight||r.isLegendInset?w:v,void(s[ub]?(Object.keys(A).forEach(function(a){A[a]=v}),Object.keys(B).forEach(function(a){B[a]=w}),f=(l-g*a.length)/2,x>f?(y=0,F=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,h,i,j,k,l,m,n,o,p,q,r=this,s=r.config,t=4,u=36,v=0,w=0,x=10,y=0,z={},A={},B={},C=[0],E={},F=0,G=r.legend.selectAll("."+qe[le]).size();b=b||{},m=Be(b,"withTransition",!0),n=Be(b,"withTransitionForTransform",!0),r.isLegendRight?(e=function(a){return v*E[a]},i=function(a){return C[E[a]]+z[a]}):r.isLegendInset?(e=function(a){return v*E[a]+10},i=function(a){return C[E[a]]+z[a]}):(e=function(a){return C[E[a]]+z[a]},i=function(a){return w*E[a]}),f=function(a,b){return e(a,b)+14},j=function(a,b){return i(a,b)+9},h=function(a,b){return e(a,b)-4},k=function(a,b){return i(a,b)-7},l=r.legend.selectAll("."+qe[he]).data(a).enter().append("g").attr("class",function(a){return r.generateClass(qe[he],a)}).style("visibility",function(a){return r.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){se(s[rb])?s[rb].call(g,a):r.api.toggle(a)}).on("mouseover",function(a){r.d3.select(this).classed(qe[le],!0),r.transiting||r.api.focus(a),se(s[sb])&&s[sb].call(r,a)}).on("mouseout",function(a){r.d3.select(this).classed(qe[le],!1),r.transiting||r.api.revert(),se(s[tb])&&s
},f.classArcs=function(a){return this.classShapes(a.data)+this.generateClass(qe[Kd],a.data.id)},f.classArea=function(a){return this.classShape(a)+this.generateClass(qe[Ld],a.id)},f.classAreas=function(a){return this.classShapes(a)+this.generateClass(qe[Md],a.id)},f.classRegion=function(a,b){return this.generateClass(qe[xd],b)+" "+("class"in a?a.class:"")},f.classEvent=function(a){return this.generateClass(qe[qd],a.index)},f.classTarget=function(a){var b=this,c=b.config[E][a],d="";return c&&(d=" "+qe[_c]+"-"+c),b.generateClass(qe[_c],a)+d},f.classChartText=function(a){return qe[fd]+this.classTarget(a.id)},f.classChartLine=function(a){return qe[bd]+this.classTarget(a.id)},f.classChartBar=function(a){return qe[dd]+this.classTarget(a.id)},f.classChartArc=function(a){return qe[hd]+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"."+qe[_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"."+qe[he]+this.getTargetSelectorSuffix(a)},f.selectorLegends=function(a){var b=this;return a.length?a.map(function(a){return b.selectorLegend(a)}):null};var re=f.isValue=function(a){return a||0===a},se=f.isFunction=function(a){return"function"==typeof a},te=f.isString=function(a){return"string"==typeof a},ue=f.isUndefined=function(a){return"undefined"==typeof a},ve=f.isDefined=function(a){return"undefined"!=typeof a},we=f.ceil10=function(a){return 10*Math.ceil(a/10)},xe=f.asHalfPixel=function(a){return Math.ceil(a)+.5},ye=f.diffDomain=function(a){return a[1]-a[0]},ze=f.isEmpty=function(a){return!a||te(a)&&0===a.length||"object"==typeof a&&0===Object.keys(a).length},Ae=f.notEmpty=function(a){return Object.keys(a).length>0},Be=f.getOption=function(a,b,c){return ve(a[b])?a[b]:c},Ce=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},De=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}},Ee=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(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));this.revert(),this.defocus(),b(e.classed(qe[wd],!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(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));this.revert(),b(e.classed(qe[wd],!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(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));b(e.classed(qe[wd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomai