From 7e2c3cc2e65e01969d777f038c9f5c8c79899aae Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 24 Jan 2014 12:19:33 +0900 Subject: [PATCH] Add axis labels --- c3.js | 20 +++++---- c3.min.js | 118 +++++++++++++++++++++++++++--------------------------- 2 files changed, 72 insertions(+), 66 deletions(-) diff --git a/c3.js b/c3.js index c916c7f..7ec43cf 100644 --- a/c3.js +++ b/c3.js @@ -79,10 +79,11 @@ __axis_x_tick_centered = getConfig(['axis', 'x', 'tick', 'centered'], false), __axis_x_tick_format = getConfig(['axis', 'x', 'tick', 'format'], null), __axis_x_default = getConfig(['axis', 'x', 'default'], null), + __axis_x_label = getConfig(['axis', 'x', 'label'], null), __axis_y_max = getConfig(['axis', 'y', 'max'], null), __axis_y_min = getConfig(['axis', 'y', 'min'], null), __axis_y_center = getConfig(['axis', 'y', 'center'], null), - __axis_y_text = getConfig(['axis', 'y', 'text'], null), + __axis_y_label = getConfig(['axis', 'y', 'label'], null), // not used //__axis_y_rescale = getConfig(['axis', 'y', 'rescale'], true), __axis_y_inner = getConfig(['axis', 'y', 'inner'], false), @@ -94,7 +95,7 @@ __axis_y2_min = getConfig(['axis', 'y2', 'min'], null), __axis_y2_center = getConfig(['axis', 'y2', 'center'], null), // not used - // __axis_y2_text = getConfig(['axis', 'y2', 'text'], null), + // __axis_y2_label = getConfig(['axis', 'y2', 'text'], null), // __axis_y2_rescale = getConfig(['axis', 'y2', 'rescale'], true), __axis_y2_inner = getConfig(['axis', 'y2', 'inner'], false), __axis_y2_format = getConfig(['axis', 'y2', 'format'], function (d) { return d; }), @@ -954,7 +955,7 @@ .attr("id", "xaxis-clip") .append("rect") .attr("x", -1 - margin.left) - .attr("y", -1) + .attr("y", -20) .attr("width", getXAxisClipWidth) .attr("height", getXAxisClipHeight); defs.append("clipPath") @@ -986,17 +987,22 @@ .attr("class", "x axis") .attr("clip-path", __axis_rotated ? "" : "url(#xaxis-clip)") .attr("transform", translate.x) - .call(__axis_rotated ? yAxis : xAxis); + .call(__axis_rotated ? yAxis : xAxis) + .append("text") + .attr("x", width) + .attr("dy", "-.5em") + .style("text-anchor", "end") + .text(__axis_x_label); main.append("g") .attr("class", "y axis") .attr("clip-path", __axis_rotated ? "url(#yaxis-clip)" : "") .call(__axis_rotated ? xAxis : yAxis) .append("text") .attr("transform", "rotate(-90)") - .attr("dy", "1.4em") - .attr("dx", "-.8em") + .attr("dy", "1.2em") + .attr("dx", "-.5em") .style("text-anchor", "end") - .text(__axis_y_text); + .text(__axis_y_label); if (__axis_y2_show) { main.append("g") diff --git a/c3.min.js b/c3.min.js index 732d4fc..072d25b 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,67 +1,67 @@ -(function(ga){function wc(){function p(e,c){e.attr("transform",function(e){return"translate("+(c(e)+V)+", 0)"})}function s(e,c){e.attr("transform",function(e){return"translate(0,"+c(e)+")"})}function ga(e){var c=e[0];e=e[e.length-1];return ca?0:a}function Cb(a){var b=Ha[a.id];a.name=p(b)?b:a.id;return a}function Tb(a){var b=a[0],d={},h=[],n,e;for(n=1;na?0:a}function Cb(a){var b=Ha[a.id];a.name=p(b)?b:a.id;return a}function Tb(a){var b=a[0],d={},h=[],m,e;for(m=1;mv[d].indexOf(e.id)))for(h=0;hv[d].indexOf(e.id)))for(h=0;h=g;g+=t)r+=e(a[c-1],a[c],g,u)}return r}function rb(a){var b=k.data.targets=Ia(a),d,c;lc=e.select(ua);if(lc.empty())ga.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{Q();zb();l.domain(e.extent(a.map(function(a){return a.x})));y.domain(ia("y"));R.domain(ia("y2")); Y.domain(l.domain());Ua.domain(y.domain());Va.domain(R.domain());J.ticks(10>a.length?a.length:10);la.ticks(Vc).outerTickSize(0).tickFormat(Wc);Wa.ticks(Xc).outerTickSize(0).tickFormat(Yc);S=l.domain();F.x(Y);oa&&G.x(l);La=e.select(ua).append("svg").attr("width",q+B+A).attr("height",t+w+X).on("mouseenter",Zc).on("mouseleave",$c);ab=La.append("defs");ab.append("clipPath").attr("id",sb).append("rect").attr("y",w).attr("width",q).attr("height",t-w);ab.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x", --1-B).attr("y",-1).attr("width",V).attr("height",W);ab.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-B+1).attr("y",w-1).attr("width",ha).attr("height",eb);g=La.append("g").attr("transform",K.main);x=xa?La.append("g").attr("transform",K.context):null;ya=za?La.append("g").attr("transform",K.legend):null;ca=e.select(ua).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden");g.append("g").attr("class", -"x axis").attr("clip-path",f?"":"url(#xaxis-clip)").attr("transform",K.x).call(f?la:J);g.append("g").attr("class","y axis").attr("clip-path",f?"url(#yaxis-clip)":"").call(f?J:la).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(ad);Jb&&g.append("g").attr("class","y2 axis").attr("transform",K.y2).call(Wa);d=g.append("g").attr("clip-path",Ma).attr("class","grid");mc&&d.append("g").attr("class","xgrids");tb&&(c=d.append("g").attr("class", -"xgrid-lines").selectAll(".xgrid-line").data(tb).enter().append("g").attr("class","xgrid-line"),c.append("line").attr("class",function(a){return""+a["class"]}),c.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",f?"":"rotate(-90)").attr("dx",f?0:-w).attr("dy",-6).text(function(a){return a.text}));bd&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",f?0:-10).attr("x2",f?q:-10).attr("y1",f?-10:w).attr("y2", -f?-10:t);nc&&d.append("g").attr("class","ygrids");ub&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(ub).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Ma).attr("class","regions");g.append("g").attr("clip-path",Ma).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",oa?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class", -function(a,b){return"event-rect event-rect-"+b}).style("cursor",da&&pa?"pointer":null).on("mouseover",function(a,b){if(!bb){var d=k.data.targets.map(function(a){return Cb(a.values[b])}),c,h;if(0",d,c,e;for(d=0;d"+e+""+c+"";return b+""}),ed=c(["tooltip","init","show"],!1),Aa=c(["tooltip","init","x"],0),sc=c(["tooltip","init","position"], -{top:"0px",left:"50px"}),sb=ua.replace("#","")+"-clip",Ma="url(#"+sb+")",z="timeseries"===vc,Z="categorized"===vc,Vb=!z&&na,xb=null,bb=!1,wb=!1,ja=za?40:0,ma=e.time.format(kd).parse,T=function(a,b){var d=[],c=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===d.indexOf(b)&&d.push(b);return c[d.indexOf(b)%c.length]}}(ld,md),Bc=function(){var a=[[e.time.format("%Y/%-m/%-d"),function(){return!0}],[e.time.format("%-m/%-d"), -function(a){return a.getMonth()}],[e.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[e.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[e.time.format("%I %p"),function(a){return a.getHours()}],[e.time.format("%I:%M"),function(a){return a.getMinutes()}],[e.time.format(":%S"),function(a){return a.getSeconds()}],[e.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var d=a.length-1,c=a[d];!c[1](b);)c=a[--d];return c[0](b)}}(),Fb,Mb, -Hb,Ta,Lb,Nb,q,t,ka,fb,va,Ob,Pb,ib,jb,l,y,R,Y,Ua,Va,J,la,Wa,Ca,xc=f?"left":"bottom",yc=f?hb?"top":"bottom":hb?"right":"left",zc=f?gb?"bottom":"top":gb?"left":"right",Ac="bottom",K={main:function(){return"translate("+B+","+w+")"},context:function(){return"translate("+H+","+Ba+")"},legend:function(){return"translate("+Bb+","+Ab+")"},y2:function(){return"translate("+(f?0:q)+","+(f?10:0)+")"},x:function(){return"translate(0,"+t+")"},subx:function(){return"translate(0,"+ka+")"}},gd=function(){var a=e.svg.line().x(f? -function(a){return E(a.id)(a.value)}:$a).y(f?$a:function(a){return E(a.id)(a.value)});return function(b){var d=jc(b.values),c;if(pb(b))return"spline"===ba["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return L};k.data.get=function(a){a=k.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Xa(function(b){return b.id===a});return 0",d,c,e;for(d=0;d"+e+""+ +c+"";return b+""}),fd=c(["tooltip","init","show"],!1),Aa=c(["tooltip","init","x"],0),sc=c(["tooltip","init","position"],{top:"0px",left:"50px"}),sb=ua.replace("#","")+"-clip",Ma="url(#"+sb+")",z="timeseries"===vc,Z="categorized"===vc,Vb=!z&&na,xb=null,bb=!1,wb=!1,ja=za?40:0,ma=e.time.format(ld).parse,T=function(a,b){var d=[],c=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===d.indexOf(b)&& +d.push(b);return c[d.indexOf(b)%c.length]}}(md,nd),Bc=function(){var a=[[e.time.format("%Y/%-m/%-d"),function(){return!0}],[e.time.format("%-m/%-d"),function(a){return a.getMonth()}],[e.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[e.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[e.time.format("%I %p"),function(a){return a.getHours()}],[e.time.format("%I:%M"),function(a){return a.getMinutes()}],[e.time.format(":%S"),function(a){return a.getSeconds()}],[e.time.format(".%L"), +function(a){return a.getMilliseconds()}]];return function(b){for(var d=a.length-1,c=a[d];!c[1](b);)c=a[--d];return c[0](b)}}(),Fb,Mb,Hb,Ta,Lb,Nb,q,t,ka,fb,va,Ob,Pb,ib,jb,l,y,R,Y,Ua,Va,J,la,Wa,Ca,xc=f?"left":"bottom",yc=f?hb?"top":"bottom":hb?"right":"left",zc=f?gb?"bottom":"top":gb?"left":"right",Ac="bottom",K={main:function(){return"translate("+B+","+w+")"},context:function(){return"translate("+H+","+Ba+")"},legend:function(){return"translate("+Bb+","+Ab+")"},y2:function(){return"translate("+(f? +0:q)+","+(f?10:0)+")"},x:function(){return"translate(0,"+t+")"},subx:function(){return"translate(0,"+ka+")"}},hd=function(){var a=e.svg.line().x(f?function(a){return E(a.id)(a.value)}:$a).y(f?$a:function(a){return E(a.id)(a.value)});return function(b){var d=jc(b.values),c;if(pb(b))return"spline"===ba["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return L};k.data.get=function(a){a=k.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b= +Xa(function(b){return b.id===a});return 0