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.

1 line
180 KiB

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.c3=e()}(this,function(){"use strict";function t(t,e){function i(t,e){t.attr("transform",function(t){return"translate("+Math.ceil(e(t)+w)+", 0)"})}function n(t,e){t.attr("transform",function(t){return"translate(0,"+Math.ceil(e(t))+")"})}function a(t){var e=t[0],i=t[t.length-1];return e<i?[e,i]:[i,e]}function o(t){var e,i,n=[];if(t.ticks)return t.ticks.apply(t,p);for(i=t.domain(),e=Math.ceil(i[0]);e<i[1];e++)n.push(e);return n.length>0&&n[0]>0&&n.unshift(n[0]-(n[1]-n[0])),n}function s(){var t,i=_.copy();return e.isCategory&&(t=_.domain(),i.domain([t[0],t[1]-1])),i}function c(t){var e=g?g(t):t;return void 0!==e?e:""}function d(t){if(r)return r;var e={h:11.5,w:5.5};return t.select("text").text(c).each(function(t){var i=this.getBoundingClientRect(),n=c(t),a=i.height,r=n?i.width/n.length:void 0;a&&r&&(e.h=a,e.w=r)}).text(""),r=e,e}function l(i){return e.withoutTransition?i:t.transition(i)}function u(r){r.each(function(){function r(t,i){function n(t,e){r=void 0;for(var s=1;s<e.length;s++)if(" "===e.charAt(s)&&(r=s),a=e.substr(0,s+1),o=z.w*a.length,i<o)return n(t.concat(e.substr(0,r||s)),e.slice(r?r+1:s));return t.concat(e)}var a,r,o,s=c(t),d=[];return"[object Array]"===Object.prototype.toString.call(s)?s:((!i||i<=0)&&(i=Y?95:e.isCategory?Math.ceil(P(L[1])-P(L[0]))-12:110),n(d,s+""))}function g(t,e){var i=z.h;return 0===e&&(i="left"===x||"right"===x?-((B[t.index]-1)*(z.h/2)-3):".71em"),i}var p,v,b,A=u.g=t.select(this),T=this.__chart__||_,P=this.__chart__=s(),L=S||o(P),C=A.selectAll(".tick").data(L,P),V=C.enter().insert("g",".domain").attr("class","tick").style("opacity",1e-6),G=C.exit().remove(),E=l(C).style("opacity",1),I=_.rangeExtent?_.rangeExtent():a(_.range()),O=A.selectAll(".domain").data([0]),R=(O.enter().append("path").attr("class","domain"),l(O));V.append("line"),V.append("text");var D=V.select("line"),F=E.select("line"),X=V.select("text"),k=E.select("text");e.isCategory?(w=Math.ceil((P(1)-P(0))/2),v=f?0:w,b=f?w:0):w=v=0;var M,H,z=d(A.select(".tick")),B=[],N=Math.max(y,0)+m,Y="left"===x||"right"===x;(H=(M=C.select("text")).selectAll("tspan").data(function(t,i){var n=e.tickMultiline?r(t,e.tickWidth):[].concat(c(t));return B[i]=n.length,n.map(function(t){return{index:i,splitted:t}})})).enter().append("tspan"),H.exit().remove(),H.text(function(t){return t.splitted});var j=e.tickTextRotate;switch(x){case"bottom":p=i,D.attr("y2",y),X.attr("y",N),F.attr("x1",v).attr("x2",v).attr("y2",function(t){var e=_(t)+(f?0:w);return I[0]<e&&e<I[1]?y:0}),k.attr("x",0).attr("y",function(t){return t?11.5-t/15*2.5*(t>0?1:-1):N}(j)).style("text-anchor",function(t){return t?t>0?"start":"end":"middle"}(j)).attr("transform",function(t){return t?"rotate("+t+")":""}(j)),H.attr("x",0).attr("dy",g).attr("dx",function(t){return t?8*Math.sin(Math.PI*(t/180)):0}(j)),R.attr("d","M"+I[0]+","+h+"V0H"+I[1]+"V"+h);break;case"top":p=i,D.attr("y2",-y),X.attr("y",-N),F.attr("x2",0).attr("y2",-y),k.attr("x",0).attr("y",-N),M.style("text-anchor","middle"),H.attr("x",0).attr("dy","0em"),R.attr("d","M"+I[0]+","+-h+"V0H"+I[1]+"V"+-h);break;case"left":p=n,D.attr("x2",-y),X.attr("x",-N),F.attr("x2",-y).attr("y1",b).attr("y2",b),k.attr("x",-N).attr("y",w),M.style("text-anchor","end"),H.attr("x",-N).attr("dy",g),R.attr("d","M"+-h+","+I[0]+"H0V"+I[1]+"H"+-h);break;case"right":p=n,D.attr("x2",y),X.attr("x",N),F.attr("x2",y).attr("y2",0),k.attr("x",N).attr("y",0),M.style("text-anchor","start"),H.attr("x",N).attr("dy",g),R.attr("d","M"+h+","+I[0]+"H0V"+I[1]+"H"+h)}if(P.rangeBand){var U=P,W=U.rangeBand()/2;T=P=function(t){return U(t)+W}}else T.rangeBand?T=P:G.call(p,P);V.call(p,T),E.call(p,P)})}var h,g,p,f,_=t.scale.linear(),x="bottom",y=6,m=3,S=null,w=0,v=!0;return e=e||{},h=e.withOuterTick?6:0,u.scale=function(t){return arguments.length?(_=t,u):_},u.orient=function(t){return arguments.length?(x=t in{top:1,right:1,bottom:1,left:1}?t+"":"bottom",u):x},u.tickFormat=function(t){return arguments.length?(g=t,u):g},u.tickCentered=function(t){r