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

11 years ago
!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}var e={version:"0.1.32"},f={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",bar:"c3-bar",bars:"c3-bars",circle:"c3-circle",circles:"c3-circles",arc:"c3-arc",area:"c3-area",text:"c3-text",texts:"c3-texts",grid:"c3-grid",xgrid:"c3-xgrid",xgrids:"c3-xgrids",xgridLine:"c3-xgrid-line",xgridLines:"c3-xgrid-lines",xgridFocus:"c3-xgrid-focus",ygrid:"c3-ygrid",ygrids:"c3-ygrids",ygridLine:"c3-ygrid-line",ygridLines:"c3-ygrid-lines",axisX:"c3-axis-x",axisXLabel:"c3-axis-x-label",axisY:"c3-axis-y",axisYLabel:"c3-axis-y-label",axisY2:"c3-axis-y2",axisY2Label:"c3-axis-y2-label",legendItem:"c3-legend-item",legendItemEvent:"c3-legend-item-event",legendItemTile:"c3-legend-item-tile",legendItemHidden:"c3-legend-item-hidden",dragarea:"c3-dragarea",EXPANDED:"_expanded_",SELECTED:"_selected_",INCLUDED:"_included_"};e.generate=function(e){function g(a,b){if(!(a in e))throw Error(b)}function h(a,b){var c,d,f,g=e;for(c=0;c<a.length;c++){if("object"==typeof g&&!(a[c]in g))return b;if(d=c===a.length-1,f=g[a[c]],!d&&"object"!=typeof f||d&&"object"!=typeof b&&"object"==typeof f&&null!==f)return b;g=f}return g}function i(a){return"url("+document.URL.split("#")[0]+"#"+a+")"}function j(a,b){var c=a!==!1?250:0,d=b&&b.axisX?b.axisX:aj.select("."+f.axisX).transition().duration(c),e=b&&b.axisY?b.axisY:aj.select("."+f.axisY).transition().duration(c),g=b&&b.axisYs?b.axisY2:aj.select("."+f.axisY2).transition().duration(c);aj.attr("transform",Mi.main),d.attr("transform",Mi.x),e.attr("transform",Mi.y),g.attr("transform",Mi.y2),aj.select("."+f.chartArcs).attr("transform",Mi.arc)}function k(a,b){var c=a!==!1?250:0,d=b&&b.axisSubX?b.axisSubX:bj.select("."+f.axisX).transition().duration(c);bj.attr("transform",Mi.context),d.attr("transform",Mi.subx)}function l(a){var b=a!==!1?250:0;cj.transition().duration(b).attr("transform",Mi.legend)}function m(a,b){j(a,b),Pg&&k(a,b),l(a)}function n(){var a=Q(),b=P(),c=Ni?0:a,d=Yg?0:w("x"),e=Pg?Qg+d:0;Qf=r(),Rf=s(),Yg?(Jf={top:w("y2"),right:u(),bottom:w("y")+c,left:e+t()},Kf={top:Jf.top,right:0/0,bottom:20+c,left:Si}):(Jf={top:4,right:u(),bottom:d+e+c,left:t()},Kf={top:Rf-e-c,right:0/0,bottom:d+c,left:Jf.left}),Lf={top:Ni?0:Rf-a,right:0/0,bottom:0,left:Ni?Qf-b:0},Mf=Qf-Jf.left-Jf.right,Of=Rf-Jf.top-Jf.bottom,0>Mf&&(Mf=0),0>Of&&(Of=0),Nf=Yg?Jf.left-Si-Ti:Mf,Pf=Yg?Of:Rf-Kf.top-Kf.bottom,0>Nf&&(Nf=0),0>Pf&&(Pf=0),p(),Ni&&be(uf.data.targets)&&(Lf.left=Mf/2+Tf)}function o(){aj.select("line."+f.xgridFocus).attr("x1",Yg?0:-10).attr("x2",Yg?Mf:-10).attr("y1",Yg?-10:Jf.top).attr("y2",Yg?-10:Of)}function p(){Tf=Of/2,Sf=.95*Tf,Uf=ae(uf.data.targets)?.6*Sf:0}function q(){var a=Yg?f.axisX:f.axisY,b=tf.select("."+a).node(),c=b?b.getBoundingClientRect():{right:0},d=tf.select(wf).node().getBoundingClientRect(),e=c.right-d.left-t();return e>0?e:0}function r(){return xf?xf:x()}function s(){var a=yf?yf:y();return a>0?a:320}function t(){return be(uf.data.targets)?0:zf?zf:Yg?Zg?v("x"):1:!ph||uh?1:v("y")}function u(){var a=1;return be(uf.data.targets)?0:Af?Af:Ni?P()+(yh&&!Yg?v("y2"):a):yh?Dh||Yg?a:v("y2"):a}function v(a){var b=jb(a);return b.isInner?20+Cb(a):40+Cb(a)}function w(a){return"x"!==a||Zg?"x"===a&&mh?mh:"y"!==a||ph?"y2"!==a||yh?(jb(a).isInner?30:40)+("y2"===a?-10:0):Ui:Sg&&!Ni?10:1:0}function x(){return+tf.select(wf).style("width").replace("px","")}function y(){r
11 years ago
}dj.html(li(uf.data.targets.map(function(a){return pc(a.values[ni])}),$(),wd,Di)),dj.style("top",oi.top).style("left",oi.left).style("display","block")}null==a.onresize&&(a.onresize=$e()),a.onresize.add&&(a.onresize.add(Gf),a.onresize.add(function(){af({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})}),a.onresize.add(Hf))}function Re(a){a.append("rect").attr("class",fd).style("cursor",Eg&&Fg?"pointer":null).on("mouseover",function(a,b){if(!zi&&!be(uf.data.targets)){var c,d,e=uf.data.targets.map(function(a){return pc(a.values[b])});if(Object.keys(tg).length>0){d=[];for(var g in tg)for(c=0;c<e.length;c++)if(e[c].id===g){d.push(e[c]),e.shift(c);break}e=d.concat(e)}Qh&&Fe(b),Ie(b),aj.selectAll("."+f.shape+"-"+b).each(function(a){Jg(a)})}}).on("mouseout",function(a,b){be(uf.data.targets)||(Pd(),Nd(),Ge(b),Je(),aj.selectAll("."+f.shape+"-"+b).each(function(a){Kg(a)}))}).on("mousemove",function(a,b){var c;zi||be(uf.data.targets)||(c=Ic(uf.data.targets).map(function(a){return pc(a.values[b])}),Md(c,tf.mouse(this)),Od(c),Eg&&(Fg||aj.selectAll("."+f.shape+"-"+b).filter(function(a){return Gg(a)}).each(function(){var a=tf.select(this).classed(f.EXPANDED,!0);"circle"===this.nodeName&&a.attr("r",Rh),$i.select("."+f.eventRect+"-"+b).style("cursor",null)}).filter(function(){return"circle"===this.nodeName?pe(this,Sh):"path"===this.nodeName?qe(this):void 0}).each(function(){var a=tf.select(this);a.classed(f.EXPANDED)||(a.classed(f.EXPANDED,!0),"circle"===this.nodeName&&a.attr("r",Sh)),$i.select("."+f.eventRect+"-"+b).style("cursor","pointer")})))}).on("click",function(a,b){return be(uf.data.targets)?void 0:Ai?void(Ai=!1):void aj.selectAll("."+f.shape+"-"+b).each(function(a){Te(this,a,b)})}).call(tf.behavior.drag().origin(Object).on("drag",function(){Ue(tf.mouse(this))}).on("dragstart",function(){Ve(tf.mouse(this))}).on("dragend",function(){We()})).call(Zi).on("dblclick.zoom",null)}function Se(a){a.append("rect").attr("x",0).attr("y",0).attr("width",Mf).attr("height",Of).attr("class",f.eventRect).on("mouseout",function(){be(uf.data.targets)||(Pd(),Nd(),Ge())}).on("mousemove",function(){var a,b,c,d,e=Ic(uf.data.targets);zi||be(e)||(a=tf.mouse(this),b=Fd(e,a),b&&(c=fe(b)?[b]:Hd(e,b.x),d=c.map(function(a){return pc(a)}),Md(d,a),Qh&&(Ge(),Fe(b.index,b.id)),Od(d),ve(b,a)<100?($i.select("."+f.eventRect).style("cursor","pointer"),Bi||(Jg(b),Bi=!0)):($i.select("."+f.eventRect).style("cursor",null),Kg(b),Bi=!1)))}).on("click",function(){var a,b,c=Ic(uf.data.targets);be(c)||(a=tf.mouse(this),b=Fd(c,a),b&&ve(b,a)<100&&aj.select("."+f.circles+"-"+ld(b.id)).select("."+f.circle+"-"+b.index).each(function(){Te(this,b,b.index)}))}).call(tf.behavior.drag().origin(Object).on("drag",function(){Ue(tf.mouse(this))}).on("dragstart",function(){Ve(tf.mouse(this))}).on("dragend",function(){We()})).call(Zi).on("dblclick.zoom",null)}function Te(a,b,c){var d,e=tf.select(a),g=e.classed(f.SELECTED),h=!1;"circle"===a.nodeName?(h=pe(a,1.5*Sh),d=ze):"path"===a.nodeName&&(h=qe(a),d=Ce),(Fg||h)&&(Eg&&Gg(b)&&(Hg||aj.selectAll("."+f.shapes+(Fg?ld(b.id):"")).selectAll("."+f.shape).each(function(a,b){var c=tf.select(this);c.classed(f.SELECTED)&&d(!1,c.classed(f.SELECTED,!1),a,b)}),e.classed(f.SELECTED,!g),d(!g,e,b,c)),Ig(b,a))}function Ue(a){var b,c,d,e,g,h,i,j;be(uf.data.targets)||Eg&&(!Bf||Zi.altDomain)&&Hg&&(b=yi[0],c=yi[1],d=a[0],e=a[1],g=Math.min(b,d),h=Math.max(b,d),i=Fg?Jf.top:Math.min(c,e),j=Fg?Of:Math.max(c,e),aj.select("."+f.dragarea).attr("x",g).attr("y",i).attr("width",h-g).attr("height",j-i),aj.selectAll("."+f.shapes).selectAll("."+f.shape).filter(function(a){return Gg(a)}).each(function(a,b){var c,d,e,k,l,m,n=tf.select(this),o=n.classed(f.SELECTED),p=n.classed(f.INCLUDED),q=!1;"circle"===this.nodeName?(c=1*n.attr("cx"),d=1*n.attr("cy"),l=ze,q=c>g&&h>c&&d>i&&j>d):"path"===this.nodeName&&(m=Id(this),c=m.x,d=m.y,e=m.width,k=m.height,l=Ce,q=!(c>h||g>c+e||d>j||i>d+k)),q^p&&(n.classed(f.INCLUDED,!p),n.classed(f.SELECTED,!o),l(!o,n,a,b))}))}function Ve(a){be(uf.data.targets)||Eg&&(yi=a,aj.select("."+f.chart).append("rect").attr("class",f.dragarea).style(
},uf.ygrids.remove=function(a){var b=rf(a);return uf.ygrids(Lh.filter(b))},uf.regions=function(a){return c(a)?hi:(hi=a,Xe(),hi)},uf.regions.add=function(a){return c(a)?hi:(hi=hi.concat(a),Xe(),hi)},uf.regions.remove=function(a,c){var e=[].concat(a);return c=d(c)?c:{},e.forEach(function(a){var d=b(c.duration)?c.duration:0;$i.selectAll("."+a).transition().duration(d).style("fill-opacity",0).remove(),hi=hi.filter(function(b){return b.classes.indexOf(a)<0})}),hi},uf.data.get=function(a){var b=uf.data.getAsTarget(a);return d(b)?b.values.map(function(a){return a.value}):void 0},uf.data.getAsTarget=function(a){var b=Fc(function(b){return b.id===a});return b.length>0?b[0]:void 0},uf.data.names=function(a){return arguments.length?(Object.keys(a).forEach(function(b){tg[b]=a[b]}),of(Cc(uf.data.targets),{withTransition:!0}),tg):tg},uf.x=function(a){return arguments.length&&(qc(uf.data.targets,a),Xe({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),uf.data.xs},uf.xs=function(a){return arguments.length&&(rc(uf.data.targets,a),Xe({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),uf.data.xs},uf.axis.labels=function(a){arguments.length&&(Object.keys(a).forEach(function(b){bb(b,a[b])}),Db())},uf.axis.max=function(a){arguments.length&&("object"==typeof a?(b(a.y)&&(qh=+a.y),b(a.y2)&&(zh=+a.y2)):qh=zh=+a,Xe())},uf.axis.min=function(a){arguments.length&&("object"==typeof a?(b(a.y)&&(rh=+a.y),b(a.y2)&&(Ah=+a.y2)):rh=Ah=+a,Xe())},uf.axis.range=function(a){arguments.length&&("undefined"!=typeof a.max&&uf.axis.max(a.max),"undefined"!=typeof a.min&&uf.axis.min(a.min))},uf.legend.show=function(a){Sg||(Sg=!0,cj.style("visibility","visible")),mf(Dc(a)),Xe({withLegend:!0})},uf.legend.hide=function(a){nf(Dc(a)),Xe({withLegend:!0}),Sg&&se(a)&&(Sg=!1,cj.style("visibility","hidden"))},uf.resize=function(a){xf=a?a.width:null,yf=a?a.height:null,af({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},uf.destroy=function(){uf.data.targets=void 0,uf.data.xs={},ej.html(""),a.onresize=null},"url"in e.data)tf.xhr(e.data.url,function(a,b){var c,d=tf.csv.parseRows(b.response);1===d.length?(c=[{}],d[0].forEach(function(a){c[0][a]=null})):c=tf.csv.parse(b.response),Qe(c)});else if("rows"in e.data)Qe(tc(e.data.rows));else{if(!("columns"in e.data))throw Error("url or rows or columns is required.");Qe(uc(e.data.columns))}return uf},"function"==typeof a.define&&a.define.amd?a.define("c3",["d3"],e):a.c3=e}(window);