diff --git a/c3.js b/c3.js index 6573efc..a5f0a04 100644 --- a/c3.js +++ b/c3.js @@ -561,12 +561,12 @@ yDomainMin = center - yDomainAbs; } if (axisId === 'y' && __axis_y_padding) { - padding_top = __axis_y_padding.top ? __axis_y_padding.top : padding; - padding_bottom = __axis_y_padding.bottom ? __axis_y_padding.bottom : padding; + padding_top = isValue(__axis_y_padding.top) ? __axis_y_padding.top : padding; + padding_bottom = isValue(__axis_y_padding.bottom) ? __axis_y_padding.bottom : padding; } if (axisId === 'y2' && __axis_y2_padding) { - padding_top = __axis_y2_padding.top ? __axis_y2_padding.top : padding; - padding_bottom = __axis_y2_padding.bottom ? __axis_y2_padding.bottom : padding; + padding_top = isValue(__axis_y2_padding.top) ? __axis_y2_padding.top : padding; + padding_bottom = isValue(__axis_y2_padding.bottom) ? __axis_y2_padding.bottom : padding; } // Bar chart with only positive values should be 0-based if (hasBarType(yTargets) && !hasNegativeValueInTargets(yTargets)) { diff --git a/c3.min.js b/c3.min.js index acbc672..e0cf5b9 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,90 +1,90 @@ -(function(P){function wd(){function v(e,g){e.attr("transform",function(e){return"translate("+(g(e)+ga)+", 0)"})}function y(e,g){e.attr("transform",function(e){return"translate(0,"+g(e)+")"})}function N(e){var g=e[0];e=e[e.length-1];return ga?a:0}),c=1;c+a||(b[d][c]+=+a)});return e.max(Object.keys(b).map(function(a){return e.max(b[a])}))}function nb(a){var b=ob(function(b){return S(b.id)===a}),c="y2"===a?Kd:Ld,d="y2"===a?Md:Nd,c=c?c:Hd(b),d=d?d:Id(b),f=0.1*Math.abs(d-c),e=f,g=f,h="y2"===a?Od:Pd;h&&(c=Math.max(Math.abs(c),Math.abs(d)),d=c-h,c=h-c);"y"===a&&Na&&(e=Na.top?Na.top:f,g=Na.bottom?Na.bottom:f);"y2"===a&&Oa&&(e=Oa.top?Oa.top:f,g=Oa.bottom? -Oa.bottom:f);ja(b,"bar")&&!Bc(b)&&(g=c);return[c-g,d+e]}function Qd(a){return e.min(a,function(a){return e.min(a.values,function(a){return a.x})})}function Rd(a){return e.max(a,function(a){return e.max(a.values,function(a){return a.x})})}function pb(a){var b=[Qd(a),Rd(a)];a=b[0];var b=b[1],c=ka?0:0.01*Math.abs(a-b);a=D?new Date(a.getTime()-c):a-c;b=D?new Date(b.getTime()+c):b+c;return[a,b]}function za(a){return a[1]-a[0]}function Sd(a){for(var b=0;ba?0:a}function Ec(a){return sa&&a===sa||ca&&Ud(ca,a)}function Vd(a){return!Ec(a)}function Wd(a){Object.keys(a).forEach(function(b){ca[b]=a[b]})}function rb(a){var b;a&&(b=Pa[a.id],a.name=b?b:a.id);return a}function Fc(a){var b=a[0],c={},d=[],f,e;for(f=1;fa?a:0}),c=1;c+a||(b[d][c]+=+a)});return e.max(Object.keys(b).map(function(a){return e.max(b[a])}))}function nb(a){var b=ob(function(b){return S(b.id)===a}),c="y2"===a?Kd:Ld,d="y2"===a?Md:Nd,c=c?c:Hd(b),d=d?d:Id(b),f=0.1*Math.abs(d-c),e=f,g=f,h="y2"===a?Od:Pd;h&&(c=Math.max(Math.abs(c),Math.abs(d)),d=c-h,c=h-c);"y"===a&&Na&&(e=z(Na.top)?Na.top:f,g=z(Na.bottom)?Na.bottom:f);"y2"===a&&Oa&&(e=z(Oa.top)?Oa.top:f,g=z(Oa.bottom)? +Oa.bottom:f);ja(b,"bar")&&!Bc(b)&&(g=c);return[c-g,d+e]}function Qd(a){return e.min(a,function(a){return e.min(a.values,function(a){return a.x})})}function Rd(a){return e.max(a,function(a){return e.max(a.values,function(a){return a.x})})}function pb(a){var b=[Qd(a),Rd(a)];a=b[0];var b=b[1],c=ka?0:0.01*Math.abs(a-b);a=E?new Date(a.getTime()-c):a-c;b=E?new Date(b.getTime()+c):b+c;return[a,b]}function za(a){return a[1]-a[0]}function Sd(a){for(var b=0;ba?0:a}function Ec(a){return sa&&a===sa||ca&&Ud(ca,a)}function Vd(a){return!Ec(a)}function Wd(a){Object.keys(a).forEach(function(b){ca[b]=a[b]})}function rb(a){var b;a&&(b=Pa[a.id],a.name=b?b:a.id);return a}function Fc(a){var b=a[0],c={},d=[],f,e;for(f=1;fb&&(c=a,b=a.values.length)}):c=a?k.data.targets[0]:null;return c}function Ra(a){a=y(a)?k.data.targets: a;return a.map(function(a){return a.id})}function Jc(a){var b=Ra(),c;for(c=0;ca})} function Jd(a){return Kc(a,function(a){return 0f&&(e-=c+30)),c=b[1]+15+df&&(e-=c+30)),c=b[1]+15+dw[c].indexOf(f.id)))for(d=0;d=e;e+=p)g+=d(a[f-1],a[f],e,m)}return g}function cc(a){var b;tb=e.select(ya);if(tb.empty())P.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{tb.html("");k.data.x={};k.data.targets=Qa(a);wa();Z();m.domain(e.extent(pb(k.data.targets)));z.domain(nb("y")); -ba.domain(nb("y2"));V.domain(m.domain());ib.domain(z.domain());jb.domain(ba.domain());J.ticks(10>a.length?a.length:10);Aa.ticks(oe).outerTickSize(0).tickFormat(dc);kb.ticks(pe).outerTickSize(0).tickFormat(qe);U=m.domain();K.scale(V);ua&&F.scale(m);n=e.select(ya).append("svg").attr("width",r+C+aa).attr("height",s+q+M).on("mouseenter",re).on("mouseleave",se);ub=n.append("defs");ub.append("clipPath").attr("id",ec).append("rect").attr("y",q).attr("width",r).attr("height",s-q);ub.append("clipPath").attr("id", -"xaxis-clip").append("rect").attr("x",-1-C).attr("y",-20).attr("width",X).attr("height",pa);ub.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-C+1).attr("y",q-1).attr("width",Bb).attr("height",xd);l=n.append("g").attr("transform",L.main);G=Ea?n.append("g").attr("transform",L.context):null;Fa=Ga?n.append("g").attr("transform",L.legend):null;W=e.select(ya).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");l.append("g").attr("class", -"x axis").attr("clip-path",h?"":"url("+document.URL+"#xaxis-clip)").attr("transform",L.x).call(h?Aa:J).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(te);l.append("g").attr("class","y axis").attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":"").call(h?J:Aa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(ue);Eb&&l.append("g").attr("class","y2 axis").attr("transform", -L.y2).call(kb);a=l.append("g").attr("clip-path",Xa).attr("class","grid");jd&&a.append("g").attr("class","xgrids");fc&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(fc).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",h?"":"rotate(-90)").attr("dx",h?0:-q).attr("dy",-5).text(function(a){return a.text})); +d){a?ed(b,c,d):Yb(b,c,d)}function me(){}function gd(){}function hd(a,b,c,d){}function Zb(a){return a.filter(function(a){return z(a.value)})}function $b(a,b){return(b?l.selectAll(".-circles-"+b):l).selectAll(".-circle"+(z(a)?"-"+a:""))}function ac(a){$b(a).filter(function(){return e.select(this).classed(ea)}).classed(ea,!1).attr("r",bc)}function ne(a,b,c,d){var f,e,g="M",k,l,m,id,n,ta=[];if(v(d))for(f=0;f=e;e+=p)g+=d(a[f-1],a[f],e,m)}return g}function cc(a){var b;tb=e.select(ya);if(tb.empty())P.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{tb.html("");k.data.x={};k.data.targets=Qa(a);wa();Z();m.domain(e.extent(pb(k.data.targets)));A.domain(nb("y")); +ba.domain(nb("y2"));V.domain(m.domain());ib.domain(A.domain());jb.domain(ba.domain());K.ticks(10>a.length?a.length:10);Aa.ticks(oe).outerTickSize(0).tickFormat(dc);kb.ticks(pe).outerTickSize(0).tickFormat(qe);U=m.domain();L.scale(V);ua&&G.scale(m);n=e.select(ya).append("svg").attr("width",r+D+aa).attr("height",s+q+N).on("mouseenter",re).on("mouseleave",se);ub=n.append("defs");ub.append("clipPath").attr("id",ec).append("rect").attr("y",q).attr("width",r).attr("height",s-q);ub.append("clipPath").attr("id", +"xaxis-clip").append("rect").attr("x",-1-D).attr("y",-20).attr("width",X).attr("height",pa);ub.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-D+1).attr("y",q-1).attr("width",Bb).attr("height",xd);l=n.append("g").attr("transform",M.main);H=Ea?n.append("g").attr("transform",M.context):null;Fa=Ga?n.append("g").attr("transform",M.legend):null;W=e.select(ya).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");l.append("g").attr("class", +"x axis").attr("clip-path",h?"":"url("+document.URL+"#xaxis-clip)").attr("transform",M.x).call(h?Aa:K).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(te);l.append("g").attr("class","y axis").attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":"").call(h?K:Aa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(ue);Eb&&l.append("g").attr("class","y2 axis").attr("transform", +M.y2).call(kb);a=l.append("g").attr("clip-path",Xa).attr("class","grid");jd&&a.append("g").attr("class","xgrids");fc&&(b=a.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(fc).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",h?"":"rotate(-90)").attr("dx",h?0:-q).attr("dy",-5).text(function(a){return a.text})); ve&&a.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",h?0:-10).attr("x2",h?r:-10).attr("y1",h?-10:q).attr("y2",h?-10:s);kd&&a.append("g").attr("class","ygrids");gc&&(a=a.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(gc).enter().append("g").attr("class","ygrid-line"),a.append("line").attr("class",function(a){return""+a["class"]}),a.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform", h?"rotate(-90)":"").attr("dx",h?0:-q).attr("dy",-5).text(function(a){return a.text}));l.append("g").attr("clip-path",Xa).attr("class","regions");l.append("g").attr("clip-path",Xa).attr("class","chart");l.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ua?h?"ns-resize":"ew-resize":null);l.select(".chart").append("g").attr("class","chart-bars");l.select(".chart").append("g").attr("class","chart-lines");l.select(".chart").append("g").attr("class","chart-arcs").attr("transform", -L.arc).append("text").attr("class","chart-arcs-title").style("text-anchor","middle").text(we);if(ua)l.insert("rect",xe?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",s).style("opacity",0).style("cursor",h?"ns-resize":"ew-resize").call(F).on("dblclick.zoom",null);null!==vb&&K.extent("function"!==typeof vb?vb:vb(pb()));Ea&&(G.append("g").attr("clip-path",Xa).attr("class","chart"),G.select(".chart").append("g").attr("class","chart-bars"),G.select(".chart").append("g").attr("class", -"chart-lines"),G.append("g").attr("clip-path",Xa).attr("class","x brush").call(K).selectAll("rect").attr(h?"width":"height",h?Fb:fb),G.append("g").attr("class","x axis").attr("transform",L.subx).attr("clip-path",h?"url("+document.URL+"#yaxis-clip)":"").call(hb));Ga&&wb(k.data.targets);ld(k.data.targets);x({withTransform:!0,withUpdateXDomain:!0});if(ye){if(D&&"string"===typeof Ha){Ha=ra(Ha);for(a=0;aUb(c,a)?n.select(".event-rect").style("cursor","pointer"):n.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;E(k.data.targets)||(a=e.mouse(this),c=Uc(k.data.targets,a),100>Ub(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){od(this,c,c.index)}))}).call(e.behavior.drag().origin(Object).on("drag",function(){pd(e.mouse(this))}).on("dragstart",function(){qd(e.mouse(this))}).on("dragend",function(){rd()})).call(F).on("dblclick.zoom", -null)}function od(a,b,c){var d=e.select(a),f=d.classed(oa),g=!1,h;"circle"===a.nodeName?(g=cd(a,1.5*Wa),h=fd):"rect"===a.nodeName&&(g=dd(a),h=hd);if(va||g)ma&&na(b)&&(d.classed(oa,!f),h(!f,d,b,c)),Ce(b,d)}function pd(a){var b,c,d,f,g,h,m;E(k.data.targets)||!ma||ua&&!F.altDomain||(b=kc[0],c=kc[1],d=a[0],a=a[1],f=Math.min(b,d),g=Math.max(b,d),h=va?q:Math.min(c,a),m=va?s:Math.max(c,a),l.select(".dragarea").attr("x",f).attr("y",h).attr("width",g-f).attr("height",m-h),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return na(a)}).each(function(a, -b){var c=e.select(this),d=c.classed(oa),k=c.classed(lc),l,n,p,q;l=!1;"circle"===this.nodeName?(l=1*c.attr("cx"),n=1*c.attr("cy"),q=fd,l=fUb(c,a)?n.select(".event-rect").style("cursor","pointer"):n.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;F(k.data.targets)||(a=e.mouse(this),c=Uc(k.data.targets,a),100>Ub(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){od(this,c,c.index)}))}).call(e.behavior.drag().origin(Object).on("drag",function(){pd(e.mouse(this))}).on("dragstart",function(){qd(e.mouse(this))}).on("dragend",function(){rd()})).call(G).on("dblclick.zoom", +null)}function od(a,b,c){var d=e.select(a),f=d.classed(oa),g=!1,h;"circle"===a.nodeName?(g=cd(a,1.5*Wa),h=fd):"rect"===a.nodeName&&(g=dd(a),h=hd);if(va||g)ma&&na(b)&&(d.classed(oa,!f),h(!f,d,b,c)),Ce(b,d)}function pd(a){var b,c,d,f,g,h,m;F(k.data.targets)||!ma||ua&&!G.altDomain||(b=kc[0],c=kc[1],d=a[0],a=a[1],f=Math.min(b,d),g=Math.max(b,d),h=va?q:Math.min(c,a),m=va?s:Math.max(c,a),l.select(".dragarea").attr("x",f).attr("y",h).attr("width",g-f).attr("height",m-h),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return na(a)}).each(function(a, +b){var c=e.select(this),d=c.classed(oa),k=c.classed(lc),l,n,p,q;l=!1;"circle"===this.nodeName?(l=1*c.attr("cx"),n=1*c.attr("cy"),q=fd,l=f"+d+""),h=a[e].name,g=b(a[e].value),d+=""+h+""+g+"");return d+""}),ye=g(["tooltip", -"init","show"],!1),Ha=g(["tooltip","init","x"],0),md=g(["tooltip","init","position"],{top:"0px",left:"50px"}),ec=ya.replace("#","")+"-clip",Xa="url("+document.URL+"#"+ec+")",D="timeseries"===vd,ka="categorized"===vd,Tb=!D&&(sa||ca),kc=null,Ya=!1,jc=!1,qa=Ga?40:0,O=function(a,b){var c=[],d=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===c.indexOf(b)&&c.push(b);return d[c.indexOf(b)%d.length]}}(Le, +""),Q=g(["regions"],[]),Wc=g(["tooltip","enabled"],!0),Xc=g(["tooltip","contents"],function(a){var b=dc?dc:function(a){return+a},c=tc(),d,e,g,h;for(e=0;e"+d+""),h=a[e].name,g=b(a[e].value),d+=""+h+""+g+"");return d+""}),ye=g(["tooltip", +"init","show"],!1),Ha=g(["tooltip","init","x"],0),md=g(["tooltip","init","position"],{top:"0px",left:"50px"}),ec=ya.replace("#","")+"-clip",Xa="url("+document.URL+"#"+ec+")",E="timeseries"===vd,ka="categorized"===vd,Tb=!E&&(sa||ca),kc=null,Ya=!1,jc=!1,qa=Ga?40:0,O=function(a,b){var c=[],d=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===c.indexOf(b)&&c.push(b);return d[c.indexOf(b)%d.length]}}(Le, Me),Ed=function(){var a=[[e.time.format("%Y/%-m/%-d"),function(){return!0}],[e.time.format("%-m/%-d"),function(a){return a.getMonth()}],[e.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[e.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[e.time.format("%I %p"),function(a){return a.getHours()}],[e.time.format("%I:%M"),function(a){return a.getMinutes()}],[e.time.format(":%S"),function(a){return a.getSeconds()}],[e.time.format(".%L"),function(a){return a.getMilliseconds()}]]; -return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),r,Fb,s,fb,Cb,xa,La,Gb,Hb,lb,wc,xc,Pb,Jb,Kb,Lb,Mb,Nb,Ob,m,z,ba,V,ib,jb,J,Aa,kb,hb,zd=h?"left":"bottom",Ad=h?cb?"top":"bottom":cb?"right":"left",Bd=h?eb?"bottom":"top":eb?"left":"right",Cd=h?"left":"bottom",L={main:function(){return"translate("+C+","+q+")"},context:function(){return"translate("+Ia+","+zb+")"},legend:function(){return"translate("+rc+","+qc+")"},y2:function(){return"translate("+(h?0:r)+","+(h?10:0)+")"}, +return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}(),r,Fb,s,fb,Cb,xa,La,Gb,Hb,lb,wc,xc,Pb,Jb,Kb,Lb,Mb,Nb,Ob,m,A,ba,V,ib,jb,K,Aa,kb,hb,zd=h?"left":"bottom",Ad=h?cb?"top":"bottom":cb?"right":"left",Bd=h?eb?"bottom":"top":eb?"left":"right",Cd=h?"left":"bottom",M={main:function(){return"translate("+D+","+q+")"},context:function(){return"translate("+Ia+","+zb+")"},legend:function(){return"translate("+rc+","+qc+")"},y2:function(){return"translate("+(h?0:r)+","+(h?10:0)+")"}, x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+(h?0:fb)+")"},arc:function(){return"translate("+r/2+","+s/2+")"}},vc=40,uc=20;Pb=e.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var Fe=function(){var a=e.svg.line().x(h?function(a){return u(a.id)(a.value)}:Ba).y(h?Ba:function(a){return u(a.id)(a.value)});return function(b){var c=Zb(b.values),d;if(Wb(b))return $c(b)?a.interpolate("cardinal"):a.interpolate("linear"),ud[b.id]?ne(c, m,u(b.id),ud[b.id]):a(c);d=m(c[0].x);b=u(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),Ge=function(){var a;a=h?e.svg.area().x0(function(a){return u(a.id)(0)}).x1(function(a){return u(a.id)(a.value)}).y(Ba):e.svg.area().x(Ba).y0(function(a){return u(a.id)(0)}).y1(function(a){return u(a.id)(a.value)});return function(b){var c=Zb(b.values),d;if(ja([b],"area")||ja([b],"area-spline"))return $c(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d=m(c[0].x);b=u(b.id)(c[0].value);return h? -"M "+b+" "+d:"M "+d+" "+b}}(),xb=function(a,b){var c=a.__max__+1,d=1 +"pie");T();ha();x({withTransform:!0})};k.toDonut=function(a){da(a,"donut");T();ha();x({withTransform:!0})};k.groups=function(a){if(y(a))return w;w=a;x();return w};k.regions=function(a){if(y(a))return Q;Q=a;x();return Q};k.regions.add=function(a){if(y(a))return Q;Q=Q.concat(a);x();return Q};k.regions.remove=function(a,b){var c=[].concat(a);b=v(b)?b:{};c.forEach(function(a){var c=z(b.duration)?b.duration:0;n.selectAll("."+a).transition().duration(c).style("fill-opacity",0).remove();Q=Q.filter(function(b){return 0> b.classes.indexOf(a)})});return Q};k.data.get=function(a){a=k.data.getAsTarget(a);return v(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=ob(function(b){return b.id===a});return 0