Browse Source

Set withUpdateXDomain false

pull/1/head
Masayuki Tanaka 11 years ago
parent
commit
651a26a5aa
  1. 12
      c3.js
  2. 14
      c3.min.js

12
c3.js

@ -1217,7 +1217,7 @@
updateTargets(targets);
// Draw with targets
redraw({withTransition:false});
redraw({withTransition:false, withUpdateXDomain:true});
// Show tooltip if needed
if (__tooltip_init_show) {
@ -1250,7 +1250,7 @@
withY = isDefined(options.withY) ? options.withY : true;
withSubchart = isDefined(options.withSubchart) ? options.withSubchart : true;
withTransition = isDefined(options.withTransition) ? options.withTransition : true;
withUpdateXDomain = isDefined(options.withUpdateXDomain) ? options.withUpdateXDomain : true;
withUpdateXDomain = isDefined(options.withUpdateXDomain) ? options.withUpdateXDomain : false;
duration = withTransition ? 250 : 0;
@ -1452,15 +1452,15 @@
redraw({
withTransition: false,
withY: false,
withSubchart: false
withSubchart: false,
withUpdateXDomain: true
});
}
function redrawForZoom() {
redraw({
withTransition: false,
withY: false,
withSubchart: false,
withUpdateXDomain: false
withSubchart: false
});
if (d3.event.sourceEvent.type === 'mousemove') {
cancelClick = true;
@ -1495,7 +1495,7 @@
updateLegend(c3.data.targets, {withTransition:false});
}
// Draw with new sizes & scales
redraw({withTransition:false});
redraw({withTransition:false, withUpdateXDomain:true});
}
function updateTargets (targets) {

14
c3.min.js vendored

@ -29,16 +29,16 @@ c).classed($,!1)}).on("mousemove",function(a,c){Z&&!$a&&(ha||g.selectAll(".-shap
a.attr("r",Fa));d3.select(".event-rect-"+c).style("cursor","pointer")}))}).on("click",function(a,c){ub?ub=!1:g.selectAll(".-shape-"+c).each(function(a){var d=d3.select(this),b=d.classed(aa),f=!1,e;"circle"===this.nodeName?(f=Vb(this,1.5*Fa),e=Yb):"rect"===this.nodeName&&(f=Wb(this),e=$b);if(ha||f)Z&&ia(a)&&(d.classed(aa,!b),e(!b,d,a,c)),Oc(a,d)})}).call(d3.behavior.drag().origin(Object).on("drag",function(a){if(Z&&!oa){a=vb[0];var c=vb[1],d=d3.mouse(this),b=d[0],d=d[1],e=Math.min(a,b),m=Math.max(a,
b),k=ha?v:Math.min(c,d),l=ha?t:Math.max(c,d);g.select(".dragarea").attr("x",e).attr("y",k).attr("width",m-e).attr("height",l-k);g.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ia(a)}).each(function(a,c){var d=d3.select(this),b=d.classed(aa),f=d.classed(wb),g,p,h,n;g=!1;"circle"===this.nodeName?(g=1*d.attr("cx"),p=1*d.attr("cy"),n=Yb,g=e<g&&g<m&&k<p&&p<l):"rect"===this.nodeName&&(g=1*d.attr("x"),p=1*d.attr("y"),h=1*d.attr("width"),n=$b,g=e<g+h&&g<m&&p<l);g^f&&(d.classed(wb,!f),
d.classed(aa,!b),n(!b,d,a,c))})}}).on("dragstart",function(){Z&&(vb=d3.mouse(this),g.select(".chart").append("rect").attr("class","dragarea").style("opacity",0.1),$a=!0)}).on("dragend",function(){Z&&(g.select(".dragarea").transition().duration(100).style("opacity",0).remove(),g.selectAll(".-shape").classed(wb,!1),$a=!1)})).call(Ga).on("dblclick.zoom",null);g.select(".chart").append("g").attr("class","chart-bars");g.select(".chart").append("g").attr("class","chart-lines");null!==Ja&&E.extent("function"!==
typeof Ja?Ja:D?Ja(Wa,ib):Ja(0,Xa()-1));pa&&(x.append("g").attr("clip-path",Ia).attr("class","chart"),x.select(".chart").append("g").attr("class","chart-bars"),x.select(".chart").append("g").attr("class","chart-lines"),x.append("g").attr("clip-path",Ia).attr("class","x brush").call(E).selectAll("rect").attr("height",ea),x.append("g").attr("class","x axis").attr("transform",I.subx).call(za));ra&&ab(c);fc(c);F({withTransition:!1});if(Pc){if(D&&"string"==typeof sa){sa=ga(sa);for(a=0;a<c[0].values.length&&
0!=c[0].values[a].x-sa;a++);sa=a}Y.html(ec(c.map(function(a){return ba(a.values[sa])})));Y.style("top",gc.top).style("left",gc.left).style("visibility","visible")}}function F(a){var c,d=Bc(),b=d.__max__+1,f,h,p,q,s,u;a=l(a)?a:{};c=l(a.withY)?a.withY:!0;s=l(a.withSubchart)?a.withSubchart:!0;u=l(a.withTransition)?a.withTransition:!0;a=l(a.withUpdateXDomain)?a.withUpdateXDomain:!0;u=u?250:0;a&&(r.domain(E.empty()?ya:E.extent()),oa&&Ga.x(r));y.domain(B(k.data.targets,"y"));O.domain(B(k.data.targets,"y2"));
g.select(".x.axis").transition().duration(e?u:0).call(e?fa:M);g.select(".y.axis").transition().duration(e?0:u).call(e?M:fa);g.select(".y2.axis").transition().call(Sa);Qa.domain(y.domain());Ra.domain(O.domain());Y.style("visibility","hidden");g.select("line.xgrid-focus").style("visibility","hidden").attr("y2",t);if(ac){if("year"===Qc)for(a=[],firstYear=Wa.getFullYear(),lastYear=ib.getFullYear(),f=firstYear;f<=lastYear;f++)a.push(new Date(f+"-01-01 00:00:00"));else a=r.ticks(10);a=g.select(".xgrids").selectAll(".xgrid").data(a);
typeof Ja?Ja:D?Ja(Wa,ib):Ja(0,Xa()-1));pa&&(x.append("g").attr("clip-path",Ia).attr("class","chart"),x.select(".chart").append("g").attr("class","chart-bars"),x.select(".chart").append("g").attr("class","chart-lines"),x.append("g").attr("clip-path",Ia).attr("class","x brush").call(E).selectAll("rect").attr("height",ea),x.append("g").attr("class","x axis").attr("transform",I.subx).call(za));ra&&ab(c);fc(c);F({withTransition:!1,withUpdateXDomain:!0});if(Pc){if(D&&"string"==typeof sa){sa=ga(sa);for(a=
0;a<c[0].values.length&&0!=c[0].values[a].x-sa;a++);sa=a}Y.html(ec(c.map(function(a){return ba(a.values[sa])})));Y.style("top",gc.top).style("left",gc.left).style("visibility","visible")}}function F(a){var c,d=Bc(),b=d.__max__+1,f,h,p,q,s,u;a=l(a)?a:{};c=l(a.withY)?a.withY:!0;s=l(a.withSubchart)?a.withSubchart:!0;u=l(a.withTransition)?a.withTransition:!0;a=l(a.withUpdateXDomain)?a.withUpdateXDomain:!1;u=u?250:0;a&&(r.domain(E.empty()?ya:E.extent()),oa&&Ga.x(r));y.domain(B(k.data.targets,"y"));O.domain(B(k.data.targets,
"y2"));g.select(".x.axis").transition().duration(e?u:0).call(e?fa:M);g.select(".y.axis").transition().duration(e?0:u).call(e?M:fa);g.select(".y2.axis").transition().call(Sa);Qa.domain(y.domain());Ra.domain(O.domain());Y.style("visibility","hidden");g.select("line.xgrid-focus").style("visibility","hidden").attr("y2",t);if(ac){if("year"===Qc)for(a=[],firstYear=Wa.getFullYear(),lastYear=ib.getFullYear(),f=firstYear;f<=lastYear;f++)a.push(new Date(f+"-01-01 00:00:00"));else a=r.ticks(10);a=g.select(".xgrids").selectAll(".xgrid").data(a);
a.enter().append("line").attr("class","xgrid");a.exit().remove();g.selectAll(".xgrid").attr("x1",function(a){return r(a)-M.tickOffset()}).attr("x2",function(a){return r(a)-M.tickOffset()}).attr("y1",v).attr("y2",t)}rb&&(a=g.selectAll(".xgrid-lines"),a.selectAll("line").attr("x1",e?0:Ea).attr("x2",e?n:Ea).attr("y1",e?Ea:v).attr("y2",e?Ea:t),a.selectAll("text").attr("x",e?n:0).attr("y",Ea));c&&bc&&(ygrid=g.select(".ygrids").selectAll(".ygrid").data(y.ticks(10)),ygrid.enter().append("line").attr("class",
"ygrid"),ygrid.attr("x1",e?y:0).attr("x2",e?y:n).attr("y1",e?0:y).attr("y2",e?t:y).attr("opacity",0).transition().attr("opacity",1),ygrid.exit().remove());c&&sb&&g.select(".ygrid-lines").selectAll(".ygrid-line").attr("y1",Qb).attr("y2",Qb);h=na?1.2*M.tickOffset()/b:0.6*((e?t:n)*S(!1)/(Xa()-1));p=Tb(e?null:t);a=Rb(h,b,d);f=Sb(p,d,e);c=g.selectAll(".-bars").selectAll(".-bar").data(Ub);c.transition().duration(u).attr("x",e?f:a).attr("y",e?a:f).attr("width",e?p:h).attr("height",e?h:p);c.enter().append("rect").attr("class",
Pb).attr("x",e?f:a).attr("y",e?a:f).attr("width",e?p:h).attr("height",e?h:p).style("opacity",0).transition().duration(u).style("opacity",1);c.exit().transition().duration(u).style("opacity",0).remove();g.selectAll(".-line").transition().duration(u).attr("d",Rc);c=g.selectAll(".-circles").selectAll(".-circle").data(Cc);c.transition().duration(u).attr("cx",e?W:V).attr("cy",e?V:W);c.enter().append("circle").attr("class",zc).attr("cx",e?W:V).attr("cy",e?V:W).attr("r",tb);c.exit().remove();pa&&(null!==
d3.event&&"zoom"===d3.event.type&&(E.extent(r.orgDomain()),x.select(".x.brush").call(E)),s&&(x.select(".x.axis").transition().duration(e?u:0).call(e?fa:za),E.empty()||(E.extent(r.orgDomain()),x.select(".x.brush").call(E)),h=na?1.2*za.tickOffset()/b:0.6*((e?t:n)*S(!0)/(Xa()-1)),p=Tb(ea,!0),a=Rb(h,b,d,!0),f=Sb(p,d,!1,!0),contextBar=x.selectAll(".-bars").selectAll(".-bar").data(Ub),contextBar.transition().duration(u).attr("x",a).attr("y",f).attr("width",h).attr("height",p),contextBar.enter().append("rect").attr("class",
Pb).attr("x",a).attr("y",f).attr("width",h).attr("height",p).style("opacity",0).transition().style("opacity",1),contextBar.exit().transition().style("opacity",0).remove(),x.selectAll(".-line").transition().duration(u).attr("d",Sc)));g.selectAll(".selected-circles").filter(function(a){return Aa(a)}).selectAll("circle").remove();g.selectAll(".selected-circle").transition().duration(u).attr("cx",e?W:V).attr("cy",e?V:W);q=(e?t:n)*S()/(Xa()-1);d=function(a){return r(a.x)-q/2};g.selectAll(".event-rect").attr("x",
e?0:d).attr("y",e?d:0).attr("width",e?n:q).attr("height",e?q:t);mainRegion=g.select(".regions").selectAll("rect.region").data(J);mainRegion.enter().append("rect");mainRegion.attr("class",Ac).attr("x",e?0:la).attr("y",e?la:v).attr("width",e?n:ua).attr("height",e?ua:t).style("fill-opacity",function(a){return l(a.opacity)?a.opacity:0.1});mainRegion.exit().transition().duration(u).style("fill-opacity",0).remove()}function Tc(){F({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!1});"mousemove"===
d3.event.sourceEvent.type&&(ub=!0)}function fc(a){var c;g.select(".chart-bars").selectAll(".chart-bar").data(a).enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}).style("pointer-events","none").style("opacity",0).append("g").attr("class",Ob).style("fill",function(a){return P(a.id)}).style("stroke",function(a){return P(a.id)}).style("stroke-width",0).style("cursor",function(a){return ia(a)?"pointer":null});c=g.select(".chart-lines").selectAll(".chart-line").data(a).enter().append("g").attr("class",
e?0:d).attr("y",e?d:0).attr("width",e?n:q).attr("height",e?q:t);mainRegion=g.select(".regions").selectAll("rect.region").data(J);mainRegion.enter().append("rect");mainRegion.attr("class",Ac).attr("x",e?0:la).attr("y",e?la:v).attr("width",e?n:ua).attr("height",e?ua:t).style("fill-opacity",function(a){return l(a.opacity)?a.opacity:0.1});mainRegion.exit().transition().duration(u).style("fill-opacity",0).remove()}function Tc(){F({withTransition:!1,withY:!1,withSubchart:!1});"mousemove"===d3.event.sourceEvent.type&&
(ub=!0)}function fc(a){var c;g.select(".chart-bars").selectAll(".chart-bar").data(a).enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}).style("pointer-events","none").style("opacity",0).append("g").attr("class",Ob).style("fill",function(a){return P(a.id)}).style("stroke",function(a){return P(a.id)}).style("stroke-width",0).style("cursor",function(a){return ia(a)?"pointer":null});c=g.select(".chart-lines").selectAll(".chart-line").data(a).enter().append("g").attr("class",
function(a){return"chart-line target target-"+a.id}).style("pointer-events","none").style("opacity",0);c.append("path").attr("class",Nb).style("stroke",function(a){return P(a.id)});c.append("g").attr("class",function(a){return"selected-circles selected-circles-"+a.id});c.append("g").attr("class",yc).style("fill",function(a){return P(a.id)}).style("cursor",function(a){return ia(a)?"pointer":null});a.forEach(function(a){g.selectAll(".selected-circles-"+a.id).selectAll(".selected-circle").each(function(c){c.value=
a.values[c.x].value})});pa&&(c=x.select(".chart-bars").selectAll(".chart-bar").data(a),c=c.enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}).style("opacity",0),c.append("g").attr("class",Ob).style("fill",function(a){return P(a.id)}),c=x.select(".chart-lines").selectAll(".chart-line").data(a),c=c.enter().append("g").attr("class",function(a){return"chart-line target target-"+a.id}).style("opacity",0),c.append("path").attr("class",Nb).style("stroke",function(a){return P(a.id)}));
ra&&ab(a);d3.selectAll(".target").transition().style("opacity",1)}function Ka(a,c){k.data.targets.forEach(function(c){for(var b=0;b<a.length;b++)if(c.id===a[b].id){c.values=a[b].values;a.splice(b,1);break}});k.data.targets=k.data.targets.concat(a);fc(k.data.targets);F();c()}function ab(a,c){var b=jb(a),e,f=n/2-La*Object.keys(a).length/2,g;c=s(c)?{}:c;g=l(c.withTransition)?c.withTransition:!0;e=qa.selectAll(".legend-item").data(b).enter().append("g").attr("class",function(a){return"legend-item legend-item-"+
@ -54,11 +54,11 @@ ic,vb=null,$a=!1,ub=!1,da=ra?40:0,ga=d3.time.format(Vc).parse,P=function(a,c){va
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()}]];return function(c){for(var b=a.length-1,e=a[b];!e[1](c);)e=a[--b];return e[0](c)}}(),Db,Ib,Fb,Pa,Hb,Jb,n,t,ea,cb,ma,Kb,Lb,fb,gb,r,y,O,U,Qa,Ra,M,fa,Sa,za,kc=e?"left":"bottom",lc=e?eb?"top":"bottom":eb?"right":"left",
mc=e?db?"bottom":"top":db?"left":"right",nc="bottom",I={main:function(){return"translate("+H+","+v+")"},context:function(){return"translate("+G+","+ta+")"},legend:function(){return"translate("+Oa+","+yb+")"},y2:function(){return"translate("+(e?0:n)+","+(e?10:0)+")"},x:function(){return"translate(0,"+t+")"},subx:function(){return"translate(0,"+ea+")"}},Rc=function(){var a=d3.svg.line().x(e?function(a){return h(a.id)(a.value)}:Ya).y(e?Ya:function(a){return h(a.id)(a.value)});return function(c){var b;
if(nb(c))return"spline"===X["string"===typeof c?c:c.id]?a.interpolate("cardinal"):a.interpolate("linear"),0<Object.keys(hc).length?Hc(c.values,r,h(c.id),hc[c.id]):a(c.values);b=r(c.values[0].x);c=h(c.id)(c.values[0].value);return e?"M "+c+" "+b:"M "+b+" "+c}}(),Sc=function(){var a=d3.svg.line().x(function(a){return U(a.x)}).y(function(a){return Na(a.id)(a.value)});return function(c){return nb(c)?a(c.values):"M "+U(c.values[0].x)+" "+Na(c.id)(c.values[0].value)}}(),E=d3.svg.brush().on("brush",function(){F({withTransition:!1,
withY:!1,withSubchart:!1})}),Ga=d3.behavior.zoom().on("zoom",oa?Tc:null),Ha,Za,g,x,qa,Y,Wa=null,ib=null,ya;k.focus=function(a){k.defocus();d3.selectAll(Ma(a)).filter(function(a){return kb(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};k.defocus=function(a){d3.selectAll(Ma(a)).filter(function(a){return kb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};k.revert=function(a){d3.selectAll(Ma(a)).filter(function(a){return kb(a.id)}).classed("focused",
withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),Ga=d3.behavior.zoom().on("zoom",oa?Tc:null),Ha,Za,g,x,qa,Y,Wa=null,ib=null,ya;k.focus=function(a){k.defocus();d3.selectAll(Ma(a)).filter(function(a){return kb(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};k.defocus=function(a){d3.selectAll(Ma(a)).filter(function(a){return kb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};k.revert=function(a){d3.selectAll(Ma(a)).filter(function(a){return kb(a.id)}).classed("focused",
!1).transition().duration(100).style("opacity",1)};k.show=function(a){d3.selectAll(Ma(a)).transition().style("opacity",1)};k.hide=function(a){d3.selectAll(Ma(a)).transition().style("opacity",0)};k.load=function(a){s(a.done)&&(a.done=function(){});if("cacheIds"in a&&K(a.cacheIds))Ka(bb(a.cacheIds),a.done);else if("data"in a)Ka(ca(data),a.done);else if("url"in a)d3.csv(a.url,function(c,b){Ka(ca(b),a.done)});else if("rows"in a)Ka(ca(va(a.rows)),a.done);else if("columns"in a)Ka(ca(wa(a.columns)),a.done);
else throw Error("url or rows or columns is required.");};k.unload=function(a){k.data.targets=k.data.targets.filter(function(c){return c.id!=a});d3.selectAll(".target-"+a).transition().style("opacity",0).remove();ra&&(d3.selectAll(".legend-item-"+a).remove(),ab(k.data.targets));0<k.data.targets.length&&F()};k.selected=function(a){a=l(a)?"-"+a:"";return d3.merge(g.selectAll(".-shapes"+a).selectAll(".-shape").filter(function(){return d3.select(this).classed(aa)}).map(function(a){return a.map(function(a){return a.__data__})}))};
k.select=function(a,c,b){Z&&g.selectAll(".-shapes").selectAll(".-shape").each(function(e,f){var g="circle"===this.nodeName?Xb:Gc,h="circle"===this.nodeName?ob:Zb;0<=c.indexOf(f)?ia(e)&&(ha||s(a)||0<=a.indexOf(e.id))&&g(d3.select(this).classed(aa,!0),e,f):l(b)&&b&&h(d3.select(this).classed(aa,!1),e,f)})};k.unselect=function(a,b){Z&&g.selectAll(".-shapes").selectAll(".-shape").each(function(d,e){var f="circle"===this.nodeName?ob:Zb;(s(b)||0<=b.indexOf(e))&&ia(d)&&(ha||s(a)||0<=a.indexOf(d.id))&&f(d3.select(this).classed(aa,
!1),d,e)})};k.toLine=function(a){mb(a,"line");F()};k.toSpline=function(a){mb(a,"spline");F()};k.toBar=function(a){mb(a,"bar");F()};k.groups=function(a){if(s(a))return w;w=a;F();return w};k.regions=function(a){if(s(a))return J;J=a;F();return J};k.regions.add=function(a){if(s(a))return J;J=J.concat(a);F();return J};k.regions.remove=function(a,b){var d=[].concat(a);b=l(b)?b:{};d.forEach(function(a){var d=d3.selectAll("."+a);l(b.duration)&&(d=d.transition().duration(b.duration).style("fill-opacity",0));
d.remove();J=J.filter(function(b){return 0>b.classes.indexOf(a)})});return J};k.data.get=function(a){a=k.data.getAsTarget(a);return l(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Ta(function(b){return b.id==a});return 0<b.length?b[0]:void 0};if("url"in Q.data)d3.csv(Q.data.url,function(a,b){pb(b)});else if("rows"in Q.data)pb(va(Q.data.rows));else if("columns"in Q.data)pb(wa(Q.data.columns));else throw Error("url or rows or columns is required.");xb.onresize=
function(){N();R();E.x(U);oa&&Ga.x(r);d3.select("svg").attr("width",cb).attr("height",ma);d3.select("#"+qb).select("rect").attr("width",n).attr("height",t);d3.select("#xaxis-clip").select("rect").attr("width",n+2);d3.select(".zoom-rect").attr("width",n).attr("height",t);g.select(".x.axis").attr("transform",I.x);g.select(".y2.axis").attr("transform",I.y2);pa&&(x.select(".x.brush").selectAll("rect").attr("height",ea),x.attr("transform",I.context),x.select(".x.axis").attr("transform",I.subx));ra&&(qa.attr("transform",
I.legend),ab(k.data.targets,{withTransition:!1}));F({withTransition:!1})};return k}})(window);
I.legend),ab(k.data.targets,{withTransition:!1}));F({withTransition:!1,withUpdateXDomain:!0})};return k}})(window);

Loading…
Cancel
Save