From e1e4db23701db4320bd754e370caf409c9b6bd71 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Wed, 11 Sep 2013 19:34:49 +0900 Subject: [PATCH] Fix grid.x.lines when timeseries --- c3.js | 2 +- c3.min.js | 60 +++++++++++++++++++++++++++---------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/c3.js b/c3.js index e02dc45..07f2d13 100644 --- a/c3.js +++ b/c3.js @@ -520,7 +520,7 @@ return x(d.x); } function xv (d) { - return x(d.value); + return x(isTimeSeries ? parseDate(d.value) : d.value); } function yv (d) { return y(d.value); diff --git a/c3.min.js b/c3.min.js index 9d6fea4..0511e49 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,17 +1,17 @@ -(function(Ka){function gb(){function n(c,i){c.attr("transform",function(c){return"translate("+(i(c)+E)+",0)"})}function c(c,i){c.attr("transform",function(c){return"translate(0,"+i(c)+")"})}function i(v){v.each(function(){for(var i=d3.select(this),v=l.domain(),k=[],x=Math.ceil(v[0]);xa.length?a.length:10);d=f.append("g").attr("clip-path", +function Ta(a,b,d){Wb(a,b);f.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+d).transition().duration(100).attr("r",0).remove()}function ob(a,b,d,g){a?nb(b,d,g):Ta(b,d,g)}function Xb(){}function pb(){}function qb(){}function Ua(a){var b=h.data.targets=E(a),d,g;q.domain(d3.extent(a.map(function(a){return a.x})));D.domain(U(b,"y"));ga.domain(U(b,"y2"));I.domain(q.domain());Pa.domain(D.domain());Oa.domain(ga.domain());w.ticks(10>a.length?a.length:10);d=f.append("g").attr("clip-path", Da).attr("class","grid");rb&&d.append("g").attr("class","xgrids");Va&&(g=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Va).enter().append("g").attr("class","xgrid-line"),g.append("line").attr("class",function(a){return""+a["class"]}),g.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-p.top).attr("dy",-6).text(function(a){return a.text}));Yb&&d.append("g").attr("class","xgrid-focus").append("line").attr("class", "xgrid-focus").attr("x1",e?0:-10).attr("x2",e?s:-10).attr("y1",e?-10:p.top).attr("y2",e?-10:u);sb&&d.append("g").attr("class","ygrids");Wa&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Wa).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});f.append("g").attr("clip-path",Da).attr("class","regions");f.append("g").attr("clip-path",Da).attr("class","chart");f.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class", function(a,b){return"event-rect event-rect-"+b}).style("cursor",function(){return V&&aa?"pointer":null}).on("mouseover",function(a,b){if(!Ea){var d=h.data.targets.map(function(a){return a.values[b]}),g,c;for(g=0;gr[g].indexOf(a.id)))for(c=0;cr[g].indexOf(a.id)))for(c=0;c",d,c,e;for(d=0;d"+e+""+ -c+"";return b+""}),Gb=n.bindto.replace("#","")+"-clip",Da="url(#"+Gb+")",M="timeseries"===Eb,wa="categorized"===Eb,Ya=null,Ea=!1,ca=ra?40:0,Hb,db=[[d3.time.format("%Y/%-m/%-d"),function(){return!0}],[d3.time.format("%-m/%-d"),function(a){return a.getMonth()}],[d3.time.format("%-m/%-d"),function(a){return 1!=a.getDate()}],[d3.time.format("%-m/%-d"),function(a){return a.getDay()&&1!=a.getDate()}],[d3.time.format("%I %p"),function(a){return a.getHours()}],[d3.time.format("%I:%M"),function(a){return a.getMinutes()}], -[d3.time.format(":%S"),function(a){return a.getSeconds()}],[d3.time.format(".%L"),function(a){return a.getMilliseconds()}]];Hb=function(a){for(var b=db.length-1,d=db[b];!d[1](a);)d=db[--b];return d[0](a)};var p={top:0,right:vb&&!e?50:1,bottom:20+Cb+ca,left:40},Ib=Ga-Cb-ca,fc=Ga-ca,s=dc-p.left-p.right,u=Ga-p.top-p.bottom,qa=Ga-Ib-(20+ca),la=d3.time.format(ec).parse,Jb=e?0:u,Kb=e?s:1,q=Na(e?10:0,e?u:s),D=ja(Jb,Kb),ga=ja(Jb,Kb),H=Na(0,s),Pa=ja(qa,10),Oa=ja(qa,10),w=wa?gb():d3.svg.axis(),oa=d3.svg.axis(), -$a=d3.svg.axis(),ia=wa?gb():d3.svg.axis();w.scale(q).orient(e?"left":"bottom");oa.scale(D).orient(e?"bottom":"left");$a.scale(ga).orient(e?"top":"right");ia.scale(H).orient("bottom");M&&w.tickFormat(Hb);wa?(w.categories(Ha).tickCentered(Fb),ia.categories(Ha).tickCentered(Fb)):(w.tickOffset=function(){return 0},ia.tickOffset=function(){return 0});if(wa){var Ia=q,Lb=H,Mb=Object.keys(q),xa,Ja,q=function(a){return Ia(a)+w.tickOffset()},H=function(a){return Lb(a)+ia.tickOffset()};for(Ja=0;Ja=h;h+=diffx2)j+=m(b[f-1],b[f],h,k)}}b=j}else b=eb(a.values);return b}b=q(a.values[0].x);a=A(a.id)(a.values[0].value);return e?"M "+a+" "+b:"M "+b+" "+a};var yb,gc=d3.svg.line().x(function(a){return H(a.x)}).y(function(a){return Q(a.id)(a.value)}); -yb=function(a){return Sa(a)?gc(a.values):"M "+H(a.values[0].x)+" "+Q(a.id)(a.values[0].value)};var cb=function(a){return"start"in a?q(M?la(a.start):a.start):0},zb=function(a){var b=cb(a),a=("end"in a?q(M?la(a.end):a.end):s)-b;return 0>a?0:a},N,fb=[],Nb=null!==Db?Db:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");N=function(a){if(a in Bb)return Bb[a];0<=fb.indexOf(a)||fb.push(a);return Nb[fb.indexOf(a)%Nb.length]};var da=d3.select(n.bindto).append("svg").attr("width", +Wb=c(["point","onunselected"],function(){}),J=c(["regions"],[]),Zb=c(["tooltip","contents"],function(a){var b="",d,c,e;for(d=0;d";return b+"
"+(H?a[0].x.getFullYear()+"."+(a[0].x.getMonth()+1)+"."+a[0].x.getDate():wa?a[0].x
"+e+""+ +c+"
"}),Gb=n.bindto.replace("#","")+"-clip",Da="url(#"+Gb+")",H="timeseries"===Eb,wa="categorized"===Eb,Ya=null,Ea=!1,ca=ra?40:0,Hb,db=[[d3.time.format("%Y/%-m/%-d"),function(){return!0}],[d3.time.format("%-m/%-d"),function(a){return a.getMonth()}],[d3.time.format("%-m/%-d"),function(a){return 1!=a.getDate()}],[d3.time.format("%-m/%-d"),function(a){return a.getDay()&&1!=a.getDate()}],[d3.time.format("%I %p"),function(a){return a.getHours()}],[d3.time.format("%I:%M"),function(a){return a.getMinutes()}], +[d3.time.format(":%S"),function(a){return a.getSeconds()}],[d3.time.format(".%L"),function(a){return a.getMilliseconds()}]];Hb=function(a){for(var b=db.length-1,d=db[b];!d[1](a);)d=db[--b];return d[0](a)};var p={top:0,right:vb&&!e?50:1,bottom:20+Cb+ca,left:40},Ib=Ga-Cb-ca,fc=Ga-ca,s=dc-p.left-p.right,u=Ga-p.top-p.bottom,qa=Ga-Ib-(20+ca),ha=d3.time.format(ec).parse,Jb=e?0:u,Kb=e?s:1,q=Na(e?10:0,e?u:s),D=ka(Jb,Kb),ga=ka(Jb,Kb),I=Na(0,s),Pa=ka(qa,10),Oa=ka(qa,10),w=wa?gb():d3.svg.axis(),oa=d3.svg.axis(), +$a=d3.svg.axis(),ja=wa?gb():d3.svg.axis();w.scale(q).orient(e?"left":"bottom");oa.scale(D).orient(e?"bottom":"left");$a.scale(ga).orient(e?"top":"right");ja.scale(I).orient("bottom");H&&w.tickFormat(Hb);wa?(w.categories(Ha).tickCentered(Fb),ja.categories(Ha).tickCentered(Fb)):(w.tickOffset=function(){return 0},ja.tickOffset=function(){return 0});if(wa){var Ia=q,Lb=I,Mb=Object.keys(q),xa,Ja,q=function(a){return Ia(a)+w.tickOffset()},I=function(a){return Lb(a)+ja.tickOffset()};for(Ja=0;Ja=h;h+=diffx2)j+=m(b[f-1],b[f],h,k)}}b=j}else b=eb(a.values);return b}b=q(a.values[0].x);a=A(a.id)(a.values[0].value);return e?"M "+a+" "+b:"M "+b+" "+a};var yb,gc=d3.svg.line().x(function(a){return I(a.x)}).y(function(a){return Q(a.id)(a.value)}); +yb=function(a){return Sa(a)?gc(a.values):"M "+I(a.values[0].x)+" "+Q(a.id)(a.values[0].value)};var cb=function(a){return"start"in a?q(H?ha(a.start):a.start):0},zb=function(a){var b=cb(a),a=("end"in a?q(H?ha(a.end):a.end):s)-b;return 0>a?0:a},N,fb=[],Nb=null!==Db?Db:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");N=function(a){if(a in Bb)return Bb[a];0<=fb.indexOf(a)||fb.push(a);return Nb[fb.indexOf(a)%Nb.length]};var da=d3.select(n.bindto).append("svg").attr("width", s+p.left+p.right).attr("height",u+p.top+p.bottom);da.append("defs");da.select("defs").append("clipPath").attr("id",Gb).append("rect").attr("y",p.top).attr("width",s).attr("height",u-p.top);da.select("defs").append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",s+2).attr("height",40);da.select("defs").append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",p.top-1).attr("width",40).attr("height",u-p.top+2);var f=da.append("g").attr("transform", -"translate("+p.left+","+p.top+")"),O=null;pa&&(O=da.append("g").attr("transform","translate(40,"+Ib+")"));var ua=null;ra&&(ua=da.append("g").attr("transform","translate(40,"+fc+")"));var Fa=d3.select(n.bindto).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),ha=d3.svg.brush().x(H).on("brush",function(){P({withTransition:!1,withY:!1,withSubchart:!1})}),Ba=null,Qa=null;h.focus=function(a){h.defocus();d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused", +"translate("+p.left+","+p.top+")"),O=null;pa&&(O=da.append("g").attr("transform","translate(40,"+Ib+")"));var ua=null;ra&&(ua=da.append("g").attr("transform","translate(40,"+fc+")"));var Fa=d3.select(n.bindto).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),ia=d3.svg.brush().x(I).on("brush",function(){P({withTransition:!1,withY:!1,withSubchart:!1})}),Ba=null,Qa=null;h.focus=function(a){h.defocus();d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused", !0).transition().duration(100).style("opacity",1)};h.defocus=function(a){d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};h.revert=function(a){d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){d3.selectAll(va(a)).transition().style("opacity",1)};h.hide=function(a){d3.selectAll(va(a)).transition().style("opacity",0)};h.load=function(a){l(a.done)&& (a.done=function(){});var b;if(b="cacheIds"in a)a:{b=a.cacheIds;for(var d=0;db.classes.indexOf(a)})});return I}; +"spline");P()};h.toBar=function(a){Ra(a,"bar");P()};h.groups=function(a){if(l(a))return r;r=a;P();return r};h.regions=function(a){if(l(a))return J;J=a;P();return J};h.regions.add=function(a){if(l(a))return J;J=J.concat(a);P();return J};h.regions.remove=function(a,b){var c=[].concat(a),b=i(b)?b:{};c.forEach(function(a){var c=d3.selectAll("."+a);i(b.duration)&&(c=c.transition().duration(b.duration).style("fill-opacity",0));c.remove();J=J.filter(function(b){return 0>b.classes.indexOf(a)})});return J}; h.data.get=function(a){a=h.data.getAsTarget(a);return i(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=k(function(b){return b.id==a});return 0