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.

2 lines
49 KiB

11 years ago
!function(a){"use strict";function b(){function a(a,b){a.attr("transform",function(a){return"translate("+(b(a)+q)+", 0)"})}function b(a,b){a.attr("transform",function(a){return"translate(0,"+b(a)+")"})}function c(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function d(a){for(var b=[],c=Math.ceil(a[0]);c<a[1];c++)b.push(c);return b.length>0&&b[0]>0&&b.unshift(b[0]-(b[1]-b[0])),b}function e(a,b){var c=a.length-1;return p>=c||b%Math.ceil(c/p)===0}function f(a){return a<t.length?t[a]:a}function h(a){var b=f(a);return r?r(b):b}function i(f){f.each(function(){var f,i,p=g.select(this),r=d(j.domain()),s=p.selectAll(".tick.major").data(r,String),t=s.enter().insert("g","path").attr("class","tick major").style("opacity",1e-6),u=g.transition(s.exit()).style("opacity",1e-6).remove(),v=g.transition(s).style("opacity",1),w=j.rangeExtent?j.rangeExtent():c(j.range()),x=p.selectAll(".domain").data([0]);x.enter().append("path").attr("class","domain");var y=g.transition(x),z=j.copy(),A=this.__chart__||z;this.__chart__=z,t.append("line"),t.append("text");var B=t.select("line"),C=v.select("line"),D=s.select("text"),E=t.select("text"),F=v.select("text");switch(q=(z(1)-z(0))/2,i=o?0:q,k){case"bottom":f=a,B.attr("y2",l),E.attr("y",Math.max(l,0)+n),C.attr("x1",i).attr("x2",i).attr("y2",l),F.attr("x",0).attr("y",Math.max(l,0)+n),D.attr("dy",".71em").style("text-anchor","middle"),D.text(function(a){return e(r,a)?h(a):""}),y.attr("d","M"+w[0]+","+m+"V0H"+w[1]+"V"+m);break;case"left":f=b,B.attr("x2",-l),E.attr("x",-(Math.max(l,0)+n)),C.attr("x2",-l).attr("y2",0),F.attr("x",-(Math.max(l,0)+n)).attr("y",q),D.attr("dy",".32em").style("text-anchor","end"),D.text(function(a){return e(r,a)?h(a):""}),y.attr("d","M"+-m+","+w[0]+"H0V"+w[1]+"H"+-m)}if(j.ticks)t.call(f,A),v.call(f,z),u.call(f,z);else{var G=z.rangeBand()/2,H=function(a){return z(a)+G};t.call(f,H),v.call(f,H)}})}var j=g.scale.linear(),k="bottom",l=6,m=6,n=3,o=!1,p=10,q=0,r=null,s=!0,t=[];return i.scale=function(a){return arguments.length?(j=a,i):j},i.orient=function(a){return arguments.length?(k=a in{top:1,right:1,bottom:1,left:1}?a+"":"bottom",i):k},i.categories=function(a){return arguments.length?(t=a,i):t},i.tickCentered=function(a){return arguments.length?(o=a,i):o},i.tickFormat=function(a){return arguments.length?(r=a,i):r},i.tickOffset=function(){return q},i.ticks=function(a){return arguments.length?(p=a,i):p},i.tickCulling=function(a){return arguments.length?(s=a,i):s},i}function c(a){return a||0===a}function d(a){return"undefined"==typeof a}function e(a){return"undefined"!=typeof a}var f=a.c3={},g=a.d3;f.generate=function(f){function h(a,b){if(!(a in f))throw Error(b)}function i(a,b){for(var c=f,d=0;d<a.length;d++){if(!(a[d]in c))return b;c=c[a[d]]}return c}function j(){rg.attr("transform",gg.main),rg.select(".x.axis").attr("transform",gg.x),rg.select(".y2.axis").attr("transform",gg.y2),rg.select(".chart-arcs").attr("transform",gg.arc)}function k(){Re&&(sg.attr("transform",gg.context),sg.select(".x.axis").attr("transform",gg.subx))}function l(a){var b=a!==!1?250:0;Ue&&tg.transition().duration(b).attr("transform",gg.legend)}function m(a){j(a),k(a),l(a)}function n(){$d=q(),_d=r(),ae=D(),be=C(),Td={top:Xe&&nf?20:0,right:t(),bottom:20+(Xe?0:Se)+(hg?0:ae),left:(Xe?Se+jg:0)+s()},Wd=$d-Td.left-Td.right,Yd=_d-Td.top-Td.bottom,Ud={top:Xe?Td.top:_d-Se-(hg?0:ae),right:0/0,bottom:20+(hg?0:ae),left:Xe?ig:Td.left},Xd=Xe?Td.left-ig-jg:Wd,Zd=Xe?Yd:_d-Ud.top-Ud.bottom,Vd={top:hg?Td.top:_d-ae,right:0/0,bottom:0,left:hg?$d-be:0},o(),hg&&yc(Dd.data.targets)&&(Vd.left=Wd/2+de)}function o(){de=Yd/2,ce=.95*de,ee=xc(Dd.data.targets)?.6*ce:0}function p(){var a=g.select(".y.axis").node().getBoundingClientRect(),b=g.select(Id).node().getBoundingClientRect();return a.right-b.left-s()}function q(){return Jd?Jd:v()}function r(){var a=Kd?Kd:w();return a>0?a:320}function s(){return yc(Dd.data.targets)?0:Ld?Ld:jf?1:u("y")}function t(){return yc(Dd.data.targets)?0:Md?Md:hg?be*(nf&&!Xe?1.25:1):nf?rf||Xe?1:u("y2"):1}function u(){return 40}function v(){return+g.select(Id).style("width").replace("px","")}function w()
}).attr("class",Qb),n.style("opacity",Tb).transition().duration(D).attr("d",z).style("opacity",1),n.exit().transition().duration(D).style("opacity",0).remove(),sg.selectAll(".-line").style("opacity",Tb).transition().duration(D).attr("d",ng).style("opacity",1))),rg.selectAll(".selected-circles").filter(function(a){return Bc(a)}).selectAll("circle").remove(),rg.selectAll(".selected-circle").transition().duration(D).attr("cx",Xe?mc:lc).attr("cy",Xe?lc:mc),Ce?(o=rg.select(".event-rects").selectAll(".event-rect").data([0]),jd(o.enter()),o.attr("x",0).attr("y",0).attr("width",Wd).attr("height",Yd)):(Yf?(r=function(a,b){var c=ub(b),d=vb(b);return(re(d?d:a.x+50)-re(c?c:a.x-50))/2},q=function(a,b){var c=ub(b);return(re(a.x)+re(c?c:a.x-50))/2}):(r=B(),q=function(a){return re(a.x)-r/2}),p=xb(),rg.select(".event-rects").datum(p?p.values:[]),o=rg.select(".event-rects").selectAll(".event-rect").data(function(a){return a}),id(o.enter()),o.attr("class",Sb).attr("x",Xe?0:q).attr("y",Xe?q:0).attr("width",Xe?Wd:r).attr("height",Xe?r:Yd),o.exit().remove()),l=rg.select(".regions").selectAll("rect.region").data(Mf),l.enter().append("rect").style("fill-opacity",0),l.attr("class",Rb).attr("x",Xe?0:ib).attr("y",Xe?ib:Td.top).attr("width",Xe?Wd:jb).attr("height",Xe?jb:Yd).transition().duration(D).style("fill-opacity",function(a){return c(a.opacity)?a.opacity:.1}),l.exit().transition().duration(D).style("fill-opacity",0).remove(),Ue&&yd(Dd.data.targets,{withTransition:u}),yb().forEach(function(a){yg[a]=!0})}function pd(){od({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}function qd(){return"mousemove"===g.event.sourceEvent.type&&og.altDomain?(re.domain(og.altDomain),void og.scale(re).updateScaleExtent()):(Xf&&re.orgDomain()[0]===wg[0]&&re.domain([wg[0]-1e-10,re.orgDomain()[1]]),od({withTransition:!1,withY:!1,withSubchart:!1}),void("mousemove"===g.event.sourceEvent.type&&(_f=!0)))}function rd(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a}function sd(a){var b,c;a=e(a)?a:{},b=e(a.withTransition)?a.withTransition:!1,c=e(a.withTransform)?a.withTransform:!1,n(),E(),kg.scale(ue),Nd&&og.scale(re),pg.attr("width",$d).attr("height",_d),pg.select("#"+Uf).select("rect").attr("width",Wd).attr("height",Yd),pg.select("#xaxis-clip").select("rect").attr("width",x),pg.select(".zoom-rect").attr("width",Wd).attr("height",Yd),m(b),od({withTransition:b,withUpdateXDomain:!0,withTransform:c,durationForExit:0})}function td(a){var b,c,d,e,f,h,i,j,k,l,m,n;i=rg.select(".chart-texts").selectAll(".chart-text").data(a),j=i.enter().append("g").attr("class",function(a){return"chart-text target target-"+a.id}).style("pointer-events","none"),j.append("g").attr("class",Hb).style("fill",function(a){return ag(a.id)}),e=rg.select(".chart-bars").selectAll(".chart-bar").data(a),d=e.enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}).style("pointer-events","none"),d.append("g").attr("class",Lb).style("fill",function(a){return ag(a.id)}).style("stroke","none").style("cursor",function(a){return Qe(a)?"pointer":null}),c=rg.select(".chart-lines").selectAll(".chart-line").data(a),b=c.enter().append("g").attr("class",function(a){return"chart-line target target-"+a.id}).style("pointer-events","none"),b.append("path").attr("class",Jb).style("opacity",0).style("stroke",function(a){return ag(a.id)}),b.append("path").attr("class",Nb).style("opacity",function(){return xg=+g.select(this).style("opacity"),0}).style("fill",function(a){return ag(a.id)}),b.append("g").attr("class",function(a){return"selected-circles selected-circles-"+a.id}),b.append("g").attr("class",Kb).style("fill",function(a){return ag(a.id)}).style("cursor",function(a){return Qe(a)?"pointer":null}),a.forEach(function(a){var b=zd(a.id);rg.selectAll(".selected-circles"+b).selectAll(".selected-circle").each(function(b){b.value=a.values[b.x].value})}),h=rg.select(".chart-arcs").selectAll(".chart-arc").data(ie(a)),f=h.enter().append("g").attr("class",function(a){return"chart-arc target target-"+a.data.id}),f.append("path").attr("class",Mb).st