diff --git a/c3.js b/c3.js index 23b1d6e..2efa25c 100644 --- a/c3.js +++ b/c3.js @@ -734,24 +734,26 @@ //-- Shape --// - function lineWithRegions (d, x, y, regions) { + function lineWithRegions (d, x, y, _regions) { var prev = -1, i, j; var s = "M", sWithRegion; var xp, yp, dx, dy, dd, diff, diff2; var xValue, yValue; + var regions = []; // Check start/end of regions - if (isDefined(regions)) { - for (i = 0; i < regions.length; i++){ - if (isUndefined(regions[i].start)) { + if (isDefined(_regions)) { + for (i = 0; i < _regions.length; i++){ + regions[i] = {}; + if (isUndefined(_regions[i].start)) { regions[i].start = d[0].x; } else if (isTimeSeries) { - regions[i].start = parseDate(regions[i].start); + regions[i].start = parseDate(_regions[i].start); } - if (isUndefined(regions[i].end)) { + if (isUndefined(_regions[i].end)) { regions[i].end = d[d.length-1].x; } else if (isTimeSeries) { - regions[i].end = parseDate(regions[i].end); + regions[i].end = parseDate(_regions[i].end); } } } diff --git a/c3.min.js b/c3.min.js index 0a15be6..685289c 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,59 +1,59 @@ -(function(jb){function kb(){function n(d,k){d.attr("transform",function(d){return"translate("+(k(d)+P)+",0)"})}function r(d,k){d.attr("transform",function(d){return"translate(0,"+k(d)+")"})}function Ba(d){var k=d[0];d=d[d.length-1];return kt[c].indexOf(f.id)))for(e=0;et[c].indexOf(f.id)))for(e=0;e=d;d+=diffx2)qa+=h(a[f-1],a[f],d, -p);return qa}function Za(a){var b=l.data.targets=I(a),c,e;p.domain(d3.extent(a.map(function(a){return a.x})));v.domain(Ca(b,"y"));N.domain(Ca(b,"y2"));w.domain(p.domain());Fa.domain(v.domain());Ga.domain(N.domain());C.ticks(10>a.length?a.length:10);c=h.append("g").attr("clip-path",Ma).attr("class","grid");Lb&&c.append("g").attr("class","xgrids");$a&&(e=c.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data($a).enter().append("g").attr("class","xgrid-line"),e.append("line").attr("class", -function(a){return""+a["class"]}),e.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",g?"":"rotate(-90)").attr("dx",g?0:-s).attr("dy",-6).text(function(a){return a.text}));oc&&c.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:s).attr("y2",g?-10:u);Mb&&c.append("g").attr("class","ygrids");ab&&c.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(ab).enter().append("line").attr("class", -function(a){return"ygrid-line "+a["class"]});h.append("g").attr("clip-path",Ma).attr("class","regions");h.append("g").attr("clip-path",Ma).attr("class","chart");h.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",function(a){return V&&$?"pointer":null}).on("mouseover",function(a,b){if(!Na){var c=l.data.targets.map(function(a){return Da(a.values[b])}), -e,d;if(0=d;d+=diffx2)qa+=e(a[f-1],a[f],d, +l);return qa}function Za(a){var b=k.data.targets=I(a),c,e;q.domain(d3.extent(a.map(function(a){return a.x})));v.domain(Ca(b,"y"));N.domain(Ca(b,"y2"));w.domain(q.domain());Fa.domain(v.domain());Ga.domain(N.domain());C.ticks(10>a.length?a.length:10);c=h.append("g").attr("clip-path",Ma).attr("class","grid");Lb&&c.append("g").attr("class","xgrids");$a&&(e=c.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data($a).enter().append("g").attr("class","xgrid-line"),e.append("line").attr("class", +function(a){return""+a["class"]}),e.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",g?"":"rotate(-90)").attr("dx",g?0:-s).attr("dy",-6).text(function(a){return a.text}));oc&&c.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?p:-10).attr("y1",g?-10:s).attr("y2",g?-10:u);Mb&&c.append("g").attr("class","ygrids");ab&&c.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(ab).enter().append("line").attr("class", +function(a){return"ygrid-line "+a["class"]});h.append("g").attr("clip-path",Ma).attr("class","regions");h.append("g").attr("clip-path",Ma).attr("class","chart");h.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",function(a){return V&&$?"pointer":null}).on("mouseover",function(a,b){if(!Na){var c=k.data.targets.map(function(a){return Da(a.values[b])}), +e,d;if(0",c,d,f;for(c=0;c",c,d,f;for(c=0;c"+f+""+d+"";return b+""}),rc=d(["tooltip","init","show"],!1),ha=d(["tooltip","init","x"],0),Rb=d(["tooltip","init","position"],{top:"0px",left:"50px"}),hb=x.bindto.replace("#","")+"-clip",Ma="url(#"+hb+")",E="timeseries"===Ub,Aa="categorized"===Ub,cb=null,Na=!1,Y=va?40:0,zc=function(a){return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}([[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()}]]),Z=d3.time.format(wc).parse,mb,rb,ob, -qb,sb,q,u,da,ub,vb,Ra,Sa,p,v,N,w,Fa,Ga,C=Aa?kb():d3.svg.axis(),oa=d3.svg.axis(),Ta=d3.svg.axis(),ea=Aa?kb():d3.svg.axis();M();P();E&&C.tickFormat(zc);Aa?(C.categories(Oa).tickCentered(Vb),ea.categories(Oa).tickCentered(Vb)):(C.tickOffset=function(){return 0},ea.tickOffset=function(){return 0});Aa&&function(){var a=p,b=w,c=Object.keys(p),d,f;p=function(b){return a(b)+C.tickOffset()};w=function(a){return b(a)+ea.tickOffset()};for(f=0;fa?0:a},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];0<=c.indexOf(b)||c.push(b);return d[c.indexOf(b)%d.length]}}(xc,yc),Pa=d3.select(x.bindto).append("svg").attr("width", -q+J+B).attr("height",u+s+R),ib=Pa.append("defs");ib.append("clipPath").attr("id",hb).append("rect").attr("y",s).attr("width",q).attr("height",u-s);ib.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",q+2).attr("height",40);ib.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",s-1).attr("width",40).attr("height",u-s+2);var h=Pa.append("g").attr("transform","translate("+J+","+s+")"),L=null;ua&&(L=Pa.append("g").attr("transform", -"translate("+F+","+ia+")"));var ya=null;va&&(ya=Pa.append("g").attr("transform","translate("+Ba+","+lb+")"));var ga=d3.select(x.bindto).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),fa=d3.svg.brush().x(w).on("brush",function(){G({withTransition:!1,withY:!1,withSubchart:!1})}),Ka=null,Ua=null;l.focus=function(a){l.defocus();d3.selectAll(za(a)).filter(function(a){return Qa(a.id)}).classed("focused",!0).transition().duration(100).style("opacity", -1)};l.defocus=function(a){d3.selectAll(za(a)).filter(function(a){return Qa(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};l.revert=function(a){d3.selectAll(za(a)).filter(function(a){return Qa(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};l.show=function(a){d3.selectAll(za(a)).transition().style("opacity",1)};l.hide=function(a){d3.selectAll(za(a)).transition().style("opacity",0)};l.load=function(a){r(a.done)&&(a.done=function(){});if("cacheIds"in -a&&ba(a.cacheIds))wa(ca(a.cacheIds),a.done);else if("data"in a)wa(I(data),a.done);else if("url"in a)d3.csv(a.url,function(b,c){wa(I(c),a.done)});else if("rows"in a)wa(I(ja(a.rows)),a.done);else if("columns"in a)wa(I(ka(a.columns)),a.done);else throw Error("url or rows or columns is required.");};l.unload=function(a){l.data.targets=l.data.targets.filter(function(b){return b.id!=a});d3.selectAll(".target-"+a).transition().style("opacity",0).remove();va&&(d3.selectAll(".legend-item-"+a).remove(),fb(l.data.targets)); -0b.classes.indexOf(a)})});return H};l.data.get=function(a){a=l.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};l.data.getAsTarget=function(a){var b=Ha(function(b){return b.id== -a});return 0a?0:a},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];0<=c.indexOf(b)||c.push(b);return d[c.indexOf(b)%d.length]}}(xc,yc),Pa=d3.select(x.bindto).append("svg").attr("width", +p+J+B).attr("height",u+s+R),ib=Pa.append("defs");ib.append("clipPath").attr("id",hb).append("rect").attr("y",s).attr("width",p).attr("height",u-s);ib.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",p+2).attr("height",40);ib.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",s-1).attr("width",40).attr("height",u-s+2);var h=Pa.append("g").attr("transform","translate("+J+","+s+")"),L=null;ua&&(L=Pa.append("g").attr("transform", +"translate("+F+","+ia+")"));var ya=null;va&&(ya=Pa.append("g").attr("transform","translate("+Ba+","+lb+")"));var ga=d3.select(x.bindto).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),fa=d3.svg.brush().x(w).on("brush",function(){G({withTransition:!1,withY:!1,withSubchart:!1})}),Ka=null,Ua=null;k.focus=function(a){k.defocus();d3.selectAll(za(a)).filter(function(a){return Qa(a.id)}).classed("focused",!0).transition().duration(100).style("opacity", +1)};k.defocus=function(a){d3.selectAll(za(a)).filter(function(a){return Qa(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};k.revert=function(a){d3.selectAll(za(a)).filter(function(a){return Qa(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};k.show=function(a){d3.selectAll(za(a)).transition().style("opacity",1)};k.hide=function(a){d3.selectAll(za(a)).transition().style("opacity",0)};k.load=function(a){r(a.done)&&(a.done=function(){});if("cacheIds"in +a&&ba(a.cacheIds))wa(ca(a.cacheIds),a.done);else if("data"in a)wa(I(data),a.done);else if("url"in a)d3.csv(a.url,function(b,c){wa(I(c),a.done)});else if("rows"in a)wa(I(ja(a.rows)),a.done);else if("columns"in a)wa(I(ka(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(b){return b.id!=a});d3.selectAll(".target-"+a).transition().style("opacity",0).remove();va&&(d3.selectAll(".legend-item-"+a).remove(),fb(k.data.targets)); +0b.classes.indexOf(a)})});return H};k.data.get=function(a){a=k.data.getAsTarget(a);return m(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Ha(function(b){return b.id== +a});return 0