From 34a5b475a3fd175d8d4abc727463da3c0997675e Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 25 Oct 2013 11:51:13 +0700 Subject: [PATCH] Fix unexpected extent --- c3.js | 4 +++- c3.min.js | 66 +++++++++++++++++++++++++++---------------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/c3.js b/c3.js index 7b3a49e..a865cd0 100644 --- a/c3.js +++ b/c3.js @@ -1481,7 +1481,9 @@ updateSizes(); updateScales(); // Set x for brush again because of scale update - brush.x(subX).extent(x.domain()); + brush.x(subX); + // Update extent width if extent specified + if ( ! brush.empty()) brush.extent(x.domain()); // Set x for zoom again because of scale update if (__zoom_enabled) zoom.x(x); // Update sizes diff --git a/c3.min.js b/c3.min.js index 3f0bed2..6420d69 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,23 +1,23 @@ -(function(vb){function wb(){function k(c,$a){c.attr("transform",function(c){return"translate("+($a(c)+U)+",0)"})}function s(c,k){c.attr("transform",function(c){return"translate(0,"+k(c)+")"})}function La(c){var k=c[0];c=c[c.length-1];return kv[d].indexOf(c.id)))for(e=0;ev[d].indexOf(c.id)))for(e=0;e=h;h+=diffx2)q+=c(a[g-1],a[g],h,t);return q}function lb(a){var b=l.data.targets=O(a),d,c;m.domain(d3.extent(a.map(function(a){return a.x})));y.domain(D(b,"y"));R.domain(D(b,"y2"));z.domain(m.domain());Oa.domain(y.domain());Pa.domain(R.domain());C.ticks(10>a.length?a.length:10);ea.ticks(Cc).outerTickSize(0).tickFormat(Dc);Qa.ticks(Ec).outerTickSize(0).tickFormat(Fc);Jb=m.domain();K.x(z);oa&&Fa.x(m);h.append("g").attr("class", +1.4*Ea).transition().duration(100).attr("r",Ea)}function kb(a,b,d){zc(a,b);h.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+d).transition().duration(100).attr("r",0).remove()}function Wb(a,b,d,c){a?Vb(b,d,c):kb(b,d,c)}function Ac(a,b,d){}function Xb(a,b,d){}function Yb(a,b,d,c){}function Bc(a,b,d,c){var g,h,q="M",l,m,t,r,n,p=[];if(k(c))for(g=0;g=h;h+=diffx2)q+=c(a[g-1],a[g],h,t);return q}function lb(a){var b=l.data.targets=O(a),d,c;m.domain(d3.extent(a.map(function(a){return a.x})));y.domain(E(b,"y"));R.domain(E(b,"y2"));z.domain(m.domain());Oa.domain(y.domain());Pa.domain(R.domain());C.ticks(10>a.length?a.length:10);ea.ticks(Cc).outerTickSize(0).tickFormat(Dc);Qa.ticks(Ec).outerTickSize(0).tickFormat(Fc);Jb=m.domain();D.x(z);oa&&Fa.x(m);h.append("g").attr("class", "x axis").attr("clip-path",f?"":"url(#xaxis-clip)").attr("transform",L.x).call(f?ea:C);h.append("g").attr("class","y axis").attr("clip-path",f?"url(#yaxis-clip)":"").call(f?C:ea).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Gc);Db&&h.append("g").attr("class","y2 axis").attr("transform",L.y2).call(Qa);if(oa)h.append("rect").attr("class","zoom-rect").attr("width",r).attr("height",u).style("opacity",0).call(Fa).on("dblclick.zoom", null);d=h.append("g").attr("clip-path",Ga).attr("class","grid");Zb&&d.append("g").attr("class","xgrids");mb&&(c=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(mb).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:-p).attr("dy",-6).text(function(a){return a.text}));Hc&&d.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:p).attr("y2",f?-10:u);$b&&d.append("g").attr("class","ygrids");nb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(nb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});h.append("g").attr("clip-path",Ga).attr("class","regions");h.append("g").attr("clip-path",Ga).attr("class","chart");h.select(".chart").append("g").attr("class","event-rects").style("fill-opacity", @@ -26,39 +26,39 @@ null);d=h.append("g").attr("clip-path",Ga).attr("class","grid");Zb&&d.append("g" b).classed($,!1)}).on("mousemove",function(a,b){Z&&!Wa&&(ia||h.selectAll(".-shape-"+b).filter(function(a){return ka(a)}).each(function(a){a=d3.select(this).classed($,!0);"circle"===this.nodeName&&a.attr("r",bc);d3.select(".event-rect-"+b).style("cursor",null)}).filter(function(a){a=d3.select(this);if("circle"===this.nodeName)return Tb(this,Ea);if("rect"===this.nodeName)return Ub(this,a.attr("x"),a.attr("y"))}).each(function(a){a=d3.select(this);a.classed($)||(a.classed($,!0),"circle"===this.nodeName&& a.attr("r",Ea));d3.select(".event-rect-"+b).style("cursor","pointer")}))}).on("click",function(a,b){pb?pb=!1:h.selectAll(".-shape-"+b).each(function(a){var d=d3.select(this),c=d.classed(aa),e=!1,g;"circle"===this.nodeName?(e=Tb(this,1.5*Ea),g=Wb):"rect"===this.nodeName&&(e=Ub(this),g=Yb);if(ia||e)Z&&ka(a)&&(d.classed(aa,!c),g(!c,d,a,b)),Ic(a,d)})}).call(d3.behavior.drag().origin(Object).on("drag",function(a){if(Z&&!oa){a=qb[0];var b=qb[1],d=d3.mouse(this),c=d[0],d=d[1],e=Math.min(a,c),f=Math.max(a, c),k=ia?p:Math.min(b,d),l=ia?u:Math.max(b,d);h.select(".dragarea").attr("x",e).attr("y",k).attr("width",f-e).attr("height",l-k);h.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ka(a)}).each(function(a,b){var d=d3.select(this),c=d.classed(aa),g=d.classed(rb),h,q,m,p;h=!1;"circle"===this.nodeName?(h=1*d.attr("cx"),q=1*d.attr("cy"),p=Wb,h=e",c,e,g;for(c=0;c"+g+""+e+"";return b+""}),Jc=c(["tooltip","init","show"],!1),ra=c(["tooltip","init","x"],0),ec=c(["tooltip","init","position"],{top:"0px",left:"50px"}),tb=ya.replace("#","")+"-clip",Ga="url(#"+tb+")",G="timeseries"===hc,ga="categorized"=== +0,Hc=c(["point","focus","line","enabled"],!0),ac=c(["point","focus","expand","enabled"],!0),bc=c(["point","focus","expand","r"],ac?4:ob),Ea=c(["point","focus","select","r"],8),Ic=c(["point","onclick"],function(){}),yc=c(["point","onselected"],function(){}),zc=c(["point","onunselected"],function(){}),M=c(["regions"],[]),cc=c(["tooltip","contents"],function(a){var b="",c,e,g;for(c=0;c";return b+"
"+(H?a[0].x.getFullYear()+"."+(a[0].x.getMonth()+1)+"."+a[0].x.getDate():ga?a[0].x
"+g+""+e+"
"}),Jc=c(["tooltip","init","show"],!1),ra=c(["tooltip","init","x"],0),ec=c(["tooltip","init","position"],{top:"0px",left:"50px"}),tb=ya.replace("#","")+"-clip",Ga="url(#"+tb+")",H="timeseries"===hc,ga="categorized"=== hc,qb=null,Wa=!1,pb=!1,ca=qa?40:0,Sc=function(a){return function(b){for(var c=a.length-1,e=a[c];!e[1](b);)e=a[--c];return e[0](b)}}([[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()}]]),ha=d3.time.format(Pc).parse,Ab,Fb,Cb,Na,Eb,Gb,r,u,da,bb,na,Hb,Ib,eb,fb,m,y,R,z,Oa,Pa,C=ga?wb():d3.svg.axis(),ea=d3.svg.axis(),Qa=d3.svg.axis(),fa=ga?wb():d3.svg.axis();Q();U();var L={main:function(){return"translate("+J+","+p+")"},context:function(){return"translate("+I+","+ta+")"},legend:function(){return"translate("+La+","+xb+")"},y2:function(){return"translate("+(f?0:r)+ -","+(f?10:0)+")"},x:function(){return"translate(0,"+u+")"},subx:function(){return"translate(0,"+da+")"}};G&&C.tickFormat(Sc);ga?(C.categories(Ya).tickCentered(ic),fa.categories(Ya).tickCentered(ic)):(C.tickOffset=function(){return 0},fa.tickOffset=function(){return 0});var Lc=function(){var a=d3.svg.line().x(f?function(a){return E(a.id)(a.value)}:Va).y(f?Va:function(a){return E(a.id)(a.value)});return function(b){var c;if(jb(b))return"spline"===Y["string"===typeof b?b:b.id]?a.interpolate("cardinal"): -a.interpolate("linear"),0a?0:a},S=function(a,b){var c=[],e=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];0<=c.indexOf(b)||c.push(b);return e[c.indexOf(b)%e.length]}}(Qc,Rc),Za=d3.select(ya).append("svg").attr("width",r+J+F).attr("height",u+p+V),ub=Za.append("defs");ub.append("clipPath").attr("id",tb).append("rect").attr("y",p).attr("width",r).attr("height",u-p);ub.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x", --1).attr("y",-1).attr("width",r+2).attr("height",40);ub.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-J+1).attr("y",p-1).attr("width",J).attr("height",u-p+2);var h=Za.append("g").attr("transform",L.main),x=null;pa&&(x=Za.append("g").attr("transform",L.context));var sa=null;qa&&(sa=Za.append("g").attr("transform",L.legend));var ja=d3.select(ya).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility", -"hidden"),K=d3.svg.brush().on("brush",function(){H({withTransition:!1,withY:!1,withSubchart:!1})}),Fa=d3.behavior.zoom().on("zoom",oa?Nc:null),Ua=null,gb=null,Jb;l.focus=function(a){l.defocus();d3.selectAll(Ka(a)).filter(function(a){return ab(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};l.defocus=function(a){d3.selectAll(Ka(a)).filter(function(a){return ab(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};l.revert=function(a){d3.selectAll(Ka(a)).filter(function(a){return ab(a.id)}).classed("focused", +[d3.time.format(":%S"),function(a){return a.getSeconds()}],[d3.time.format(".%L"),function(a){return a.getMilliseconds()}]]),ha=d3.time.format(Pc).parse,Ab,Fb,Cb,Na,Eb,Gb,r,u,da,bb,na,Hb,Ib,eb,fb,m,y,R,z,Oa,Pa,C=ga?wb():d3.svg.axis(),ea=d3.svg.axis(),Qa=d3.svg.axis(),fa=ga?wb():d3.svg.axis();Q();U();var L={main:function(){return"translate("+K+","+p+")"},context:function(){return"translate("+J+","+ta+")"},legend:function(){return"translate("+La+","+xb+")"},y2:function(){return"translate("+(f?0:r)+ +","+(f?10:0)+")"},x:function(){return"translate(0,"+u+")"},subx:function(){return"translate(0,"+da+")"}};H&&C.tickFormat(Sc);ga?(C.categories(Ya).tickCentered(ic),fa.categories(Ya).tickCentered(ic)):(C.tickOffset=function(){return 0},fa.tickOffset=function(){return 0});var Lc=function(){var a=d3.svg.line().x(f?function(a){return F(a.id)(a.value)}:Va).y(f?Va:function(a){return F(a.id)(a.value)});return function(b){var c;if(jb(b))return"spline"===Y["string"===typeof b?b:b.id]?a.interpolate("cardinal"): +a.interpolate("linear"),0a?0:a},S=function(a,b){var c=[],e=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];0<=c.indexOf(b)||c.push(b);return e[c.indexOf(b)%e.length]}}(Qc,Rc),Za=d3.select(ya).append("svg").attr("width",r+K+G).attr("height",u+p+V),ub=Za.append("defs");ub.append("clipPath").attr("id",tb).append("rect").attr("y",p).attr("width",r).attr("height",u-p);ub.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x", +-1).attr("y",-1).attr("width",r+2).attr("height",40);ub.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-K+1).attr("y",p-1).attr("width",K).attr("height",u-p+2);var h=Za.append("g").attr("transform",L.main),x=null;pa&&(x=Za.append("g").attr("transform",L.context));var sa=null;qa&&(sa=Za.append("g").attr("transform",L.legend));var ja=d3.select(ya).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility", +"hidden"),D=d3.svg.brush().on("brush",function(){I({withTransition:!1,withY:!1,withSubchart:!1})}),Fa=d3.behavior.zoom().on("zoom",oa?Nc:null),Ua=null,gb=null,Jb;l.focus=function(a){l.defocus();d3.selectAll(Ka(a)).filter(function(a){return ab(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};l.defocus=function(a){d3.selectAll(Ka(a)).filter(function(a){return ab(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};l.revert=function(a){d3.selectAll(Ka(a)).filter(function(a){return ab(a.id)}).classed("focused", !1).transition().duration(100).style("opacity",1)};l.show=function(a){d3.selectAll(Ka(a)).transition().style("opacity",1)};l.hide=function(a){d3.selectAll(Ka(a)).transition().style("opacity",0)};l.load=function(a){s(a.done)&&(a.done=function(){});if("cacheIds"in a&&la(a.cacheIds))Ia(ma(a.cacheIds),a.done);else if("data"in a)Ia(O(data),a.done);else if("url"in a)d3.csv(a.url,function(b,c){Ia(O(c),a.done)});else if("rows"in a)Ia(O(ua(a.rows)),a.done);else if("columns"in a)Ia(O(va(a.columns)),a.done); -else throw Error("url or rows or columns is required.");};l.unload=function(a){l.data.targets=l.data.targets.filter(function(b){return b.id!=a});d3.selectAll(".target-"+a).transition().style("opacity",0).remove();qa&&(d3.selectAll(".legend-item-"+a).remove(),Xa(l.data.targets));0b.classes.indexOf(a)})});return M};l.data.get=function(a){a=l.data.getAsTarget(a);return k(a)?a.values.map(function(a){return a.value}):void 0};l.data.getAsTarget=function(a){var b=Ra(function(b){return b.id==a});return 0