From c478f1f840c68dd59fd862669c19e76cdac2a24c Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 23 Feb 2014 21:04:27 +0900 Subject: [PATCH] Fix x tick format --- c3.js | 19 ++++++++++++------- c3.min.js | 10 +++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/c3.js b/c3.js index 77bf678..5061be7 100644 --- a/c3.js +++ b/c3.js @@ -134,15 +134,16 @@ // tooltip - show when mouseover on each data var __tooltip_enabled = getConfig(['tooltip', 'enabled'], true), __tooltip_contents = getConfig(['tooltip', 'contents'], function (d) { - var title = getXAxisTickFormat()(d[0].x), - text = "", i, value, name, - format = __axis_y_tick_format ? __axis_y_tick_format : function (v) { return +v; }; + var yFormat = __axis_y_tick_format ? __axis_y_tick_format : function (v) { return +v; }, + xFormat = getXAxisTickFormat(), + title = xFormat ? xFormat(d[0].x) : d[0].x, + text = "
" + title + "
", i, value, name; for (i = 0; i < d.length; i++) { if (! d[i] || ! isValue(d[i].value)) { continue; } value = '-'; if (isValue(d[i].value)) { - value = format(d[i].value); + value = yFormat(d[i].value); } name = d[i].name; @@ -402,11 +403,15 @@ return id in __data_axes ? __data_axes[id] : 'y'; } function getXAxisTickFormat() { - var tickFormat = isTimeSeries ? defaultTimeFormat : isCategorized ? category : function (x) { return x; }; + var format = 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; + if (typeof __axis_x_tick_format === 'function') { + format = __axis_x_tick_format; + } else if (isTimeSeries) { + format = function (date) { return d3.time.format(__axis_x_tick_format)(date); }; + } } - return tickFormat; + return format; } //-- Arc --// diff --git a/c3.min.js b/c3.min.js index c27be89..1456a5a 100644 --- a/c3.min.js +++ b/c3.min.js @@ -6,9 +6,9 @@ C=e in{top:1,right:1,bottom:1,left:1}?e+"":"bottom";return p};p.categories=funct O.c3={},e=O.d3;Ab.generate=function(ea){var pc,qc,Ha,Ia,p,q,C,M,$;function g(a,b){for(var c=ea,d=0;da?a:0}),c=1;c+a||(b[d][c]+=+a)});return e.max(Object.keys(b).map(function(a){return e.max(b[a])}))}function nb(a){var b=ob(function(b){return R(b.id)===a}),c="y2"===a?Kd:Ld,d="y2"===a?Md:Nd,c=c?c:Hd(b),d=d?d:Id(b),f=0.1*Math.abs(d-c),e=f,g=f,h="y2"===a?Od:Pd;h&&(c=Math.max(Math.abs(c),Math.abs(d)),d=c-h,c=h-c);"y"===a&&Na&&(e=Na.top?Na.top:f,g=Na.bottom?Na.bottom:f);"y2"===a&&Oa&&(e=Oa.top?Oa.top:f,g=Oa.bottom? Oa.bottom:f);ia(b,"bar")&&!Ac(b)&&(g=c);return[c-g,d+e]}function Qd(a){return e.min(a,function(a){return e.min(a.values,function(a){return a.x})})}function Rd(a){return e.max(a,function(a){return e.max(a.values,function(a){return a.x})})}function pb(a){var b=[Qd(a),Rd(a)];a=b[0];var b=b[1],c=ja?0:0.01*Math.abs(a-b);a=D?new Date(a.getTime()-c):a-c;b=D?new Date(b.getTime()+c):b+c;return[a,b]}function ya(a){return a[1]-a[0]}function Sd(a){for(var b=0;b",c,d,e,g=cc?cc:function(a){return+a};for(c=0;c"}return b+"
" + title + "
"+e+""+d+"
"}),ye=g(["tooltip","init","show"],!1),Ga=g(["tooltip","init","x"],0),md= -g(["tooltip","init","position"],{top:"0px",left:"50px"}),dc=xa.replace("#","")+"-clip",Xa="url("+document.URL+"#"+dc+")",D="timeseries"===vd,ja="categorized"===vd,Sb=!D&&(ra||ba),jc=null,Ya=!1,ic=!1,pa=Fa?40:0,N=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]}}(Le,Me),Ed=function(){var a=[[e.time.format("%Y/%-m/%-d"), +function(a){var b=cc?cc:function(a){return+a},c=sc(),c="",d,e,g;for(d=0;d"}return c+"
"+(c?c(a[0].x):a[0].x)+"
"+g+""+e+"
"}),ye=g(["tooltip","init","show"],!1),Ga=g(["tooltip","init", +"x"],0),md=g(["tooltip","init","position"],{top:"0px",left:"50px"}),dc=xa.replace("#","")+"-clip",Xa="url("+document.URL+"#"+dc+")",D="timeseries"===vd,ja="categorized"===vd,Sb=!D&&(ra||ba),jc=null,Ya=!1,ic=!1,pa=Fa?40:0,N=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]}}(Le,Me),Ed=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 c=a.length-1,d= a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),r,Eb,s,fb,Bb,wa,La,Fb,Gb,lb,vc,wc,Ob,Ib,Jb,Kb,Lb,Mb,Nb,m,z,aa,U,ib,jb,J,za,kb,hb,zd=h?"left":"bottom",Ad=h?cb?"top":"bottom":cb?"right":"left",Bd=h?eb?"bottom":"top":eb?"left":"right",Cd=h?"left":"bottom",L={main:function(){return"translate("+C+","+q+")"},context:function(){return"translate("+Ia+","+Ha+")"},legend:function(){return"translate("+qc+","+pc+")"},y2:function(){return"translate("+(h?0:r)+","+(h?10:0)+")"},x:function(){return"translate(0,"+s+")"}, subx:function(){return"translate(0,"+(h?0:fb)+")"},arc:function(){return"translate("+r/2+","+s/2+")"}},uc=40,tc=20;Ob=e.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var Fe=function(){var a=e.svg.line().x(h?function(a){return u(a.id)(a.value)}:Aa).y(h?Aa:function(a){return u(a.id)(a.value)});return function(b){var c=Yb(b.values),d;if(Vb(b))return Zc(b)?a.interpolate("cardinal"):a.interpolate("linear"),ud[b.id]?ne(c,m,u(b.id),ud[b.id]):a(c);d=m(c[0].x);