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
66 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}var e={version:"0.1.31"},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){var b=a!==!1?250:0;Xi.attr("transform",Hi.main),Xi.select("."+f.axisX).transition().duration(b).attr("transform",Hi.x),Xi.select("."+f.axisY).transition().duration(b).attr("transform",Hi.y),Xi.select("."+f.axisY2).attr("transform",Hi.y2),Xi.select("."+f.chartArcs).attr("transform",Hi.arc)}function k(){Mg&&(Yi.attr("transform",Hi.context),Yi.select("."+f.axisX).attr("transform",Hi.subx))}function l(a){var b=a!==!1?250:0;Zi.transition().duration(b).attr("transform",Hi.legend)}function m(a){j(a),k(a),l(a)}function n(){var a=Q(),b=P();Nf=r(),Of=s(),Gf={top:Vg?w("y2"):0,right:u(),bottom:w(Vg?"y":"x")+(Vg?0:Ng)+(Ii?0:a),left:(Vg?Ng+Oi:0)+t()},Jf=Nf-Gf.left-Gf.right,Lf=Of-Gf.top-Gf.bottom,0>Jf&&(Jf=0),0>Lf&&(Lf=0),Hf={top:Vg?Gf.top:Of-Ng-(Ii?0:a),right:0/0,bottom:20+(Ii?0:a),left:Vg?Ni:Gf.left},Kf=Vg?Gf.left-Ni-Oi:Jf,Mf=Vg?Lf:Of-Hf.top-Hf.bottom,0>Kf&&(Kf=0),0>Mf&&(Mf=0),If={top:Ii?0:Of-a,right:0/0,bottom:0,left:Ii?Nf-b:0},p(),Ii&&$d(rf.data.targets)&&(If.left=Jf/2+Qf)}function o(){Xi.select("line."+f.xgridFocus).attr("x1",Vg?0:-10).attr("x2",Vg?Jf:-10).attr("y1",Vg?-10:Gf.top).attr("y2",Vg?-10:Lf)}function p(){Qf=Lf/2,Pf=.95*Qf,Rf=Zd(rf.data.targets)?.6*Pf:0}function q(){var a=Vg?f.axisX:f.axisY,b=qf.select("."+a).node(),c=b?b.getBoundingClientRect():{right:0},d=qf.select(tf).node().getBoundingClientRect(),e=c.right-d.left-t();return e>0?e:0}function r(){return uf?uf:x()}function s(){var a=vf?vf:y();return a>0?a:320}function t(){return $d(rf.data.targets)?0:wf?wf:Vg||!kh||ph?1:v("y")}function u(){var a=1;return $d(rf.data.targets)?0:xf?xf:Ii?P()+(th&&!Vg?v("y2"):a):th?yh||Vg?a:v("y2"):a}function v(a){var b=gb(a);return b.isInner?20+zb(a):40+zb(a)}function w(a){return"x"!==a||Wg?"y"!==a||kh?"y2"!==a||th?(gb(a).isInner?30:40)+("y2"===a?-10:0):Pi:Pg&&!Ii?10:1:0}function x(){return+qf.select(tf).style("width").replace("px","")}function y(){return+qf.select(tf).style("height").replace("px","")}function z(a){return a?-5:-(Gf.left-1)}function A(a){return a?-20:-1}function B(){return z(!Vg)}function C(){return A(!Vg)}function D(){return z(Vg)}function E(){return A(Vg)}function F(a){return a?Jf+2+4:Gf.le
}$i.html(gi(rf.data.targets.map(function(a){return nc(a.values[ii])}),$(),td,yi)),$i.style("top",ji.top).style("left",ji.left).style("display","block")}null==a.onresize&&(a.onresize=Xe()),a.onresize.add&&(a.onresize.add(Df),a.onresize.add(function(){Ze({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})}),a.onresize.add(Ef))}function Oe(a){a.append("rect").attr("class",cd).style("cursor",Bg&&Cg?"pointer":null).on("mouseover",function(a,b){if(!ui&&!$d(rf.data.targets)){var c,d,e=rf.data.targets.map(function(a){return nc(a.values[b])});if(Object.keys(qg).length>0){d=[];for(var g in qg)for(c=0;c<e.length;c++)if(e[c].id===g){d.push(e[c]),e.shift(c);break}e=d.concat(e)}Lh&&Ce(b),Fe(b),Xi.selectAll("."+f.shape+"-"+b).each(function(a){Gg(a)})}}).on("mouseout",function(a,b){$d(rf.data.targets)||(Md(),Kd(),De(b),Ge(),Xi.selectAll("."+f.shape+"-"+b).each(function(a){Hg(a)}))}).on("mousemove",function(a,b){var c;ui||$d(rf.data.targets)||(c=Fc(rf.data.targets).map(function(a){return nc(a.values[b])}),Jd(c,qf.mouse(this)),Ld(c),Bg&&(Cg||Xi.selectAll("."+f.shape+"-"+b).filter(function(a){return Dg(a)}).each(function(){var a=qf.select(this).classed(f.EXPANDED,!0);"circle"===this.nodeName&&a.attr("r",Mh),Vi.select("."+f.eventRect+"-"+b).style("cursor",null)}).filter(function(){return"circle"===this.nodeName?me(this,Nh):"path"===this.nodeName?ne(this):void 0}).each(function(){var a=qf.select(this);a.classed(f.EXPANDED)||(a.classed(f.EXPANDED,!0),"circle"===this.nodeName&&a.attr("r",Nh)),Vi.select("."+f.eventRect+"-"+b).style("cursor","pointer")})))}).on("click",function(a,b){return $d(rf.data.targets)?void 0:vi?void(vi=!1):void Xi.selectAll("."+f.shape+"-"+b).each(function(a){Qe(this,a,b)})}).call(qf.behavior.drag().origin(Object).on("drag",function(){Re(qf.mouse(this))}).on("dragstart",function(){Se(qf.mouse(this))}).on("dragend",function(){Te()})).call(Ui).on("dblclick.zoom",null)}function Pe(a){a.append("rect").attr("x",0).attr("y",0).attr("width",Jf).attr("height",Lf).attr("class",f.eventRect).on("mouseout",function(){$d(rf.data.targets)||(Md(),Kd(),De())}).on("mousemove",function(){var a,b,c,d;ui||$d(rf.data.targets)||(a=qf.mouse(this),b=Cd(rf.data.targets,a),c=ce(b)?[b]:Ed(rf.data.targets,b.x),d=c.map(function(a){return nc(a)}),Jd(d,a),Lh&&(De(),Ce(b.index,b.id)),Ld(d),se(b,a)<100?(Vi.select("."+f.eventRect).style("cursor","pointer"),wi||(Gg(b),wi=!0)):(Vi.select("."+f.eventRect).style("cursor",null),Hg(b),wi=!1))}).on("click",function(){var a,b;$d(rf.data.targets)||(a=qf.mouse(this),b=Cd(rf.data.targets,a),se(b,a)<100&&Xi.select("."+f.circles+"-"+id(b.id)).select("."+f.circle+"-"+b.index).each(function(){Qe(this,b,b.index)}))}).call(qf.behavior.drag().origin(Object).on("drag",function(){Re(qf.mouse(this))}).on("dragstart",function(){Se(qf.mouse(this))}).on("dragend",function(){Te()})).call(Ui).on("dblclick.zoom",null)}function Qe(a,b,c){var d,e=qf.select(a),g=e.classed(f.SELECTED),h=!1;"circle"===a.nodeName?(h=me(a,1.5*Nh),d=we):"path"===a.nodeName&&(h=ne(a),d=ze),(Cg||h)&&(Bg&&Dg(b)&&(Eg||Xi.selectAll("."+f.shapes+(Cg?id(b.id):"")).selectAll("."+f.shape).each(function(a,b){var c=qf.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)),Fg(b,a))}function Re(a){var b,c,d,e,g,h,i,j;$d(rf.data.targets)||Bg&&(!yf||Ui.altDomain)&&Eg&&(b=ti[0],c=ti[1],d=a[0],e=a[1],g=Math.min(b,d),h=Math.max(b,d),i=Cg?Gf.top:Math.min(c,e),j=Cg?Lf:Math.max(c,e),Xi.select("."+f.dragarea).attr("x",g).attr("y",i).attr("width",h-g).attr("height",j-i),Xi.selectAll("."+f.shapes).selectAll("."+f.shape).filter(function(a){return Dg(a)}).each(function(a,b){var c,d,e,k,l,m,n=qf.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=we,q=c>g&&h>c&&d>i&&j>d):"path"===this.nodeName&&(m=Fd(this),c=m.x,d=m.y,e=m.width,k=m.height,l=ze,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 Se(a){$d(rf.data.targets)||Bg&&(ti=a,Xi.select("."+f.chart).append("rect").attr("class",
},rf.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;Vi.selectAll("."+a).transition().duration(d).style("fill-opacity",0).remove(),ci=ci.filter(function(b){return b.classes.indexOf(a)<0})}),ci},rf.data.get=function(a){var b=rf.data.getAsTarget(a);return d(b)?b.values.map(function(a){return a.value}):void 0},rf.data.getAsTarget=function(a){var b=Cc(function(b){return b.id===a});return b.length>0?b[0]:void 0},rf.data.names=function(a){return arguments.length?(Object.keys(a).forEach(function(b){qg[b]=a[b]}),lf(zc(rf.data.targets),{withTransition:!0}),qg):qg},rf.x=function(a){return arguments.length&&(oc(rf.data.targets,a),Ue({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),rf.data.xs},rf.xs=function(a){return arguments.length&&(pc(rf.data.targets,a),Ue({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),rf.data.xs},rf.axis.labels=function(a){arguments.length&&(Object.keys(a).forEach(function(b){bb(b,a[b])}),Ab())},rf.axis.max=function(a){arguments.length&&("object"==typeof a?(b(a.y)&&(lh=+a.y),b(a.y2)&&(uh=+a.y2)):lh=uh=+a,Ue())},rf.axis.min=function(a){arguments.length&&("object"==typeof a?(b(a.y)&&(mh=+a.y),b(a.y2)&&(vh=+a.y2)):mh=vh=+a,Ue())},rf.axis.range=function(a){arguments.length&&("undefined"!=typeof a.max&&rf.axis.max(a.max),"undefined"!=typeof a.min&&rf.axis.min(a.min))},rf.legend.show=function(a){Pg||(Pg=!0,Zi.style("visibility","visible")),jf(Ac(a)),Ue({withTransitionForHorizontalAxis:!1})},rf.legend.hide=function(a){Pg&&pe(a)&&(Pg=!1,Zi.style("visibility","hidden")),kf(Ac(a)),Ue({withTransitionForHorizontalAxis:!1})},rf.resize=function(a){uf=a?a.width:null,vf=a?a.height:null,Ze({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},rf.destroy=function(){rf.data.targets=void 0,rf.data.xs={},_i.html(""),a.onresize=null},"url"in e.data)qf.xhr(e.data.url,function(a,b){var c,d=qf.csv.parseRows(b.response);1===d.length?(c=[{}],d[0].forEach(function(a){c[0][a]=null})):c=qf.csv.parse(b.response),Ne(c)});else if("rows"in e.data)Ne(rc(e.data.rows));else{if(!("columns"in e.data))throw Error("url or rows or columns is required.");Ne(sc(e.data.columns))}return rf},"function"==typeof a.define&&a.define.amd?a.define("c3",["d3"],e):a.c3=e}(window);