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
179 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=f.copy();return e.isCategory&&(t=f.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=B.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=j?95:e.isCategory?Math.ceil(L(C[1])-L(C[0]))-12:110),n(d,s+""))}function g(t,e){var i=B.h;return 0===e&&(i="left"===x||"right"===x?-((N[t.index]-1)*(B.h/2)-3):".71em"),i}function p(t){var e=f(t)+(_?0:w);return O[0]<e&&e<O[1]?y:0}var v,b,A,T=u.g=t.select(this),P=this.__chart__||f,L=this.__chart__=s(),C=S||o(L),V=T.selectAll(".tick").data(C,L),G=V.enter().insert("g",".domain").attr("class","tick").style("opacity",1e-6),E=V.exit().remove(),I=l(V).style("opacity",1),O=f.rangeExtent?f.rangeExtent():a(f.range()),R=T.selectAll(".domain").data([0]),D=(R.enter().append("path").attr("class","domain"),l(R));G.append("line"),G.append("text");var F=G.select("line"),X=I.select("line"),k=G.select("text"),M=I.select("text");e.isCategory?(w=Math.ceil((L(1)-L(0))/2),b=_?0:w,A=_?w:0):w=b=0;var H,z,B=d(T.select(".tick")),N=[],Y=Math.max(y,0)+m,j="left"===x||"right"===x;(z=(H=V.select("text")).selectAll("tspan").data(function(t,i){var n=e.tickMultiline?r(t,e.tickWidth):[].concat(c(t));return N[i]=n.length,n.map(function(t){return{index:i,splitted:t}})})).enter().append("tspan"),z.exit().remove(),z.text(function(t){return t.splitted});var U=e.tickTextRotate;switch(x){case"bottom":v=i,F.attr("y2",y),k.attr("y",Y),X.attr("x1",b).attr("x2",b).attr("y2",p),M.attr("x",0).attr("y",function(t){return t?11.5-t/15*2.5*(t>0?1:-1):Y}(U)).style("text-anchor",function(t){return t?t>0?"start":"end":"middle"}(U)).attr("transform",function(t){return t?"rotate("+t+")":""}(U)),z.attr("x",0).attr("dy",g).attr("dx",function(t){return t?8*Math.sin(Math.PI*(t/180)):0}(U)),D.attr("d","M"+O[0]+","+h+"V0H"+O[1]+"V"+h);break;case"top":v=i,F.attr("y2",-y),k.attr("y",-Y),X.attr("x2",0).attr("y2",-y),M.attr("x",0).attr("y",-Y),H.style("text-anchor","middle"),z.attr("x",0).attr("dy","0em"),D.attr("d","M"+O[0]+","+-h+"V0H"+O[1]+"V"+-h);break;case"left":v=n,F.attr("x2",-y),k.attr("x",-Y),X.attr("x2",-y).attr("y1",A).attr("y2",A),M.attr("x",-Y).attr("y",w),H.style("text-anchor","end"),z.attr("x",-Y).attr("dy",g),D.attr("d","M"+-h+","+O[0]+"H0V"+O[1]+"H"+-h);break;case"right":v=n,F.attr("x2",y),k.attr("x",Y),X.attr("x2",y).attr("y2",0),M.attr("x",Y).attr("y",0),H.style("text-anchor","start"),z.attr("x",Y).attr("dy",g),D.attr("d","M"+h+","+O[0]+"H0V"+O[1]+"H"+h)}if(L.rangeBand){var W=L,Q=W.rangeBand()/2;P=L=function(t){return W(t)+Q}}else P.rangeBand?P=L:E.call(v,L);G.call(v,P),I.call(v,L)})}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?(f=t,u):f},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