Browse Source

Fix NaN when undefined x for bar chart

pull/18/head
Masayuki Tanaka 11 years ago
parent
commit
0099bf287b
  1. 3
      c3.js
  2. 22
      c3.min.js

3
c3.js

@ -740,9 +740,10 @@
} }
function getBarX(barW, barTargetsNum, barIndices, isSub) { function getBarX(barW, barTargetsNum, barIndices, isSub) {
var scale = isSub ? subX : x; var scale = isSub ? subX : x;
if (! barTargetsNum) { return function () { return 0; }; }
return function (d) { return function (d) {
var barIndex = d.id in barIndices ? barIndices[d.id] : 0; var barIndex = d.id in barIndices ? barIndices[d.id] : 0;
return scale(d.x) - barW * (barTargetsNum / 2 - barIndex); return d.x || d.x === 0 ? scale(d.x) - barW * (barTargetsNum / 2 - barIndex) : 0;
}; };
} }
function getBarY(barH, barIndices, zeroBased, isSub) { function getBarY(barH, barIndices, zeroBased, isSub) {

22
c3.min.js vendored

@ -16,17 +16,17 @@ function vb(a){var b=ub(),d;for(d=0;d<b.length;d++)if(b[d]===a)return!0;return!1
b}function kd(a,b){return"region region-"+b+" "+("classes"in a?[].concat(a.classes).join(" "):"")}function fb(a){return m(a.x)}function Na(a){return m(C?qa(a.value):a.value)}function kc(a){return u(a.value)}function lc(a,b,d,f){d=d?d:0;f=f?f:a.length-1;var c=Math.floor((f-d)/2)+d;0<m(a[c].x)-b[0]?f=c:d=c;if(1===f-d){if(!a[d].x)return a[f];if(!a[f].x)return a[d];c=Math.pow(b[0]-m(a[d].x),2)+Math.pow(b[1]-u(a[d].value),2);b=Math.pow(b[0]-m(a[f].x),2)+Math.pow(b[1]-u(a[f].value),2);return c<b?a[d]:a[f]}return lc(a, b}function kd(a,b){return"region region-"+b+" "+("classes"in a?[].concat(a.classes).join(" "):"")}function fb(a){return m(a.x)}function Na(a){return m(C?qa(a.value):a.value)}function kc(a){return u(a.value)}function lc(a,b,d,f){d=d?d:0;f=f?f:a.length-1;var c=Math.floor((f-d)/2)+d;0<m(a[c].x)-b[0]?f=c:d=c;if(1===f-d){if(!a[d].x)return a[f];if(!a[f].x)return a[d];c=Math.pow(b[0]-m(a[d].x),2)+Math.pow(b[1]-u(a[d].value),2);b=Math.pow(b[0]-m(a[f].x),2)+Math.pow(b[1]-u(a[f].value),2);return c<b?a[d]:a[f]}return lc(a,
b,d,f)}function mc(a,b){var d,f;a.map(function(a){return lc(a.values,b)}).forEach(function(a){var c=Math.pow(m(a.x)-b[0],2)+Math.pow(u(a.value)-b[1],2);if(c<f||!f)f=c,d=a});return d}function nc(a,b){P.html(oc(a)).style("visibility","hidden").style("display","block");var d=P.property("offsetWidth"),f=P.property("offsetHeight");P.style("top",(b[1]+15+f<U()?b[1]+15:b[1]-f)+"px").style("left",g?b[0]:m(a[0].x)+60+d<(null===Xa?ca():Xa)?m(a[0].x)+60+"px":m(a[0].x)-d+30+"px").style("visibility","visible")} b,d,f)}function mc(a,b){var d,f;a.map(function(a){return lc(a.values,b)}).forEach(function(a){var c=Math.pow(m(a.x)-b[0],2)+Math.pow(u(a.value)-b[1],2);if(c<f||!f)f=c,d=a});return d}function nc(a,b){P.html(oc(a)).style("visibility","hidden").style("display","block");var d=P.property("offsetWidth"),f=P.property("offsetHeight");P.style("top",(b[1]+15+f<U()?b[1]+15:b[1]-f)+"px").style("left",g?b[0]:m(a[0].x)+60+d<(null===Xa?ca():Xa)?m(a[0].x)+60+"px":m(a[0].x)-d+30+"px").style("visibility","visible")}
function pc(a){bc(h.data.targets,"line")&&k.selectAll("line.xgrid-focus").style("visibility","visible").data([a]).attr(g?"y1":"x1",fb).attr(g?"y2":"x2",fb)}function qc(){k.select("line.xgrid-focus").style("visibility","hidden")}function ga(a){return a.x||0===a.x?m(a.x):null}function ha(a){return F(a.id)(a.value)}function ld(){var a={},b=0,d,f;cb(Ha).forEach(function(c){for(d=0;d<t.length;d++)if(!(0>t[d].indexOf(c.id)))for(f=0;f<t[d].length;f++)if(t[d][f]in a){a[c.id]=a[t[d][f]];break}s(a[c.id])&& function pc(a){bc(h.data.targets,"line")&&k.selectAll("line.xgrid-focus").style("visibility","visible").data([a]).attr(g?"y1":"x1",fb).attr(g?"y2":"x2",fb)}function qc(){k.select("line.xgrid-focus").style("visibility","hidden")}function ga(a){return a.x||0===a.x?m(a.x):null}function ha(a){return F(a.id)(a.value)}function ld(){var a={},b=0,d,f;cb(Ha).forEach(function(c){for(d=0;d<t.length;d++)if(!(0>t[d].indexOf(c.id)))for(f=0;f<t[d].length;f++)if(t[d][f]in a){a[c.id]=a[t[d][f]];break}s(a[c.id])&&
(a[c.id]=b++)});a.__max__=b-1;return a}function rc(a,b,d,f){var c=f?fa:m;return function(f){var e=f.id in d?d[f.id]:0;return c(f.x)-a*(b/2-e)}}function sc(a,b,d,f){var c=Object.keys(b);return function(e,g){var h=0,k=f?T(e.id):F(e.id);cb(Ha).forEach(function(d){d.id!==e.id&&b[d.id]===b[e.id]&&c.indexOf(d.id)<c.indexOf(e.id)&&(h+=a(d.values[g]))});return d?h:k(e.value)-h}}function tc(a,b){var d=null===a?function(a){return a}:function(b){return a>b?a-b:0};return function(a){var c=b?T(a.id):F(a.id);return d(c(a.value))}} (a[c.id]=b++)});a.__max__=b-1;return a}function rc(a,b,d,f){var c=f?fa:m;return b?function(f){var e=f.id in d?d[f.id]:0;return f.x||0===f.x?c(f.x)-a*(b/2-e):0}:function(){return 0}}function sc(a,b,d,f){var c=Object.keys(b);return function(e,g){var h=0,k=f?T(e.id):F(e.id);cb(Ha).forEach(function(d){d.id!==e.id&&b[d.id]===b[e.id]&&c.indexOf(d.id)<c.indexOf(e.id)&&(h+=a(d.values[g]))});return d?h:k(e.value)-h}}function tc(a,b){var d=null===a?function(a){return a}:function(b){return a>b?a-b:0};return function(a){var c=
function gb(a,b){var d=s(a)?ub():a;"string"===typeof d&&(d=[d]);for(var f=0;f<d.length;f++)Z[d[f]]=b}function bc(a,b){var d=!1;a.forEach(function(a){Z[a.id]===b&&(d=!0);a.id in Z||"line"!==b||(d=!0)});return d}function xb(a){a="string"===typeof a?a:a.id;return!(a in Z)||"line"===Z[a]||"spline"===Z[a]}function Ha(a){return"bar"===Z["string"===typeof a?a:a.id]}function uc(a){return Ha(a)?a.values:[]}function md(a){var b;(b=xb(a))||(b="scatter"===Z["string"===typeof a?a:a.id]);return b?a.values:[]}function qa(a){var b; b?T(a.id):F(a.id);return d(c(a.value))}}function gb(a,b){var d=s(a)?ub():a;"string"===typeof d&&(d=[d]);for(var f=0;f<d.length;f++)Z[d[f]]=b}function bc(a,b){var d=!1;a.forEach(function(a){Z[a.id]===b&&(d=!0);a.id in Z||"line"!==b||(d=!0)});return d}function xb(a){a="string"===typeof a?a:a.id;return!(a in Z)||"line"===Z[a]||"spline"===Z[a]}function Ha(a){return"bar"===Z["string"===typeof a?a:a.id]}function uc(a){return Ha(a)?a.values:[]}function md(a){var b;(b=xb(a))||(b="scatter"===Z["string"===
if(!a)throw Error(a+" can not be parsed as d3.time with format "+yb+". Maybe 'x' of this data is not defined. See data.x or data.xs option.");b=c.time.format(yb).parse(a);if(!b)throw Error("Failed to parse '"+a+"' with format "+yb);return b}function vc(a,b){var d=c.mouse(a),f=c.select(a),e=1*f.attr("cx"),f=1*f.attr("cy");return Math.sqrt(Math.pow(e-d[0],2)+Math.pow(f-d[1],2))<b}function wc(a){var b=c.mouse(a),d=c.select(a);a=1*d.attr("x");var f=1*d.attr("y"),d=1*d.attr("width");return a-10<b[0]&& typeof a?a:a.id]);return b?a.values:[]}function qa(a){var b;if(!a)throw Error(a+" can not be parsed as d3.time with format "+yb+". Maybe 'x' of this data is not defined. See data.x or data.xs option.");b=c.time.format(yb).parse(a);if(!b)throw Error("Failed to parse '"+a+"' with format "+yb);return b}function vc(a,b){var d=c.mouse(a),f=c.select(a),e=1*f.attr("cx"),f=1*f.attr("cy");return Math.sqrt(Math.pow(e-d[0],2)+Math.pow(f-d[1],2))<b}function wc(a){var b=c.mouse(a),d=c.select(a);a=1*d.attr("x");
b[0]<a+d+10&&f-10<b[1]}function nd(a,b){var d;for(d=0;d<b.length;d++)if(b[d].start<a&&a<=b[d].end)return!0;return!1}function fd(a,b){var d=!1;Object.keys(a).forEach(function(f){a[f]===b&&(d=!0)});return d}function xc(a,b){return Math.pow(m(a.x)-b[0],2)+Math.pow(u(a.value)-b[1],2)}function yc(a,b,d){od(a,b);k.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+d).data([b]).enter().append("circle").attr("class",function(){return"selected-circle selected-circle-"+d}).attr("cx",g?ha:ga).attr("cy", var f=1*d.attr("y"),d=1*d.attr("width");return a-10<b[0]&&b[0]<a+d+10&&f-10<b[1]}function nd(a,b){var d;for(d=0;d<b.length;d++)if(b[d].start<a&&a<=b[d].end)return!0;return!1}function fd(a,b){var d=!1;Object.keys(a).forEach(function(f){a[f]===b&&(d=!0)});return d}function xc(a,b){return Math.pow(m(a.x)-b[0],2)+Math.pow(u(a.value)-b[1],2)}function yc(a,b,d){od(a,b);k.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+d).data([b]).enter().append("circle").attr("class",function(){return"selected-circle selected-circle-"+
g?ga:ha).attr("stroke",function(){return $(b.id)}).attr("r",1.4*Oa).transition().duration(100).attr("r",Oa)}function zb(a,b,d){pd(a,b);k.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+d).transition().duration(100).attr("r",0).remove()}function zc(a,b,d,f){a?yc(b,d,f):zb(b,d,f)}function qd(){}function Ac(){}function Bc(a,b,d,f){}function Cc(a){return a.filter(function(a){return null!==a.value})}function Ab(a,b){return(b?k.selectAll(".-circles-"+b):k).selectAll(".-circle"+(a||0===a? d}).attr("cx",g?ha:ga).attr("cy",g?ga:ha).attr("stroke",function(){return $(b.id)}).attr("r",1.4*Oa).transition().duration(100).attr("r",Oa)}function zb(a,b,d){pd(a,b);k.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+d).transition().duration(100).attr("r",0).remove()}function zc(a,b,d,f){a?yc(b,d,f):zb(b,d,f)}function qd(){}function Ac(){}function Bc(a,b,d,f){}function Cc(a){return a.filter(function(a){return null!==a.value})}function Ab(a,b){return(b?k.selectAll(".-circles-"+b):
"-"+a:""))}function Bb(a){Ab(a).filter(function(){return c.select(this).classed(aa)}).classed(aa,!1).attr("r",Cb)}function Dc(a){return k.selectAll(".-bar"+(a||0===a?"-"+a:""))}function rd(a,b,d,f){var c,e,h="M",k,m,l,Ec,q,p=[];if(n(f))for(c=0;c<f.length;c++)p[c]={},s(f[c].start)?p[c].start=a[0].x:p[c].start=C?qa(f[c].start):f[c].start,s(f[c].end)?p[c].end=a[a.length-1].x:p[c].end=C?qa(f[c].end):f[c].end;Ec=g?function(a){return d(a.value)}:function(a){return b(a.x)};q=g?function(a){return b(a.x)}: k).selectAll(".-circle"+(a||0===a?"-"+a:""))}function Bb(a){Ab(a).filter(function(){return c.select(this).classed(aa)}).classed(aa,!1).attr("r",Cb)}function Dc(a){return k.selectAll(".-bar"+(a||0===a?"-"+a:""))}function rd(a,b,d,f){var c,e,h="M",k,m,l,Ec,q,p=[];if(n(f))for(c=0;c<f.length;c++)p[c]={},s(f[c].start)?p[c].start=a[0].x:p[c].start=C?qa(f[c].start):f[c].start,s(f[c].end)?p[c].end=a[a.length-1].x:p[c].end=C?qa(f[c].end):f[c].end;Ec=g?function(a){return d(a.value)}:function(a){return b(a.x)};
function(a){return d(a.value)};f=C?function(a,c,f,e){var g=a.x.getTime();a=c.x-a.x;c=new Date(g+a*(f+e));return"M"+b(new Date(g+a*f))+" "+d(m(f))+" "+b(c)+" "+d(m(f+e))}:function(a,c,f,e){return"M"+b(k(f))+" "+d(m(f))+" "+b(k(f+e))+" "+d(m(f+e))};for(c=0;c<a.length;c++)if(s(p)||!nd(a[c].x,p))h+=" "+Ec(a[c])+" "+q(a[c]);else{k=J(a[c-1].x,a[c].x);m=E(a[c-1].value,a[c].value);e=b(a[c].x)-b(a[c-1].x);l=d(a[c].value)-d(a[c-1].value);e=Math.sqrt(Math.pow(e,2)+Math.pow(l,2));l=2/e;var r=2*l;for(e=l;1>=e;e+= q=g?function(a){return b(a.x)}:function(a){return d(a.value)};f=C?function(a,c,f,e){var g=a.x.getTime();a=c.x-a.x;c=new Date(g+a*(f+e));return"M"+b(new Date(g+a*f))+" "+d(m(f))+" "+b(c)+" "+d(m(f+e))}:function(a,c,f,e){return"M"+b(k(f))+" "+d(m(f))+" "+b(k(f+e))+" "+d(m(f+e))};for(c=0;c<a.length;c++)if(s(p)||!nd(a[c].x,p))h+=" "+Ec(a[c])+" "+q(a[c]);else{k=J(a[c-1].x,a[c].x);m=E(a[c-1].value,a[c].value);e=b(a[c].x)-b(a[c-1].x);l=d(a[c].value)-d(a[c-1].value);e=Math.sqrt(Math.pow(e,2)+Math.pow(l,2));
r)h+=f(a[c-1],a[c],e,l)}return h}function Db(a){var b,d;hb=c.select(xa);if(hb.empty())Q.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{hb.html("");h.data.x={};h.data.targets=La(a);va();Mb();m.domain(c.extent(Va()));u.domain(la("y"));V.domain(la("y2"));fa.domain(m.domain());Za.domain(u.domain());$a.domain(V.domain());B.ticks(10>a.length?a.length:10);oa.ticks(sd).outerTickSize(0).tickFormat(td);ab.ticks(ud).outerTickSize(0).tickFormat(vd); l=2/e;var r=2*l;for(e=l;1>=e;e+=r)h+=f(a[c-1],a[c],e,l)}return h}function Db(a){var b,d;hb=c.select(xa);if(hb.empty())Q.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{hb.html("");h.data.x={};h.data.targets=La(a);va();Mb();m.domain(c.extent(Va()));u.domain(la("y"));V.domain(la("y2"));fa.domain(m.domain());Za.domain(u.domain());$a.domain(V.domain());B.ticks(10>a.length?a.length:10);oa.ticks(sd).outerTickSize(0).tickFormat(td);
W=m.domain();I.x(fa);sa&&D.x(m);Pa=c.select(xa).append("svg").attr("width",q+A+ea).attr("height",p+r+G).on("mouseenter",wd).on("mouseleave",xd);ib=Pa.append("defs");ib.append("clipPath").attr("id",Eb).append("rect").attr("y",r).attr("width",q).attr("height",p-r);ib.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-A).attr("y",-20).attr("width",S).attr("height",R);ib.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-A+1).attr("y",r-1).attr("width",ka).attr("height", ab.ticks(ud).outerTickSize(0).tickFormat(vd);W=m.domain();I.x(fa);sa&&D.x(m);Pa=c.select(xa).append("svg").attr("width",q+A+ea).attr("height",p+r+G).on("mouseenter",wd).on("mouseleave",xd);ib=Pa.append("defs");ib.append("clipPath").attr("id",Eb).append("rect").attr("y",r).attr("width",q).attr("height",p-r);ib.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-A).attr("y",-20).attr("width",S).attr("height",R);ib.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",
nb);k=Pa.append("g").attr("transform",L.main);w=za?Pa.append("g").attr("transform",L.context):null;Aa=Ba?Pa.append("g").attr("transform",L.legend):null;P=c.select(xa).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");k.append("g").attr("class","x axis").attr("clip-path",g?"":"url(#xaxis-clip)").attr("transform",L.x).call(g?oa:B).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(yd); -A+1).attr("y",r-1).attr("width",ka).attr("height",nb);k=Pa.append("g").attr("transform",L.main);w=za?Pa.append("g").attr("transform",L.context):null;Aa=Ba?Pa.append("g").attr("transform",L.legend):null;P=c.select(xa).style("position","relative").append("div").style("position","absolute").style("z-index","10").style("display","none");k.append("g").attr("class","x axis").attr("clip-path",g?"":"url(#xaxis-clip)").attr("transform",L.x).call(g?oa:B).append("text").attr("class","-axis-x-label").attr("x",
k.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?B:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(zd);Tb&&k.append("g").attr("class","y2 axis").attr("transform",L.y2).call(ab);b=k.append("g").attr("clip-path",Qa).attr("class","grid");Fc&&b.append("g").attr("class","xgrids");Fb&&(d=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Fb).enter().append("g").attr("class", q).attr("dy","-.5em").style("text-anchor","end").text(yd);k.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?B:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(zd);Tb&&k.append("g").attr("class","y2 axis").attr("transform",L.y2).call(ab);b=k.append("g").attr("clip-path",Qa).attr("class","grid");Fc&&b.append("g").attr("class","xgrids");Fb&&(d=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Fb).enter().append("g").attr("class",
"xgrid-line"),d.append("line").attr("class",function(a){return""+a["class"]}),d.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",g?"":"rotate(-90)").attr("dx",g?0:-r).attr("dy",-6).text(function(a){return a.text}));Ad&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?q:-10).attr("y1",g?-10:r).attr("y2",g?-10:p);Gc&&b.append("g").attr("class","ygrids");Gb&&b.append("g").attr("class", "xgrid-line"),d.append("line").attr("class",function(a){return""+a["class"]}),d.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",g?"":"rotate(-90)").attr("dx",g?0:-r).attr("dy",-6).text(function(a){return a.text}));Ad&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?q:-10).attr("y1",g?-10:r).attr("y2",g?-10:p);Gc&&b.append("g").attr("class","ygrids");Gb&&b.append("g").attr("class",
"ygrid-lines").selectAll("ygrid-line").data(Gb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Qa).attr("class","regions");k.append("g").attr("clip-path",Qa).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",sa?"ew-resize":null);Y?Bd(b):Cd(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");if(sa)k.insert("rect", "ygrid-lines").selectAll("ygrid-line").data(Gb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Qa).attr("class","regions");k.append("g").attr("clip-path",Qa).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",sa?"ew-resize":null);Y?Bd(b):Cd(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");if(sa)k.insert("rect",
Dd?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",p).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom",null);null!==jb&&I.extent("function"!==typeof jb?jb:jb(pa,ya));za&&(w.append("g").attr("clip-path",Qa).attr("class","chart"),w.select(".chart").append("g").attr("class","chart-bars"),w.select(".chart").append("g").attr("class","chart-lines"),w.append("g").attr("clip-path",Qa).attr("class","x brush").call(I).selectAll("rect").attr("height",na),w.append("g").attr("class", Dd?null:"g.grid").attr("class","zoom-rect").attr("width",q).attr("height",p).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom",null);null!==jb&&I.extent("function"!==typeof jb?jb:jb(pa,ya));za&&(w.append("g").attr("clip-path",Qa).attr("class","chart"),w.select(".chart").append("g").attr("class","chart-bars"),w.select(".chart").append("g").attr("class","chart-lines"),w.append("g").attr("clip-path",Qa).attr("class","x brush").call(I).selectAll("rect").attr("height",na),w.append("g").attr("class",

Loading…
Cancel
Save