diff --git a/c3.js b/c3.js index 85b6a0e..25de8fb 100644 --- a/c3.js +++ b/c3.js @@ -465,7 +465,7 @@ id: convertedId, id_org: id, values: data.map(function (d) { - return {x: d.x, value: +d[id], id: convertedId}; + return {x: d.x, value: d[id] !== null ? +d[id] : null, id: convertedId}; }) }; }); @@ -712,6 +712,10 @@ (selected) ? selectBar(target, d, i) : unselectBar(target, d, i); } + function filterRemoveNull(data) { + return data.filter(function (d) { return d.value !== null; }); + } + //-- Shape --// // For main region @@ -720,13 +724,13 @@ .x(__axis_rotated ? function (d) { return getYScale(d.id)(d.value); } : xx) .y(__axis_rotated ? xx : function (d) { return getYScale(d.id)(d.value); }); return function (d) { - var x0, y0; + var data = filterRemoveNull(d.values), x0, y0; if (isLineType(d)) { isSplineType(d) ? line.interpolate("cardinal") : line.interpolate("linear"); - return Object.keys(__data_regions).length > 0 ? lineWithRegions(d.values, x, getYScale(d.id), __data_regions[d.id]) : line(d.values); + return Object.keys(__data_regions).length > 0 ? lineWithRegions(data, x, getYScale(d.id), __data_regions[d.id]) : line(data); } else { - x0 = x(d.values[0].x); - y0 = getYScale(d.id)(d.values[0].value); + x0 = x(data[0].x); + y0 = getYScale(d.id)(data[0].value); return __axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } }; @@ -738,7 +742,8 @@ .x(function (d) { return subX(d.x); }) .y(function (d) { return getSubYScale(d.id)(d.value); }); return function (d) { - return isLineType(d) ? line(d.values) : "M " + subX(d.values[0].x) + " " + getSubYScale(d.id)(d.values[0].value); + var data = filterRemoveNull(d.values); + return isLineType(d) ? line(data) : "M " + subX(data[0].x) + " " + getSubYScale(d.id)(data[0].value); }; })(); @@ -1409,9 +1414,11 @@ mainCircle = main.selectAll('.-circles').selectAll('.-circle') .data(lineData); mainCircle.transition().duration(duration) + .style('opacity', function (d) { return d.value === null ? 0 : 1; }) .attr("cx", __axis_rotated ? circleY : circleX) .attr("cy", __axis_rotated ? circleX : circleY); mainCircle.enter().append("circle") + .style('opacity', function (d) { return d.value === null ? 0 : 1; }) .attr("class", classCircle) .attr("cx", __axis_rotated ? circleY : circleX) .attr("cy", __axis_rotated ? circleX : circleY) diff --git a/c3.min.js b/c3.min.js index a832f97..9e31a2a 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,65 +1,66 @@ -(function(qa){function oc(){function n(d,c){d.attr("transform",function(d){return"translate("+(c(d)+V)+", 0)"})}function t(d,c){d.attr("transform",function(d){return"translate(0,"+c(d)+")"})}function qa(d){var c=d[0];d=d[d.length-1];return ca?0:a}function ga(a){var b=Ia[a.id];a.name=n(b)?b:a.id;return a}function Ca(a){var b=a[0],e={},h=[],d,c;for(d=1;dx[e].indexOf(m.id)))for(d=0;d=g;g+=v)s+=d(a[c-1],a[c],g,u)}return s}function tb(a){var b=k.data.targets=ha(a),e,c;dc=d.select(ua);if(dc.empty())qa.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); -else{Q();V();l.domain(d.extent(a.map(function(a){return a.x})));A.domain(D(b,"y"));R.domain(D(b,"y2"));Y.domain(l.domain());Ua.domain(A.domain());Va.domain(R.domain());P.ticks(10>a.length?a.length:10);ka.ticks(Mc).outerTickSize(0).tickFormat(Nc);Wa.ticks(Oc).outerTickSize(0).tickFormat(Pc);S=l.domain();G.x(Y);na&&H.x(l);Ma=d.select(ua).append("svg").attr("width",r+J+E).attr("height",p+v+X).on("mouseenter",Qc).on("mouseleave",Rc);bb=Ma.append("defs");bb.append("clipPath").attr("id",ub).append("rect").attr("y", -v).attr("width",r).attr("height",p-v);bb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",r+2).attr("height",40);bb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-J+1).attr("y",v-1).attr("width",J).attr("height",p-v+2);g=Ma.append("g").attr("transform",K.main);z=wa?Ma.append("g").attr("transform",K.context):null;xa=ya?Ma.append("g").attr("transform",K.legend):null;ba=d.select(ua).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",f?"":"url(#xaxis-clip)").attr("transform",K.x).call(f?ka:P);g.append("g").attr("class","y axis").attr("clip-path",f?"url(#yaxis-clip)":"").call(f?P:ka).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Sc);Jb&&g.append("g").attr("class","y2 axis").attr("transform",K.y2).call(Wa);e=g.append("g").attr("clip-path", -Na).attr("class","grid");ec&&e.append("g").attr("class","xgrids");vb&&(c=e.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(vb).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:-v).attr("dy",-6).text(function(a){return a.text}));Tc&&e.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:v).attr("y2",f?-10:p);fc&&e.append("g").attr("class","ygrids");wb&&e.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(wb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Na).attr("class","regions");g.append("g").attr("clip-path",Na).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor", -na?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",ca&&oa?"pointer":null).on("mouseover",function(a,b){if(!cb){var e=k.data.targets.map(function(a){return ga(a.values[b])}),c,h;if(0",e,c,d;for(e=0;e"+d+""+c+""; -return b+""}),Wc=c(["tooltip","init","show"],!1),za=c(["tooltip","init","x"],0),kc=c(["tooltip","init","position"],{top:"0px",left:"50px"}),ub=ua.replace("#","")+"-clip",Na="url(#"+ub+")",F="timeseries"===nc,la="categorized"===nc,zb=null,cb=!1,yb=!1,ia=ya?40:0,ma=d.time.format(bd).parse,T=function(a,b){var e=[],c=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===e.indexOf(b)&&e.push(b);return c[e.indexOf(b)% -c.length]}}(cd,dd),tc=function(){var a=[[d.time.format("%Y/%-m/%-d"),function(){return!0}],[d.time.format("%-m/%-d"),function(a){return a.getMonth()}],[d.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[d.time.format("%-m/%-d"),function(a){return a.getDay()&&1!==a.getDate()}],[d.time.format("%I %p"),function(a){return a.getHours()}],[d.time.format("%I:%M"),function(a){return a.getMinutes()}],[d.time.format(":%S"),function(a){return a.getSeconds()}],[d.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)}}(),Gb,Lb,Ib,Ta,Kb,Mb,r,p,ja,gb,va,Nb,Ob,jb,kb,l,A,R,Y,Ua,Va,P,ka,Wa,Ea,pc=f?"left":"bottom",qc=f?ib?"top":"bottom":ib?"right":"left",rc=f?hb?"bottom":"top":hb?"left":"right",sc="bottom",K={main:function(){return"translate("+J+","+v+")"},context:function(){return"translate("+I+","+Aa+")"},legend:function(){return"translate("+Cb+","+Bb+")"},y2:function(){return"translate("+(f?0:r)+","+(f?10:0)+")"},x:function(){return"translate(0,"+ -p+")"},subx:function(){return"translate(0,"+ja+")"}},Yc=function(){var a=d.svg.line().x(f?function(a){return fa(a.id)(a.value)}:ab).y(f?ab:function(a){return fa(a.id)(a.value)});return function(b){var c;if(rb(b))return"spline"===aa["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return L};k.data.get=function(a){a=k.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Xa(function(b){return b.id===a});return 0a?0:a}function fa(a){var b=Ia[a.id];a.name=n(b)?b:a.id;return a}function Ca(a){var b=a[0],d={},h=[],e,c;for(e=1;ev[d].indexOf(e.id)))for(h=0;h=g;g+=t)r+=e(a[c-1],a[c],g,u)}return r}function tb(a){var b=k.data.targets= +ga(a),d,c;fc=e.select(ta);if(fc.empty())pa.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{P();U();m.domain(e.extent(a.map(function(a){return a.x})));z.domain(C(b,"y"));Q.domain(C(b,"y2"));X.domain(m.domain());Ua.domain(z.domain());Va.domain(Q.domain());O.ticks(10>a.length?a.length:10);ja.ticks(Oc).outerTickSize(0).tickFormat(Pc);Wa.ticks(Qc).outerTickSize(0).tickFormat(Rc);R=m.domain();F.x(X);ma&&G.x(m);Ma= +e.select(ta).append("svg").attr("width",q+I+D).attr("height",t+w+W).on("mouseenter",Sc).on("mouseleave",Tc);bb=Ma.append("defs");bb.append("clipPath").attr("id",ub).append("rect").attr("y",w).attr("width",q).attr("height",t-w);bb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",q+2).attr("height",40);bb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-I+1).attr("y",w-1).attr("width",I).attr("height",t-w+2);g=Ma.append("g").attr("transform", +J.main);y=wa?Ma.append("g").attr("transform",J.context):null;xa=ya?Ma.append("g").attr("transform",J.legend):null;aa=e.select(ta).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",f?"":"url(#xaxis-clip)").attr("transform",J.x).call(f?ja:O);g.append("g").attr("class","y axis").attr("clip-path",f?"url(#yaxis-clip)":"").call(f?O:ja).append("text").attr("transform", +"rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Uc);Jb&&g.append("g").attr("class","y2 axis").attr("transform",J.y2).call(Wa);d=g.append("g").attr("clip-path",Na).attr("class","grid");gc&&d.append("g").attr("class","xgrids");vb&&(c=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(vb).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:-w).attr("dy",-6).text(function(a){return a.text}));Vc&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",f?0:-10).attr("x2",f?q:-10).attr("y1",f?-10:w).attr("y2",f?-10:t);hc&&d.append("g").attr("class","ygrids");wb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(wb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]}); +g.append("g").attr("clip-path",Na).attr("class","regions");g.append("g").attr("clip-path",Na).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ma?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",ba&&na?"pointer":null).on("mouseover",function(a,b){if(!cb){var d=k.data.targets.map(function(a){return fa(a.values[b])}),c,h;if(0",d,c,e;for(d=0;d"+e+""+c+"";return b+""}),Yc=c(["tooltip","init","show"],!1),za=c(["tooltip","init","x"],0),mc=c(["tooltip","init","position"],{top:"0px",left:"50px"}),ub=ta.replace("#","")+"-clip",Na="url(#"+ +ub+")",E="timeseries"===pc,ka="categorized"===pc,zb=null,cb=!1,yb=!1,ha=ya?40:0,la=e.time.format(dd).parse,S=function(a,b){var d=[],c=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===d.indexOf(b)&&d.push(b);return c[d.indexOf(b)%c.length]}}(ed,fd),vc=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 d=a.length-1,c=a[d];!c[1](b);)c=a[--d];return c[0](b)}}(),Gb,Lb,Ib,Ta,Kb,Mb,q,t,ia,gb,ua,Nb,Ob,jb,kb,m,z,Q,X,Ua,Va,O,ja,Wa, +Ea,rc=f?"left":"bottom",sc=f?ib?"top":"bottom":ib?"right":"left",tc=f?hb?"bottom":"top":hb?"left":"right",uc="bottom",J={main:function(){return"translate("+I+","+w+")"},context:function(){return"translate("+H+","+Aa+")"},legend:function(){return"translate("+Cb+","+Bb+")"},y2:function(){return"translate("+(f?0:q)+","+(f?10:0)+")"},x:function(){return"translate(0,"+t+")"},subx:function(){return"translate(0,"+ia+")"}},$c=function(){var a=e.svg.line().x(f?function(a){return ea(a.id)(a.value)}:ab).y(f? +ab:function(a){return ea(a.id)(a.value)});return function(b){var d=dc(b.values),c;if(rb(b))return"spline"===$["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return K};k.data.get=function(a){a=k.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Xa(function(b){return b.id===a});return 0