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
63 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.28"},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",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",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;yi.attr("transform",ji.main),yi.select("."+f.axisX).transition().duration(b).attr("transform",ji.x),yi.select("."+f.axisY).transition().duration(b).attr("transform",ji.y),yi.select("."+f.axisY2).attr("transform",ji.y2),yi.select("."+f.chartArcs).attr("transform",ji.arc)}function k(){yg&&(zi.attr("transform",ji.context),zi.select("."+f.axisX).attr("transform",ji.subx))}function l(a){var b=a!==!1?250:0;Bg&&Ai.transition().duration(b).attr("transform",ji.legend)}function m(a){j(a),k(a),l(a)}function n(){yf=r(),zf=s(),Af=Q(),Bf=P(),rf={top:Fg?w("y2"):qi,right:u(),bottom:w(Fg?"y":"x")+(Fg?0:zg)+(ki?0:Af),left:(Fg?zg+pi:0)+t()},uf=yf-rf.left-rf.right,wf=zf-rf.top-rf.bottom,0>uf&&(uf=0),0>wf&&(wf=0),sf={top:Fg?rf.top:zf-zg-(ki?0:Af),right:0/0,bottom:20+(ki?0:Af),left:Fg?oi:rf.left},vf=Fg?rf.left-oi-pi:uf,xf=Fg?wf:zf-sf.top-sf.bottom,0>vf&&(vf=0),0>xf&&(xf=0),tf={top:ki?0:zf-Af,right:0/0,bottom:0,left:ki?yf-Bf:0},p(),ki&&Rd(df.data.targets)&&(tf.left=uf/2+Df)}function o(){yi.select("line."+f.xgridFocus).attr("x1",Fg?0:-10).attr("x2",Fg?uf:-10).attr("y1",Fg?-10:rf.top).attr("y2",Fg?-10:wf)}function p(){Df=wf/2,Cf=.95*Df,Ef=Qd(df.data.targets)?.6*Cf:0}function q(){var a=Fg?f.axisX:f.axisY,b=cf.select("."+a).node(),c=b?b.getBoundingClientRect():{right:0},d=cf.select(ff).node().getBoundingClientRect(),e=c.right-d.left-t();return e>0?e:0}function r(){return gf?gf:x()}function s(){var a=hf?hf:y();return a>0?a:320}function t(){return Rd(df.data.targets)?0:jf?jf:Fg||!Sg||Xg?1:v("y")}function u(){var a=1;return Rd(df.data.targets)?0:kf?kf:ki?Bf+(_g&&!Fg?v("y2"):a):_g?eh||Fg?a:v("y2"):a}function v(a){var b=gb(a);return b.isInner?20+zb(a):40+zb(a)}function w(a){return"y"!==a||Sg?"y2"!==a||_g?(gb(a).isInner?30:40)+("y2"===a?-10:0):qi:Bg&&!ki?10:1}function x(){return+cf.select(ff).style("width").replace("px","")}function y(){return+cf.select(ff).style("height").replace("px","")}function z(a){return a?-5:-(rf.left-1)}function A(a){return a?-20:-1}function B(){return z(!Fg)}function C(){return A(!Fg)}function D(){return z(Fg)}function E(){return A(Fg)}function F(a){return a?uf+2+4:rf.left+20}function G(a){return a?80:wf+2}function H(){return F(!Fg)}function I(){return G(!Fg)}function J(){return F(Fg)}function K(){retu
}Bi.html(Lh(df.data.targets.map(function(a){return jc(a.values[Nh])}),$(),kd,bi)),Bi.style("top",Oh.top).style("left",Oh.left).style("display","block")}null==a.onresize&&(a.onresize=Me()),a.onresize.add&&a.onresize.add(function(){Oe({withTransition:!1,withLegend:!0})})}function De(a){a.append("rect").attr("class",$c).style("cursor",ng&&og?"pointer":null).on("mouseover",function(a,b){if(!Zh&&!Rd(df.data.targets)){var c,d,e=df.data.targets.map(function(a){return jc(a.values[b])});if(Object.keys(dg).length>0){d=[];for(var g in dg)for(c=0;c<e.length;c++)if(e[c].id===g){d.push(e[c]),e.shift(c);break}e=d.concat(e)}rh&&re(b),ue(b),yi.selectAll("."+f.shape+"-"+b).each(function(a){sg(a)})}}).on("mouseout",function(a,b){Rd(df.data.targets)||(Dd(),Bd(),se(b),ve(),yi.selectAll("."+f.shape+"-"+b).each(function(a){tg(a)}))}).on("mousemove",function(a,b){var c;Zh||Rd(df.data.targets)||(c=Bc(df.data.targets).map(function(a){return jc(a.values[b])}),Ad(c,cf.mouse(this)),Cd(c),ng&&(og||yi.selectAll("."+f.shape+"-"+b).filter(function(a){return pg(a)}).each(function(){var a=cf.select(this).classed(f.EXPANDED,!0);"circle"===this.nodeName&&a.attr("r",sh),wi.select("."+f.eventRect+"-"+b).style("cursor",null)}).filter(function(){return"circle"===this.nodeName?ce(this,th):"path"===this.nodeName?de(this):void 0}).each(function(){var a=cf.select(this);a.classed(f.EXPANDED)||(a.classed(f.EXPANDED,!0),"circle"===this.nodeName&&a.attr("r",th)),wi.select("."+f.eventRect+"-"+b).style("cursor","pointer")})))}).on("click",function(a,b){return Rd(df.data.targets)?void 0:$h?void($h=!1):void yi.selectAll("."+f.shape+"-"+b).each(function(a){Fe(this,a,b)})}).call(cf.behavior.drag().origin(Object).on("drag",function(){Ge(cf.mouse(this))}).on("dragstart",function(){He(cf.mouse(this))}).on("dragend",function(){Ie()})).call(vi).on("dblclick.zoom",null)}function Ee(a){a.append("rect").attr("x",0).attr("y",0).attr("width",uf).attr("height",wf).attr("class",f.eventRect).on("mouseout",function(){Rd(df.data.targets)||(Dd(),Bd(),se())}).on("mousemove",function(){var a,b,c,d;Zh||Rd(df.data.targets)||(a=cf.mouse(this),b=td(df.data.targets,a),c=vd(df.data.targets,b.x),d=c.map(function(a){return jc(a)}),Ad(d,a),rh&&(se(),re(b.index,b.id)),Cd(d),he(b,a)<100?(wi.select("."+f.eventRect).style("cursor","pointer"),_h||(sg(b),_h=!0)):(wi.select("."+f.eventRect).style("cursor",null),tg(b),_h=!1))}).on("click",function(){var a,b;Rd(df.data.targets)||(a=cf.mouse(this),b=td(df.data.targets,a),he(b,a)<100&&yi.select("."+f.circles+"-"+_c(b.id)).select("."+f.circle+"-"+b.index).each(function(){Fe(this,b,b.index)}))}).call(cf.behavior.drag().origin(Object).on("drag",function(){Ge(cf.mouse(this))}).on("dragstart",function(){He(cf.mouse(this))}).on("dragend",function(){Ie()})).call(vi).on("dblclick.zoom",null)}function Fe(a,b,c){var d,e=cf.select(a),g=e.classed(f.SELECTED),h=!1;"circle"===a.nodeName?(h=ce(a,1.5*th),d=le):"path"===a.nodeName&&(h=de(a),d=oe),(og||h)&&(ng&&pg(b)&&(qg||yi.selectAll("."+f.shapes+(og?_c(b.id):"")).selectAll("."+f.shape).each(function(a,b){var c=cf.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)),rg(b,a))}function Ge(a){var b,c,d,e,g,h,i,j;Rd(df.data.targets)||ng&&(!lf||vi.altDomain)&&qg&&(b=Yh[0],c=Yh[1],d=a[0],e=a[1],g=Math.min(b,d),h=Math.max(b,d),i=og?rf.top:Math.min(c,e),j=og?wf:Math.max(c,e),yi.select("."+f.dragarea).attr("x",g).attr("y",i).attr("width",h-g).attr("height",j-i),yi.selectAll("."+f.shapes).selectAll("."+f.shape).filter(function(a){return pg(a)}).each(function(a,b){var c,d,e,k,l,m,n=cf.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=le,q=c>g&&h>c&&d>i&&j>d):"path"===this.nodeName&&(m=wd(this),c=m.x,d=m.y,e=m.width,k=m.height,l=oe,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 He(a){Rd(df.data.targets)||ng&&(Yh=a,yi.select("."+f.chart).append("rect").attr("class",f.dragarea).style("opacity",.1),Zh=!0,wg())}function Ie(){Rd(df.data.targets)||n
},df.legend.show=function(a){Bg&&(Xe(wc(a)),Je({withTransitionForHorizontalAxis:!1}))},df.legend.hide=function(a){Bg&&(Ye(wc(a)),Je({withTransitionForHorizontalAxis:!1}))},df.resize=function(a){gf=a?a.width:null,hf=a?a.height:null,Oe({withLegend:!0,withTransition:!1})},df.destroy=function(){df.data.targets=void 0,df.data.x={},Ci.html(""),a.onresize=null},"url"in e.data)cf.csv(e.data.url,function(a,b){Ce(b)});else if("rows"in e.data)Ce(nc(e.data.rows));else{if(!("columns"in e.data))throw Error("url or rows or columns is required.");Ce(oc(e.data.columns))}return df},"function"==typeof a.define&&a.define.amd?a.define("c3",["d3"],e):a.c3=e}(window);