diff --git a/c3.js b/c3.js index b36b233..22027aa 100644 --- a/c3.js +++ b/c3.js @@ -33,7 +33,8 @@ var __size_width = getConfig(['size','width'], null), __size_height = getConfig(['size','height'], null); - var __zoom_enabled = getConfig(['zoom','enabled'], false); + var __zoom_enabled = getConfig(['zoom','enabled'], false), + __zoom_extent = getConfig(['zoom','extent'], null); // data - data configuration checkConfig('data', 'data is required in config'); @@ -804,7 +805,8 @@ return this; }; zoom.orgScaleExtent = function () { - return [1, Math.max(maxDataCount()/10, 10)]; + var extent = __zoom_extent ? __zoom_extent : [1,10]; + return [extent[0], Math.max(maxDataCount()/extent[1], extent[1])]; }; zoom.updateScaleExtent = function () { var ratio = diffDomain(x.orgDomain())/diffDomain(orgXDomain), extent = this.orgScaleExtent(); diff --git a/c3.min.js b/c3.min.js index 9e392c7..e7fdc8b 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,64 +1,64 @@ -(function(wb){function ic(){function l(b,h){b.attr("transform",function(b){return"translate("+(h(b)+S)+",0)"})}function u(b,h){b.attr("transform",function(b){return"translate(0,"+h(b)+")"})}function Oa(b){var h=b[0];b=b[b.length-1];return ha?0:a}function ca(a){var c=Da[a.id];a.name=l(c)?c:a.id;return a}function wa(a){var c=a[0],d={},n=[],f,b;for(f=1;fq[d].indexOf(f.id)))for(b=0;b=g;g+=diffx2)p+=b(a[f-1],a[f],g,h);return p}function ob(a){var c=k.data.targets=da(a),d,b;N();S();m.domain(d3.extent(a.map(function(a){return a.x}))); -x.domain(B(c,"y"));O.domain(B(c,"y2"));V.domain(m.domain());Qa.domain(x.domain());Ra.domain(O.domain());M.ticks(10>a.length?a.length:10);ga.ticks(Hc).outerTickSize(0).tickFormat(Ic);Sa.ticks(Jc).outerTickSize(0).tickFormat(Kc);P=m.domain();E.x(V);ja&&F.x(m);Ha=d3.select(ya).append("svg").attr("width",t+H+C).attr("height",s+v+U);Ya=Ha.append("defs");Ya.append("clipPath").attr("id",pb).append("rect").attr("y",v).attr("width",t).attr("height",s-v);Ya.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x", +a.id}function yc(a){return kb(a)+" -circles -circles-"+a.id}function Nb(a){return kb(a)+" -bars -bars-"+a.id}function zc(a,c){return"-shape -shape-"+c+" -circle -circle-"+c}function Ob(a,c){return"-shape -shape-"+c+" -bar -bar-"+c}function Ac(a,c){return"region region-"+c+" "+("classes"in a?[].concat(a.classes).join(" "):"")}function Xa(a){return m(a.x)}function Fa(a){return m(D?ia(a.value):a.value)}function Pb(a){return x(a.value)}function W(a){return m(a.x)}function X(a){return h(a.id)(a.value)} +function Bc(){var a={},c=0,d,b;Ta(Aa).forEach(function(f){for(d=0;dq[d].indexOf(f.id)))for(b=0;b=g;g+=diffx2)p+=b(a[f-1],a[f],g,h);return p}function ob(a){var c=k.data.targets=da(a),d,b;N();S();m.domain(d3.extent(a.map(function(a){return a.x}))); +x.domain(B(c,"y"));O.domain(B(c,"y2"));V.domain(m.domain());Qa.domain(x.domain());Ra.domain(O.domain());M.ticks(10>a.length?a.length:10);ga.ticks(Ic).outerTickSize(0).tickFormat(Jc);Sa.ticks(Kc).outerTickSize(0).tickFormat(Lc);P=m.domain();E.x(V);ja&&F.x(m);Ha=d3.select(ya).append("svg").attr("width",t+H+C).attr("height",s+v+U);Ya=Ha.append("defs");Ya.append("clipPath").attr("id",pb).append("rect").attr("y",v).attr("width",t).attr("height",s-v);Ya.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x", -1).attr("y",-1).attr("width",t+2).attr("height",40);Ya.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-H+1).attr("y",v-1).attr("width",H).attr("height",s-v+2);g=Ha.append("g").attr("transform",I.main);w=qa?Ha.append("g").attr("transform",I.context):null;ra=sa?Ha.append("g").attr("transform",I.legend):null;Z=d3.select(ya).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden");g.append("g").attr("class", -"x axis").attr("clip-path",e?"":"url(#xaxis-clip)").attr("transform",I.x).call(e?ga:M);g.append("g").attr("class","y axis").attr("clip-path",e?"url(#yaxis-clip)":"").call(e?M:ga).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Lc);Fb&&g.append("g").attr("class","y2 axis").attr("transform",I.y2).call(Sa);if(ja)g.append("rect").attr("class","zoom-rect").attr("width",t).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(F).on("dblclick.zoom", -null);d=g.append("g").attr("clip-path",Ia).attr("class","grid");$b&&d.append("g").attr("class","xgrids");qb&&(b=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(qb).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-v).attr("dy",-6).text(function(a){return a.text}));Mc&&d.append("g").attr("class", +"x axis").attr("clip-path",e?"":"url(#xaxis-clip)").attr("transform",I.x).call(e?ga:M);g.append("g").attr("class","y axis").attr("clip-path",e?"url(#yaxis-clip)":"").call(e?M:ga).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Mc);Fb&&g.append("g").attr("class","y2 axis").attr("transform",I.y2).call(Sa);if(ja)g.append("rect").attr("class","zoom-rect").attr("width",t).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(F).on("dblclick.zoom", +null);d=g.append("g").attr("clip-path",Ia).attr("class","grid");$b&&d.append("g").attr("class","xgrids");qb&&(b=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(qb).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-v).attr("dy",-6).text(function(a){return a.text}));Nc&&d.append("g").attr("class", "xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",e?t:-10).attr("y1",e?-10:v).attr("y2",e?-10:s);ac&&d.append("g").attr("class","ygrids");rb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(rb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Ia).attr("class","regions");g.append("g").attr("clip-path",Ia).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity", 0).style("cursor",ja?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,c){return"event-rect event-rect-"+c}).style("cursor",$&&ka?"pointer":null).on("mouseover",function(a,c){if(!Za){var d=k.data.targets.map(function(a){return ca(a.values[c])}),b,n;if(0",b,e,f;for(b=0;b"+f+""+e+"";return c+""}),Oc=b(["tooltip","init", -"show"],!1),ta=b(["tooltip","init","x"],0),fc=b(["tooltip","init","position"],{top:"0px",left:"50px"}),pb=ya.replace("#","")+"-clip",Ia="url(#"+pb+")",D="timeseries"===hc,ha="categorized"===hc,ub=null,Za=!1,tb=!1,ea=sa?40:0,ia=d3.time.format(Uc).parse,Q=function(a,c){var b=[],e=null!==c?c:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(c){if(c in a)return a[c];0<=b.indexOf(c)||b.push(c);return e[b.indexOf(c)%e.length]}}(Vc,Wc),nc=function(){var a= -[[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()}]];return function(c){for(var b= -a.length-1,e=a[b];!e[1](c);)e=a[--b];return e[0](c)}}(),Cb,Hb,Eb,Pa,Gb,Ib,t,s,fa,bb,pa,Jb,Kb,eb,fb,m,x,O,V,Qa,Ra,M,ga,Sa,za,jc=e?"left":"bottom",kc=e?db?"top":"bottom":db?"right":"left",lc=e?cb?"bottom":"top":cb?"left":"right",mc="bottom",I={main:function(){return"translate("+H+","+v+")"},context:function(){return"translate("+G+","+ua+")"},legend:function(){return"translate("+Oa+","+xb+")"},y2:function(){return"translate("+(e?0:t)+","+(e?10:0)+")"},x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+ -fa+")"}},Qc=function(){var a=d3.svg.line().x(e?function(a){return h(a.id)(a.value)}:Xa).y(e?Xa:function(a){return h(a.id)(a.value)});return function(c){var b;if(mb(c))return"spline"===Y["string"===typeof c?c:c.id]?a.interpolate("cardinal"):a.interpolate("linear"),0",b,e,f;for(b=0;b"+f+""+e+"";return c+""}), +Pc=b(["tooltip","init","show"],!1),ta=b(["tooltip","init","x"],0),fc=b(["tooltip","init","position"],{top:"0px",left:"50px"}),pb=ya.replace("#","")+"-clip",Ia="url(#"+pb+")",D="timeseries"===ic,ha="categorized"===ic,ub=null,Za=!1,tb=!1,ea=sa?40:0,ia=d3.time.format(Vc).parse,Q=function(a,c){var b=[],e=null!==c?c:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(c){if(c in a)return a[c];0<=b.indexOf(c)||b.push(c);return e[b.indexOf(c)%e.length]}}(Wc, +Xc),oc=function(){var a=[[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()}]]; +return function(c){for(var b=a.length-1,e=a[b];!e[1](c);)e=a[--b];return e[0](c)}}(),Cb,Hb,Eb,Pa,Gb,Ib,t,s,fa,bb,pa,Jb,Kb,eb,fb,m,x,O,V,Qa,Ra,M,ga,Sa,za,kc=e?"left":"bottom",lc=e?db?"top":"bottom":db?"right":"left",mc=e?cb?"bottom":"top":cb?"left":"right",nc="bottom",I={main:function(){return"translate("+H+","+v+")"},context:function(){return"translate("+G+","+ua+")"},legend:function(){return"translate("+Oa+","+xb+")"},y2:function(){return"translate("+(e?0:t)+","+(e?10:0)+")"},x:function(){return"translate(0,"+ +s+")"},subx:function(){return"translate(0,"+fa+")"}},Rc=function(){var a=d3.svg.line().x(e?function(a){return h(a.id)(a.value)}:Xa).y(e?Xa:function(a){return h(a.id)(a.value)});return function(c){var b;if(mb(c))return"spline"===Y["string"===typeof c?c:c.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.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