diff --git a/c3.js b/c3.js index dea2968..9110506 100644 --- a/c3.js +++ b/c3.js @@ -128,8 +128,8 @@ // tooltip - show when mouseover on each data var __tooltip_contents = getConfig(['tooltip', 'contents'], function (d) { - var date = isTimeSeries ? d[0].x.getFullYear() + '.' + (d[0].x.getMonth() + 1) + '.' + d[0].x.getDate() : isCategorized ? category(d[0].x) : d[0].x, - text = "", i, value, name; + var title = getXAxisTickFormat()(d[0].x), + text = "
" + date + "
", i, value, name; for (i = 0; i < d.length; i++) { if (isDefined(d[i])) { value = isDefined(d[i].value) ? (Math.round(d[i].value * 100) / 100).toFixed(2) : '-'; @@ -329,13 +329,9 @@ function getXAxis(scale, orient) { var axis = (isCategorized ? categoryAxis() : d3.svg.axis()).scale(scale).orient(orient); - var tickFormat = isTimeSeries ? defaultTimeFormat : null; // Set tick format - if (__axis_x_tick_format) { - tickFormat = typeof __axis_x_tick_format === 'function' ? __axis_x_tick_format : isTimeSeries ? function (date) { return d3.time.format(__axis_x_tick_format)(date); } : null; - } - axis.tickFormat(tickFormat); + axis.tickFormat(getXAxisTickFormat()); // Set categories if (isCategorized) { @@ -353,6 +349,13 @@ function getAxisId(id) { return id in __data_axes ? __data_axes[id] : 'y'; } + function getXAxisTickFormat() { + var tickFormat = isTimeSeries ? defaultTimeFormat : isCategorized ? category : null; + if (__axis_x_tick_format) { + tickFormat = typeof __axis_x_tick_format === 'function' ? __axis_x_tick_format : isTimeSeries ? function (date) { return d3.time.format(__axis_x_tick_format)(date); } : tickFormat; + } + return tickFormat; + } //-- Domain --// diff --git a/c3.min.js b/c3.min.js index cddd5a3..c88992a 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,68 +1,68 @@ -(function(M){function wc(){function n(d,e){d.attr("transform",function(d){return"translate("+(e(d)+$)+", 0)"})}function s(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function M(d){var e=d[0];d=d[d.length-1];return ea?0:a}function ob(a){var b=Ga[a.id];a.name=n(b)?b:a.id;return a}function Wb(a){var b= -a[0],c={},f=[],q,d;for(q=1;q -w[c].indexOf(d.id)))for(f=0;f=e;e+=v)k+=f(a[d-1],a[d],e,t)}return k}function xb(a){var b,c;cb=d.select(ua);if(cb.empty())M.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); -else{cb.html("");k.data.x=void 0;k.data.targets=Ha(a);R();O();l.domain(d.extent(a.map(function(a){return a.x})));z.domain(Q("y"));T.domain(Q("y2"));ca.domain(l.domain());Va.domain(z.domain());Wa.domain(T.domain());I.ticks(10>a.length?a.length:10);na.ticks(Wc).outerTickSize(0).tickFormat(Xc);Xa.ticks(Yc).outerTickSize(0).tickFormat(Zc);U=l.domain();E.x(ca);pa&&F.x(l);Ka=d.select(ua).append("svg").attr("width",r+C+B).attr("height",p+v+ba).on("mouseenter",$c).on("mouseleave",ad);db=Ka.append("defs"); -db.append("clipPath").attr("id",yb).append("rect").attr("y",v).attr("width",r).attr("height",p-v);db.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-C).attr("y",-20).attr("width",Z).attr("height",ib);db.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-C+1).attr("y",v-1).attr("width",xc).attr("height",N);h=Ka.append("g").attr("transform",J.main);x=wa?Ka.append("g").attr("transform",J.context):null;xa=ya?Ka.append("g").attr("transform",J.legend):null;X=d.select(ua).style("position", -"relative").append("div").style("position","absolute").style("z-index","10").style("display","none");h.append("g").attr("class","x axis").attr("clip-path",g?"":"url(#xaxis-clip)").attr("transform",J.x).call(g?na:I).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(bd);h.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?I:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor", -"end").text(cd);Lb&&h.append("g").attr("class","y2 axis").attr("transform",J.y2).call(Xa);b=h.append("g").attr("clip-path",La).attr("class","grid");mc&&b.append("g").attr("class","xgrids");zb&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(zb).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",g?"":"rotate(-90)").attr("dx", -g?0:-v).attr("dy",-6).text(function(a){return a.text}));dd&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?r:-10).attr("y1",g?-10:v).attr("y2",g?-10:p);nc&&b.append("g").attr("class","ygrids");Ab&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Ab).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});h.append("g").attr("clip-path",La).attr("class","regions");h.append("g").attr("clip-path", -La).attr("class","chart");h.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",pa?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",ha&&qa?"pointer":null).on("mouseover",function(a,b){if(!eb){var c=k.data.targets.map(function(a){return ob(a.values[b])}),d,e;if(0",c,d,e;for(c=0;c";return b+"
" + title + "
"+e+""+d+"
"}),gd=e(["tooltip","init","show"],!1),za=e(["tooltip","init","x"],0),sc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),yb=ua.replace("#","")+"-clip",La="url(#"+yb+")",A="timeseries"===vc,da="categorized"===vc,pb=!A&&V,Db=null,eb=!1,Cb=!1,la=ya?40:0,oa=d.time.format(nd).parse,W=function(a,b){var c=[],d=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===c.indexOf(b)&&c.push(b);return d[c.indexOf(b)%d.length]}}(od,pd),Cc=function(){var a=[[d.time.format("%Y/%-m/%-d"),function(){return!0}],[d.time.format("%-m/%-d"),function(a){return a.getMonth()}],[d.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[d.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[d.time.format("%I %p"),function(a){return a.getHours()}],[d.time.format("%I:%M"),function(a){return a.getMinutes()}],[d.time.format(":%S"), -function(a){return a.getSeconds()}],[d.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),Hb,Ob,Jb,Ua,Nb,Pb,r,p,ma,jb,ta,Rb,Sb,mb,nb,l,z,T,ca,Va,Wa,I,na,Xa,Ba,yc=g?"left":"bottom",zc=g?lb?"top":"bottom":lb?"right":"left",Ac=g?kb?"bottom":"top":kb?"left":"right",Bc="bottom",J={main:function(){return"translate("+C+","+v+")"},context:function(){return"translate("+G+","+Aa+")"},legend:function(){return"translate("+ -Gb+","+Fb+")"},y2:function(){return"translate("+(g?0:r)+","+(g?10:0)+")"},x:function(){return"translate(0,"+p+")"},subx:function(){return"translate(0,"+ma+")"}},jd=function(){var a=d.svg.line().x(g?function(a){return y(a.id)(a.value)}:bb).y(g?bb:function(a){return y(a.id)(a.value)});return function(b){var c=lc(b.values),d;if(vb(b))return"spline"===ga["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return K};k.data.get=function(a){a=k.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b= -Za(function(b){return b.id===a});return 0a?0:a}function ob(a){var b=Ia[a.id];a.name=n(b)?b:a.id;return a}function Wb(a){var b= +a[0],d={},g=[],p,e;for(p=1;pw[d].indexOf(e.id)))for(g=0;g=h;h+=v)s+=e(a[c-1],a[c],h,u)}return s}function xb(a){var b,d;cb=e.select(va);if(cb.empty())M.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); +else{cb.html("");h.data.x=void 0;h.data.targets=Ja(a);Q();O();l.domain(e.extent(a.map(function(a){return a.x})));z.domain(ka("y"));S.domain(ka("y2"));ba.domain(l.domain());Va.domain(z.domain());Wa.domain(S.domain());I.ticks(10>a.length?a.length:10);na.ticks(Yc).outerTickSize(0).tickFormat(Zc);Xa.ticks($c).outerTickSize(0).tickFormat(ad);T=l.domain();E.x(ba);pa&&F.x(l);Ma=e.select(va).append("svg").attr("width",r+C+B).attr("height",q+v+aa).on("mouseenter",bd).on("mouseleave",cd);db=Ma.append("defs"); +db.append("clipPath").attr("id",yb).append("rect").attr("y",v).attr("width",r).attr("height",q-v);db.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-C).attr("y",-20).attr("width",Y).attr("height",hb);db.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-C+1).attr("y",v-1).attr("width",xc).attr("height",N);k=Ma.append("g").attr("transform",J.main);x=xa?Ma.append("g").attr("transform",J.context):null;ya=za?Ma.append("g").attr("transform",J.legend):null;W=e.select(va).style("position", +"relative").append("div").style("position","absolute").style("z-index","10").style("display","none");k.append("g").attr("class","x axis").attr("clip-path",f?"":"url(#xaxis-clip)").attr("transform",J.x).call(f?na:I).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(dd);k.append("g").attr("class","y axis").attr("clip-path",f?"url(#yaxis-clip)":"").call(f?I:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor", +"end").text(ed);Lb&&k.append("g").attr("class","y2 axis").attr("transform",J.y2).call(Xa);b=k.append("g").attr("clip-path",Na).attr("class","grid");mc&&b.append("g").attr("class","xgrids");zb&&(d=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(zb).enter().append("g").attr("class","xgrid-line"),d.append("line").attr("class",function(a){return""+a["class"]}),d.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",f?"":"rotate(-90)").attr("dx", +f?0:-v).attr("dy",-6).text(function(a){return a.text}));fd&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",f?0:-10).attr("x2",f?r:-10).attr("y1",f?-10:v).attr("y2",f?-10:q);nc&&b.append("g").attr("class","ygrids");Ab&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Ab).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Na).attr("class","regions");k.append("g").attr("clip-path", +Na).attr("class","chart");k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",pa?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",ga&&qa?"pointer":null).on("mouseover",function(a,b){if(!eb){var d=h.data.targets.map(function(a){return ob(a.values[b])}),e,c;if(0",d,c,e;for(d=0;d"+e+""+ +c+"";return b+""}),id=c(["tooltip","init","show"],!1),Aa=c(["tooltip","init","x"],0),sc=c(["tooltip","init","position"],{top:"0px",left:"50px"}),yb=va.replace("#","")+"-clip",Na="url(#"+yb+")",A="timeseries"===vc,ca="categorized"===vc,pb=!A&&U,Db=null,eb=!1,Cb=!1,la=za?40:0,oa=e.time.format(pd).parse,V=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]}}(qd,rd),Ec=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)}}(),Hb,Ob,Jb,Ua,Nb,Pb,r,q,ma,ib,ua,Rb,Sb,lb,mb,l,z,S,ba,Va,Wa,I,na,Xa,Da,zc=f?"left":"bottom",Ac=f?kb?"top":"bottom":kb?"right":"left",Bc=f?jb?"bottom":"top":jb?"left":"right",Cc="bottom",J={main:function(){return"translate("+C+","+v+")"},context:function(){return"translate("+G+","+Ba+")"},legend:function(){return"translate("+Gb+","+Fb+")"},y2:function(){return"translate("+(f? +0:r)+","+(f?10:0)+")"},x:function(){return"translate(0,"+q+")"},subx:function(){return"translate(0,"+ma+")"}},ld=function(){var a=e.svg.line().x(f?function(a){return y(a.id)(a.value)}:bb).y(f?bb:function(a){return y(a.id)(a.value)});return function(b){var d=lc(b.values),c;if(vb(b))return"spline"===fa["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return K};h.data.get=function(a){a=h.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b= +Za(function(b){return b.id===a});return 0