diff --git a/c3.js b/c3.js index 85ced1d..85b6a0e 100644 --- a/c3.js +++ b/c3.js @@ -834,7 +834,7 @@ /*-- Draw Chart --*/ // for svg elements - var svg, defs, main, context, legend, tooltip; + var svg, defs, main, context, legend, tooltip, selectChart; // for brush area culculation var firstDate = null, lastDate = null, orgXDomain; @@ -844,6 +844,12 @@ var grid, xgridLine; var i; + selectChart = d3.select(__bindto); + if (selectChart.empty()) { + window.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); + return; + } + // TODO: set names if names not specified // Init sizes and scales diff --git a/c3.min.js b/c3.min.js index 6bf305e..a832f97 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,65 +1,65 @@ -(function(ya){function mc(){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 Ta(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 Ba(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;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());Va.domain(A.domain());Wa.domain(R.domain());P.ticks(10>a.length?a.length:10);ka.ticks(Lc).outerTickSize(0).tickFormat(Mc);Xa.ticks(Nc).outerTickSize(0).tickFormat(Oc);S=l.domain();G.x(Y);na&&H.x(l);Ma=d.select(Da).append("svg").attr("width",r+J+E).attr("height",p+v+X).on("mouseenter",Pc).on("mouseleave",Qc);cb=Ma.append("defs");cb.append("clipPath").attr("id",ub).append("rect").attr("y",v).attr("width",r).attr("height",p-v);cb.append("clipPath").attr("id", -"xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",r+2).attr("height",40);cb.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=ua?Ma.append("g").attr("transform",K.context):null;va=wa?Ma.append("g").attr("transform",K.legend):null;ba=d.select(Da).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(Rc);Ib&&g.append("g").attr("class","y2 axis").attr("transform",K.y2).call(Xa);e=g.append("g").attr("clip-path",Na).attr("class","grid");cc&&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}));Sc&&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);dc&&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(!db){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+""}),Vc=c(["tooltip","init","show"],!1),xa=c(["tooltip","init","x"],0),ic=c(["tooltip","init","position"],{top:"0px",left:"50px"}),ub=Da.replace("#","")+"-clip",Na="url(#"+ub+")",F="timeseries"===lc,la="categorized"===lc,zb=null,db=!1,yb=!1,ia=wa?40:0,ma=d.time.format(ad).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]}}(bd,cd),rc=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)}}(),Fb,Kb,Hb,Ua,Jb,Lb,r,p,ja,gb,ta,Mb,Nb,jb,kb,l,A,R,Y,Va,Wa,P,ka,Xa,Ea,nc=f?"left":"bottom",oc=f?ib?"top":"bottom":ib?"right":"left",pc=f?hb?"bottom":"top":hb?"left":"right",qc="bottom",K={main:function(){return"translate("+J+","+v+")"},context:function(){return"translate("+I+","+za+")"},legend:function(){return"translate("+Ta+","+Bb+")"},y2:function(){return"translate("+(f?0:r)+","+(f?10:0)+")"},x:function(){return"translate(0,"+ -p+")"},subx:function(){return"translate(0,"+ja+")"}},Xc=function(){var a=d.svg.line().x(f?function(a){return fa(a.id)(a.value)}:bb).y(f?bb: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"),0a?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=Ya(function(b){return b.id===a});return 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 0