From 68ba938ec837c2803ef7470f1a6f07b87ca47014 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Mon, 9 Sep 2013 18:42:35 +0900 Subject: [PATCH] Fix regions for timeseries --- c3.js | 6 ++-- c3.min.js | 104 +++++++++++++++++++++++++++--------------------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/c3.js b/c3.js index 0263d84..ee7ea29 100644 --- a/c3.js +++ b/c3.js @@ -261,11 +261,11 @@ // For region var regionStart = function (d) { - return ('start' in d) ? x(d.start) : 0; + return ('start' in d) ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0; }; var regionWidth = function (d) { - var start = ('start' in d) ? x(d.start) : 0, - end = ('end' in d) ? x(d.end) : width, + var start = regionStart(d), + end = ('end' in d) ? x(isTimeSeries ? parseDate(d.end) : d.end) : width, w = end - start; return (w < 0) ? 0 : w; }; diff --git a/c3.min.js b/c3.min.js index 00faf8a..4892ce1 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,57 +1,57 @@ -(function(Ma){function fb(){function u(c,j){c.attr("transform",function(c){return"translate("+(j(c)+S)+",0)"})}function c(c,j){c.attr("transform",function(c){return"translate(0,"+j(c)+")"})}function i(i){i.each(function(){for(var i=d3.select(this),x=j.domain(),l=[],H=Math.ceil(x[0]);Ha.length?a.length:10);d=g.append("g").attr("clip-path",Fa).attr("class","grid");ob&&d.append("g").attr("class","xgrids");Va&&(f=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Va).enter().append("g").attr("class", -"xgrid-line"),f.append("line").attr("class",function(a){return""+a["class"]}),f.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-m.top).attr("dy",-6).text(function(a){return a.text}));Xb&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",e?r:-10).attr("y1",e?-10:m.top).attr("y2",e?-10:t);pb&&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"]});g.append("g").attr("clip-path",Fa).attr("class","regions");g.append("g").attr("clip-path",Fa).attr("class","chart");g.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 U&&aa?"pointer":null}).on("mouseover", -function(a,b){if(!Ga){var d=h.data.targets.map(function(a){return a.values[b]}),f,c;for(f=0;fq[f].indexOf(a.id)))for(c=0;c",d,c,e;for(d=0;d"+e+""+c+"";return b+""}),Eb=u.bindto.replace("#","")+"-clip",Fa="url(#"+Eb+")",ga="timeseries"===Cb,ya="categorized"===Cb,Ya=null,Ga=!1,ca=ta?40:0,Fb,cb=[[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()}]];Fb=function(a){for(var b=cb.length-1,d=cb[b];!d[1](a);)d=cb[--b];return d[0](a)};var m={top:0,right:sb&&!e?50:1,bottom:20+ -Ab+ca,left:40},Gb=Ia-Ab-ca,ec=Ia-ca,r=cc-m.left-m.right,t=Ia-m.top-m.bottom,sa=Ia-Gb-(20+ca),Sb=d3.time.format(dc).parse,fc=e?10:0,gc=e?t:r,Hb=e?0:t,Ib=e?r:1,n=(ga?d3.time.scale():d3.scale.linear()).range([fc,gc]),D=d3.scale.linear().range([Hb,Ib]),fa=d3.scale.linear().range([Hb,Ib]),F=(ga?d3.time.scale():d3.scale.linear()).range([0,r]),Qa=d3.scale.linear().range([sa,10]),Pa=d3.scale.linear().range([sa,10]),B=ya?fb():d3.svg.axis(),qa=d3.svg.axis(),$a=d3.svg.axis(),ia=ya?fb():d3.svg.axis();B.scale(n).orient(e? -"left":"bottom");qa.scale(D).orient(e?"bottom":"left");$a.scale(fa).orient(e?"top":"right");ia.scale(F).orient("bottom");ga&&B.tickFormat(Fb);ya?(B.categories(Ja).tickCentered(Db),ia.categories(Ja).tickCentered(Db)):(B.tickOffset=function(){return 0},ia.tickOffset=function(){return 0});if(ya){var Ka=n,Jb=F,Kb=Object.keys(n),za,La,n=function(a){return Ka(a)+B.tickOffset()},F=function(a){return Jb(a)+ia.tickOffset()};for(La=0;Laa.length?a.length:10);d=g.append("g").attr("clip-path",Fa).attr("class","grid");qb&&d.append("g").attr("class","xgrids");Wa&&(f=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Wa).enter().append("g").attr("class", +"xgrid-line"),f.append("line").attr("class",function(a){return""+a["class"]}),f.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-m.top).attr("dy",-6).text(function(a){return a.text}));Xb&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",e?r:-10).attr("y1",e?-10:m.top).attr("y2",e?-10:t);rb&&d.append("g").attr("class","ygrids");Xa&&d.append("g").attr("class", +"ygrid-lines").selectAll("ygrid-line").data(Xa).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Fa).attr("class","regions");g.append("g").attr("clip-path",Fa).attr("class","chart");g.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&&ba?"pointer":null}).on("mouseover", +function(a,b){if(!Ga){var d=h.data.targets.map(function(a){return a.values[b]}),f,c;for(f=0;fq[f].indexOf(a.id)))for(c=0;c",d,c,e;for(d=0;d"+e+""+c+"";return b+""}),Fb=u.bindto.replace("#","")+"-clip",Fa="url(#"+Fb+")",U="timeseries"===Db,ya="categorized"===Db,Za=null,Ga=!1,da=ta?40:0,Gb,eb=[[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()}]];Gb=function(a){for(var b=eb.length-1,d=eb[b];!d[1](a);)d=eb[--b];return d[0](a)};var m={top:0,right:ub&&!e?50:1,bottom:20+ +Bb+da,left:40},Hb=Ia-Bb-da,ec=Ia-da,r=cc-m.left-m.right,t=Ia-m.top-m.bottom,sa=Ia-Hb-(20+da),Ra=d3.time.format(dc).parse,fc=e?10:0,gc=e?t:r,Ib=e?0:t,Jb=e?r:1,n=(U?d3.time.scale():d3.scale.linear()).range([fc,gc]),D=d3.scale.linear().range([Ib,Jb]),ga=d3.scale.linear().range([Ib,Jb]),F=(U?d3.time.scale():d3.scale.linear()).range([0,r]),Qa=d3.scale.linear().range([sa,10]),Pa=d3.scale.linear().range([sa,10]),B=ya?hb():d3.svg.axis(),qa=d3.svg.axis(),ab=d3.svg.axis(),ia=ya?hb():d3.svg.axis();B.scale(n).orient(e? +"left":"bottom");qa.scale(D).orient(e?"bottom":"left");ab.scale(ga).orient(e?"top":"right");ia.scale(F).orient("bottom");U&&B.tickFormat(Gb);ya?(B.categories(Ja).tickCentered(Eb),ia.categories(Ja).tickCentered(Eb)):(B.tickOffset=function(){return 0},ia.tickOffset=function(){return 0});if(ya){var Ka=n,Kb=F,Lb=Object.keys(n),za,La,n=function(a){return Ka(a)+B.tickOffset()},F=function(a){return Kb(a)+ia.tickOffset()};for(La=0;La=h;h+=diffx2)k+="M"+ -d(i(h))+" "+c(l(h))+" "+d(i(h+m))+" "+c(l(h+m))}}b=k}else b=db(a.values);return b}b=n(a.values[0].x);a=X(a.id)(a.values[0].value);return e?"M "+a+" "+b:"M "+b+" "+a};var vb,hc=d3.svg.line().x(function(a){return F(a.x)}).y(function(a){return z(a.id)(a.value)});vb=function(a){return Sa(a)?hc(a.values):"M "+F(a.values[0].x)+" "+z(a.id)(a.values[0].value)};var wb=function(a){return"start"in a?n(a.start):0},xb=function(a){var b="start"in a?n(a.start):0,a=("end"in a?n(a.end):r)-b;return 0>a?0:a},N,eb=[], -Lb=null!==Bb?Bb:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");N=function(a){if(a in zb)return zb[a];0<=eb.indexOf(a)||eb.push(a);return Lb[eb.indexOf(a)%Lb.length]};var da=d3.select(u.bindto).append("svg").attr("width",r+m.left+m.right).attr("height",t+m.top+m.bottom);da.append("defs");da.select("defs").append("clipPath").attr("id",Eb).append("rect").attr("y",m.top).attr("width",r).attr("height",t-m.top);da.select("defs").append("clipPath").attr("id", -"xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",r+2).attr("height",40);da.select("defs").append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",m.top-1).attr("width",40).attr("height",t-m.top+2);var g=da.append("g").attr("transform","translate("+m.left+","+m.top+")"),O=null;ra&&(O=da.append("g").attr("transform","translate(40,"+Gb+")"));var wa=null;ta&&(wa=da.append("g").attr("transform","translate(40,"+ec+")"));var Ha=d3.select(u.bindto).style("position", -"relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),ha=d3.svg.brush().x(F).on("brush",function(){P({withTransition:!1,withY:!1,withSubchart:!1})}),Da=null,Ra=null;h.focus=function(a){h.defocus();d3.selectAll(xa(a)).filter(function(a){return x(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){d3.selectAll(xa(a)).filter(function(a){return x(a.id)}).classed("focused",!1).transition().duration(100).style("opacity", +d(i(h))+" "+c(l(h))+" "+d(i(h+m))+" "+c(l(h+m))}}b=k}else b=fb(a.values);return b}b=n(a.values[0].x);a=Y(a.id)(a.values[0].value);return e?"M "+a+" "+b:"M "+b+" "+a};var xb,hc=d3.svg.line().x(function(a){return F(a.x)}).y(function(a){return z(a.id)(a.value)});xb=function(a){return Ta(a)?hc(a.values):"M "+F(a.values[0].x)+" "+z(a.id)(a.values[0].value)};var db=function(a){return"start"in a?n(U?Ra(a.start):a.start):0},yb=function(a){var b=db(a),a=("end"in a?n(U?Ra(a.end):a.end):r)-b;return 0>a?0:a}, +N,gb=[],Mb=null!==Cb?Cb:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");N=function(a){if(a in Ab)return Ab[a];0<=gb.indexOf(a)||gb.push(a);return Mb[gb.indexOf(a)%Mb.length]};var ea=d3.select(u.bindto).append("svg").attr("width",r+m.left+m.right).attr("height",t+m.top+m.bottom);ea.append("defs");ea.select("defs").append("clipPath").attr("id",Fb).append("rect").attr("y",m.top).attr("width",r).attr("height",t-m.top);ea.select("defs").append("clipPath").attr("id", +"xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",r+2).attr("height",40);ea.select("defs").append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",m.top-1).attr("width",40).attr("height",t-m.top+2);var g=ea.append("g").attr("transform","translate("+m.left+","+m.top+")"),O=null;ra&&(O=ea.append("g").attr("transform","translate(40,"+Hb+")"));var wa=null;ta&&(wa=ea.append("g").attr("transform","translate(40,"+ec+")"));var Ha=d3.select(u.bindto).style("position", +"relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),ha=d3.svg.brush().x(F).on("brush",function(){P({withTransition:!1,withY:!1,withSubchart:!1})}),Da=null,Sa=null;h.focus=function(a){h.defocus();d3.selectAll(xa(a)).filter(function(a){return x(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){d3.selectAll(xa(a)).filter(function(a){return x(a.id)}).classed("focused",!1).transition().duration(100).style("opacity", 0.3)};h.revert=function(a){d3.selectAll(xa(a)).filter(function(a){return x(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){d3.selectAll(xa(a)).transition().style("opacity",1)};h.hide=function(a){d3.selectAll(xa(a)).transition().style("opacity",0)};h.load=function(a){p(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 G};h.data.get=function(a){a=h.data.getAsTarget(a);return j(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=Aa(function(b){return b.id== -a});return 0