From cd50426ab11edbf45e6b3868f1636b0d717b941a Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 13 Feb 2014 10:32:24 +0900 Subject: [PATCH 1/3] Fix unexpected selection when multiple charts exist --- c3.js | 46 +++++++-------- c3.min.js | 164 +++++++++++++++++++++++++++--------------------------- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/c3.js b/c3.js index 53a197e..c620ac7 100644 --- a/c3.js +++ b/c3.js @@ -419,8 +419,8 @@ return ratio.toFixed(1) + "%"; } function expandArc(targetId, withoutFadeOut) { - var target = d3.selectAll('.chart-arc.target' + (targetId ? '-' + targetId : '')), - noneTargets = d3.selectAll('.-arc').filter(function (data) { return data.data.id !== targetId; }); + var target = svg.selectAll('.chart-arc.target' + (targetId ? '-' + targetId : '')), + noneTargets = svg.selectAll('.-arc').filter(function (data) { return data.data.id !== targetId; }); target.selectAll('path') .transition().duration(50) .attr("d", svgArcExpanded) @@ -431,11 +431,11 @@ } } function unexpandArc(targetId) { - var target = d3.selectAll('.chart-arc.target' + (targetId ? '-' + targetId : '')); + var target = svg.selectAll('.chart-arc.target' + (targetId ? '-' + targetId : '')); target.selectAll('path') .transition().duration(50) .attr("d", svgArc); - d3.selectAll('.-arc') + svg.selectAll('.-arc') .style("opacity", 1); } @@ -1587,7 +1587,7 @@ .each(function () { var _this = d3.select(this).classed(EXPANDED, true); if (this.nodeName === 'circle') { _this.attr('r', __point_focus_expand_r); } - d3.select('.event-rect-' + i).style('cursor', null); + svg.select('.event-rect-' + i).style('cursor', null); }) .filter(function () { var _this = d3.select(this); @@ -1604,7 +1604,7 @@ _this.classed(EXPANDED, true); if (this.nodeName === 'circle') { _this.attr('r', __point_select_r); } } - d3.select('.event-rect-' + i).style('cursor', 'pointer'); + svg.select('.event-rect-' + i).style('cursor', 'pointer'); }); }) .on('click', function (d, i) { @@ -1661,9 +1661,9 @@ // Show cursor as pointer if point is close to mouse position if (dist(closest, mouse) < 100) { - d3.select('.event-rect').style('cursor', 'pointer'); + svg.select('.event-rect').style('cursor', 'pointer'); } else { - d3.select('.event-rect').style('cursor', null); + svg.select('.event-rect').style('cursor', null); } }) .on('click', function () { @@ -2092,10 +2092,10 @@ // Set x for zoom again because of scale update if (__zoom_enabled) { zoom.x(x); } // Update sizes - d3.select('svg').attr('width', currentWidth).attr('height', currentHeight); - d3.select('#' + clipId).select('rect').attr('width', width).attr('height', height); - d3.select('#xaxis-clip').select('rect').attr('width', getXAxisClipWidth); - d3.select('.zoom-rect').attr('width', width).attr('height', height); + svg.attr('width', currentWidth).attr('height', currentHeight); + svg.select('#' + clipId).select('rect').attr('width', width).attr('height', height); + svg.select('#xaxis-clip').select('rect').attr('width', getXAxisClipWidth); + svg.select('.zoom-rect').attr('width', width).attr('height', height); // Update main positions main.select('.x.axis').attr("transform", translate.x); main.select('.y2.axis').attr("transform", translate.y2); @@ -2239,7 +2239,7 @@ /*-- Show --*/ // Fade-in each chart - d3.selectAll('.target') + svg.selectAll('.target') .transition() .style("opacity", 1); } @@ -2269,12 +2269,12 @@ /*-- Draw Legend --*/ function focusLegend(id) { - d3.selectAll('.legend-item').filter(function (d) { return d !== id; }) + svg.selectAll('.legend-item').filter(function (d) { return d !== id; }) .transition().duration(100) .style('opacity', 0.3); } function revertLegend() { - d3.selectAll('.legend-item') + svg.selectAll('.legend-item') .transition().duration(100) .style('opacity', 1); } @@ -2355,7 +2355,7 @@ } c3.focus = function (target) { - var candidates = d3.selectAll(getTargetSelector(target)), + var candidates = svg.selectAll(getTargetSelector(target)), candidatesForNoneArc = candidates.filter(isNoneArc), candidatesForArc = candidates.filter(isArc); function focus(targets) { @@ -2370,7 +2370,7 @@ }; c3.defocus = function (target) { - var candidates = d3.selectAll(getTargetSelector(target)), + var candidates = svg.selectAll(getTargetSelector(target)), candidatesForNoneArc = candidates.filter(isNoneArc), candidatesForArc = candidates.filter(isArc); function defocus(targets) { @@ -2384,7 +2384,7 @@ }; c3.revert = function (target) { - var candidates = d3.selectAll(getTargetSelector(target)), + var candidates = svg.selectAll(getTargetSelector(target)), candidatesForNoneArc = candidates.filter(isNoneArc), candidatesForArc = candidates.filter(isArc); function revert(targets) { @@ -2398,13 +2398,13 @@ }; c3.show = function (target) { - d3.selectAll(getTargetSelector(target)) + svg.selectAll(getTargetSelector(target)) .transition() .style('opacity', 1); }; c3.hide = function (target) { - d3.selectAll(getTargetSelector(target)) + svg.selectAll(getTargetSelector(target)) .transition() .style('opacity', 0); }; @@ -2453,13 +2453,13 @@ c3.data.targets = c3.data.targets.filter(function (d) { return d.id !== target; }); - d3.selectAll('.target-' + target) + svg.selectAll('.target-' + target) .transition() .style('opacity', 0) .remove(); if (__legend_show) { - d3.selectAll('.legend-item-' + target).remove(); + svg.selectAll('.legend-item-' + target).remove(); updateLegend(c3.data.targets); } @@ -2547,7 +2547,7 @@ var regionClasses = [].concat(classes); options = isDefined(options) ? options : {}; regionClasses.forEach(function (cls) { - var regions = d3.selectAll('.' + cls); + var regions = svg.selectAll('.' + cls); if (isDefined(options.duration)) { regions = regions.transition().duration(options.duration).style('fill-opacity', 0); } diff --git a/c3.min.js b/c3.min.js index 4c6fc29..d680348 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,83 +1,83 @@ -(function(U){function id(){function p(d,e){d.attr("transform",function(d){return"translate("+(e(d)+da)+", 0)"})}function t(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function U(d){var e=d[0];d=d[d.length-1];return ea?0:a}function qc(a){return pa&&a===pa||aa&&Dd(aa,a)}function Ed(a){return!qc(a)}function nb(a){var b= -Na[a.id];a.name=p(b)?b:a.id;return a}function rc(a){var b=a[0],c={},k=[],f,d;for(f=1;fx[c].indexOf(f.id)))for(d=0;db?a-b:0};return function(a){var d=b?X(a.id):u(a.id);return c(d(a.value))}}function Sa(a,b){var c=t(a)?ob():a;"string"===typeof c&&(c=[c]);for(var d=0;d=e;e+=s)g+=d(a[f-1],a[f],e,n)}return g}function Mb(a){var b,c;pb=d.select(va);if(pb.empty())U.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{pb.html(""); -g.data.x={};g.data.targets=Oa(a);ta();Xb();m.domain(d.extent(lb(g.data.targets)));y.domain(jb("y"));Z.domain(jb("y2"));R.domain(m.domain());eb.domain(y.domain());fb.domain(Z.domain());G.ticks(10>a.length?a.length:10);na.ticks(Sd).outerTickSize(0).tickFormat(Td);gb.ticks(Ud).outerTickSize(0).tickFormat(Vd);S=m.domain();H.x(R);qa&&D.x(m);Ua=d.select(va).append("svg").attr("width",r+F+ea).attr("height",q+s+K).on("mouseenter",Wd).on("mouseleave",Xd);qb=Ua.append("defs");qb.append("clipPath").attr("id", -Nb).append("rect").attr("y",s).attr("width",r).attr("height",q-s);qb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-F).attr("y",-20).attr("width",W).attr("height",V);qb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-F+1).attr("y",s-1).attr("width",ka).attr("height",tb);l=Ua.append("g").attr("transform",I.main);z=ya?Ua.append("g").attr("transform",I.context):null;za=Aa?Ua.append("g").attr("transform",I.legend):null;T=d.select(va).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(#xaxis-clip)").attr("transform",I.x).call(h?na:G).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(Yd);l.append("g").attr("class","y axis").attr("clip-path",h?"url(#yaxis-clip)":"").call(h?G:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Zd);dc&& -l.append("g").attr("class","y2 axis").attr("transform",I.y2).call(gb);b=l.append("g").attr("clip-path",Va).attr("class","grid");Vc&&b.append("g").attr("class","xgrids");Ob&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Ob).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",h?"":"rotate(-90)").attr("dx",h? -0:-s).attr("dy",-6).text(function(a){return a.text}));$d&&b.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:s).attr("y2",h?-10:q);Wc&&b.append("g").attr("class","ygrids");Pb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Pb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});l.append("g").attr("clip-path",Va).attr("class","regions");l.append("g").attr("clip-path", -Va).attr("class","chart");b=l.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",qa?"ew-resize":null);aa?ae(b):be(b,a);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",I.arc);if(qa)l.insert("rect",ce?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",q).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom", -null);null!==rb&&H.extent("function"!==typeof rb?rb:rb(lb()));ya&&(z.append("g").attr("clip-path",Va).attr("class","chart"),z.select(".chart").append("g").attr("class","chart-bars"),z.select(".chart").append("g").attr("class","chart-lines"),z.append("g").attr("clip-path",Va).attr("class","x brush").call(H).selectAll("rect").attr("height",ma),z.append("g").attr("class","x axis").attr("transform",I.subx).call(Ha));Aa&&sb(g.data.targets);Xc(g.data.targets);E({withTransition:!1,withUpdateXDomain:!0}); -if(de){if(A&&"string"===typeof Ba){Ba=oa(Ba);for(a=0;aEb(c,a)?d.select(".event-rect").style("cursor","pointer"):d.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;B(g.data.targets)||(a=d.mouse(this),c=Cc(g.data.targets,a),100>Eb(c,a)&&l.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Zc(this, -c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){$c(d.mouse(this))}).on("dragstart",function(){ad(d.mouse(this))}).on("dragend",function(){bd()})).call(D).on("dblclick.zoom",null)}function Zc(a,b,c){var e=d.select(a),f=e.classed(ja),g=!1,h;"circle"===a.nodeName?(g=Nc(a,1.5*Ta),h=Qc):"rect"===a.nodeName&&(g=Oc(a),h=Sc);if(ra||g)ha&&ia(b)&&(e.classed(ja,!f),h(!f,e,b,c)),fe(b,e)}function $c(a){var b,c,e,f,h,m,n;B(g.data.targets)||!ha||qa&&!D.altDomain||(b=Tb[0],c=Tb[1],e=a[0], -a=a[1],f=Math.min(b,e),h=Math.max(b,e),m=ra?s:Math.min(c,a),n=ra?q:Math.max(c,a),l.select(".dragarea").attr("x",f).attr("y",m).attr("width",h-f).attr("height",n-m),l.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ia(a)}).each(function(a,b){var c=d.select(this),e=c.classed(ja),k=c.classed(Ub),g,l,p,q;g=!1;"circle"===this.nodeName?(g=1*c.attr("cx"),l=1*c.attr("cy"),q=Qc,g=f",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),de=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Yc=e(["tooltip","init", -"position"],{top:"0px",left:"50px"}),Nb=va.replace("#","")+"-clip",Va="url(#"+Nb+")",A="timeseries"===hd,$="categorized"===hd,Db=!A&&(pa||aa),Tb=null,Wa=!1,Sb=!1,la=Aa?40:0,N=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]}}(me,ne),qd=function(){var a=[[d.time.format("%Y/%-m/%-d"),function(){return!0}],[d.time.format("%-m/%-d"), +(function(V){function id(){function p(d,e){d.attr("transform",function(d){return"translate("+(e(d)+ea)+", 0)"})}function u(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function V(d){var e=d[0];d=d[d.length-1];return ea?0:a}function qc(a){return qa&&a===qa||ba&&Dd(ba,a)}function Ed(a){return!qc(a)}function nb(a){var b= +Oa[a.id];a.name=p(b)?b:a.id;return a}function rc(a){var b=a[0],c={},f=[],m,d;for(m=1;my[c].indexOf(m.id)))for(f=0;fb?a-b:0};return function(a){var d=b?Y(a.id):x(a.id);return c(d(a.value))}}function Ta(a,b){var c=u(a)?ob():a;"string"===typeof c&&(c=[c]);for(var f=0;f=e;e+=s)h+=f(a[d-1],a[d],e,n)}return h}function Mb(a){var b,c;pb=d.select(wa);if(pb.empty())V.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{pb.html(""); +h.data.x={};h.data.targets=Pa(a);ua();Xb();l.domain(d.extent(lb(h.data.targets)));z.domain(jb("y"));$.domain(jb("y2"));S.domain(l.domain());eb.domain(z.domain());fb.domain($.domain());H.ticks(10>a.length?a.length:10);oa.ticks(Sd).outerTickSize(0).tickFormat(Td);gb.ticks(Ud).outerTickSize(0).tickFormat(Vd);T=l.domain();I.x(S);ra&&E.x(l);q=d.select(wa).append("svg").attr("width",r+G+fa).attr("height",s+t+L).on("mouseenter",Wd).on("mouseleave",Xd);qb=q.append("defs");qb.append("clipPath").attr("id", +Nb).append("rect").attr("y",t).attr("width",r).attr("height",s-t);qb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-G).attr("y",-20).attr("width",X).attr("height",W);qb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-G+1).attr("y",t-1).attr("width",la).attr("height",tb);k=q.append("g").attr("transform",J.main);A=za?q.append("g").attr("transform",J.context):null;Aa=Ba?q.append("g").attr("transform",J.legend):null;U=d.select(wa).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",J.x).call(g?oa:H).append("text").attr("class","-axis-x-label").attr("x",r).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?H:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Zd);dc&& +k.append("g").attr("class","y2 axis").attr("transform",J.y2).call(gb);b=k.append("g").attr("clip-path",Va).attr("class","grid");Vc&&b.append("g").attr("class","xgrids");Ob&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Ob).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",g?"":"rotate(-90)").attr("dx",g? +0:-t).attr("dy",-6).text(function(a){return a.text}));$d&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?r:-10).attr("y1",g?-10:t).attr("y2",g?-10:s);Wc&&b.append("g").attr("class","ygrids");Pb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Pb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Va).attr("class","regions");k.append("g").attr("clip-path", +Va).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ra?"ew-resize":null);ba?ae(b):be(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");k.select(".chart").append("g").attr("class","chart-arcs").attr("transform",J.arc);if(ra)k.insert("rect",ce?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(E).on("dblclick.zoom", +null);null!==rb&&I.extent("function"!==typeof rb?rb:rb(lb()));za&&(A.append("g").attr("clip-path",Va).attr("class","chart"),A.select(".chart").append("g").attr("class","chart-bars"),A.select(".chart").append("g").attr("class","chart-lines"),A.append("g").attr("clip-path",Va).attr("class","x brush").call(I).selectAll("rect").attr("height",na),A.append("g").attr("class","x axis").attr("transform",J.subx).call(Ia));Ba&&sb(h.data.targets);Xc(h.data.targets);F({withTransition:!1,withUpdateXDomain:!0}); +if(de){if(B&&"string"===typeof Ca){Ca=pa(Ca);for(a=0;aEb(c,a)?q.select(".event-rect").style("cursor","pointer"):q.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;C(h.data.targets)||(a=d.mouse(this),c=Cc(h.data.targets,a),100>Eb(c,a)&&k.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Zc(this, +c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){$c(d.mouse(this))}).on("dragstart",function(){ad(d.mouse(this))}).on("dragend",function(){bd()})).call(E).on("dblclick.zoom",null)}function Zc(a,b,c){var f=d.select(a),e=f.classed(ka),h=!1,g;"circle"===a.nodeName?(h=Nc(a,1.5*Ua),g=Qc):"rect"===a.nodeName&&(h=Oc(a),g=Sc);if(sa||h)ia&&ja(b)&&(f.classed(ka,!e),g(!e,f,b,c)),fe(b,f)}function $c(a){var b,c,f,e,g,l,n;C(h.data.targets)||!ia||ra&&!E.altDomain||(b=Tb[0],c=Tb[1],f=a[0], +a=a[1],e=Math.min(b,f),g=Math.max(b,f),l=sa?t:Math.min(c,a),n=sa?s:Math.max(c,a),k.select(".dragarea").attr("x",e).attr("y",l).attr("width",g-e).attr("height",n-l),k.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ja(a)}).each(function(a,b){var c=d.select(this),f=c.classed(ka),h=c.classed(Ub),k,p,r,q;k=!1;"circle"===this.nodeName?(k=1*c.attr("cx"),p=1*c.attr("cy"),q=Qc,k=e",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),de=e(["tooltip","init","show"],!1),Ca=e(["tooltip","init","x"],0),Yc=e(["tooltip","init", +"position"],{top:"0px",left:"50px"}),Nb=wa.replace("#","")+"-clip",Va="url(#"+Nb+")",B="timeseries"===hd,aa="categorized"===hd,Db=!B&&(qa||ba),Tb=null,Wa=!1,Sb=!1,ma=Ba?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]}}(me,ne),qd=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)}}(),$b,gc, -bc,cb,fc,hc,r,q,ma,ub,ua,db,xb,hb,lc,mc,Ab,jc,kc,yb,zb,m,y,Z,R,eb,fb,G,na,gb,Ha,ld=h?"left":"bottom",md=h?wb?"top":"bottom":wb?"right":"left",nd=h?vb?"bottom":"top":vb?"left":"right",od="bottom",I={main:function(){return"translate("+F+","+s+")"},context:function(){return"translate("+n+","+Ca+")"},legend:function(){return"translate("+Zb+","+Yb+")"},y2:function(){return"translate("+(h?0:r)+","+(h?10:0)+")"},x:function(){return"translate(0,"+q+")"},subx:function(){return"translate(0,"+ma+")"},arc:function(){return"translate("+ -r/2+","+q/2+")"}};Ab=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var he=function(){var a=d.svg.line().x(h?function(a){return u(a.id)(a.value)}:xa).y(h?xa:function(a){return u(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Fb(b))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),gd[b.id]?Rd(c,m,u(b.id),gd[b.id]):a(c);d=m(c[0].x);b=u(b.id)(c[0].value);return h?"M "+b+" "+d:"M "+d+" "+b}}(),ie=function(){var a;a=h?d.svg.area().x0(function(a){return u(a.id)(0)}).x1(function(a){return u(a.id)(a.value)}).y(xa): -d.svg.area().x(xa).y0(function(a){return u(a.id)(0)}).y1(function(a){return u(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Ma([b],"area")||Ma([b],"area-spline"))return Kc(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}}(),je=function(){var a=d.svg.line().x(function(a){return R(a.x)}).y(function(a){return X(a.id)(a.value)});return function(b){var c=Ib(b.values);return Fb(b)?a(c):"M "+R(c[0].x)+" "+X(b.id)(c[0].value)}}(), -H=d.svg.brush().on("brush",function(){E({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),D=d.behavior.zoom().on("zoomstart",function(){D.altDomain=d.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",qa?ke:null);H.update=function(){z&&z.select(".x.brush").call(this);return this};D.orgScaleExtent=function(){var a=fd?fd:[1,10];return[a[0],Math.max(Pa()/a[1],a[1])]};D.updateScaleExtent=function(){var a=m.orgDomain(),a=(a[1]-a[0])/(S[1]-S[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]* -a,b[1]*a]);return this};var Ua,qb,l,z,za,T,pb,S;g.focus=function(a){var b=d.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);g.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(g.data.targets)&&Fa(a,!0)};g.defocus=function(a){var b=d.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);B(g.data.targets)&&Ga(a)}; -g.revert=function(a){var b=d.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(g.data.targets)&&Ga(a)};g.show=function(a){d.selectAll(Za(a)).transition().style("opacity",1)};g.hide=function(a){d.selectAll(Za(a)).transition().style("opacity",0)};g.unzoom=function(){H.clear().update();E({withUpdateXDomain:!0})};g.load=function(a){t(a.done)&&(a.done=function(){});"categories"in a&&$&& -(Ia=a.categories,G.categories(Ia));if("cacheIds"in a&&Bd(a.cacheIds))Xa(Cd(a.cacheIds),a.done);else if("data"in a)Xa(Oa(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Xa(Oa(c),a.done)});else if("rows"in a)Xa(Oa(rc(a.rows)),a.done);else if("columns"in a)Xa(Oa(sc(a.columns)),a.done);else throw Error("url or rows or columns is required.");};g.unload=function(a){g.data.targets=g.data.targets.filter(function(b){return b.id!==a});d.selectAll(".target-"+a).transition().style("opacity",0).remove(); -Aa&&(d.selectAll(".legend-item-"+a).remove(),sb(g.data.targets));0b.classes.indexOf(a)})});return O}; -g.data.get=function(a){a=g.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};g.data.getAsTarget=function(a){var b=kb(function(b){return b.id===a});return 0b.classes.indexOf(a)})});return P}; +h.data.get=function(a){a=h.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=kb(function(b){return b.id===a});return 0 Date: Thu, 13 Feb 2014 10:42:28 +0900 Subject: [PATCH 2/3] Fix resize when multiple charts exist - #17 --- c3.js | 17 +++++++- c3.min.js | 128 +++++++++++++++++++++++++++--------------------------- 2 files changed, 80 insertions(+), 65 deletions(-) diff --git a/c3.js b/c3.js index c620ac7..67a691d 100644 --- a/c3.js +++ b/c3.js @@ -1519,7 +1519,10 @@ // Bind resize event if (window.onresize == null) { - window.onresize = resize; + window.onresize = generateResize(); + } + if (window.onresize.add) { + window.onresize.add(resize); } } @@ -2083,6 +2086,18 @@ } } + function generateResize() { + var resizeFunctions = []; + function callResizeFunctions() { + resizeFunctions.forEach(function (f) { + f(); + }); + } + callResizeFunctions.add = function (f) { + resizeFunctions.push(f); + }; + return callResizeFunctions; + } function resize() { // Update sizes and scales updateSizes(); diff --git a/c3.min.js b/c3.min.js index d680348..06d8013 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,83 +1,83 @@ -(function(V){function id(){function p(d,e){d.attr("transform",function(d){return"translate("+(e(d)+ea)+", 0)"})}function u(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function V(d){var e=d[0];d=d[d.length-1];return ea?0:a}function qc(a){return qa&&a===qa||ba&&Dd(ba,a)}function Ed(a){return!qc(a)}function nb(a){var b= -Oa[a.id];a.name=p(b)?b:a.id;return a}function rc(a){var b=a[0],c={},f=[],m,d;for(m=1;my[c].indexOf(m.id)))for(f=0;fb?a-b:0};return function(a){var d=b?Y(a.id):x(a.id);return c(d(a.value))}}function Ta(a,b){var c=u(a)?ob():a;"string"===typeof c&&(c=[c]);for(var f=0;f=e;e+=s)h+=f(a[d-1],a[d],e,n)}return h}function Mb(a){var b,c;pb=d.select(wa);if(pb.empty())V.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{pb.html(""); -h.data.x={};h.data.targets=Pa(a);ua();Xb();l.domain(d.extent(lb(h.data.targets)));z.domain(jb("y"));$.domain(jb("y2"));S.domain(l.domain());eb.domain(z.domain());fb.domain($.domain());H.ticks(10>a.length?a.length:10);oa.ticks(Sd).outerTickSize(0).tickFormat(Td);gb.ticks(Ud).outerTickSize(0).tickFormat(Vd);T=l.domain();I.x(S);ra&&E.x(l);q=d.select(wa).append("svg").attr("width",r+G+fa).attr("height",s+t+L).on("mouseenter",Wd).on("mouseleave",Xd);qb=q.append("defs");qb.append("clipPath").attr("id", -Nb).append("rect").attr("y",t).attr("width",r).attr("height",s-t);qb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-G).attr("y",-20).attr("width",X).attr("height",W);qb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-G+1).attr("y",t-1).attr("width",la).attr("height",tb);k=q.append("g").attr("transform",J.main);A=za?q.append("g").attr("transform",J.context):null;Aa=Ba?q.append("g").attr("transform",J.legend):null;U=d.select(wa).style("position","relative").append("div").style("position", +e))};for(d=0;d=e;e+=s)h+=f(a[d-1],a[d],e,n)}return h}function Mb(a){var b,c;pb=d.select(wa);if(pb.empty())M.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{pb.html(""); +h.data.x={};h.data.targets=Pa(a);ua();Xb();l.domain(d.extent(lb(h.data.targets)));z.domain(jb("y"));$.domain(jb("y2"));T.domain(l.domain());eb.domain(z.domain());fb.domain($.domain());H.ticks(10>a.length?a.length:10);oa.ticks(Sd).outerTickSize(0).tickFormat(Td);gb.ticks(Ud).outerTickSize(0).tickFormat(Vd);U=l.domain();I.x(T);ra&&E.x(l);q=d.select(wa).append("svg").attr("width",r+G+fa).attr("height",s+t+L).on("mouseenter",Wd).on("mouseleave",Xd);qb=q.append("defs");qb.append("clipPath").attr("id", +Nb).append("rect").attr("y",t).attr("width",r).attr("height",s-t);qb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-G).attr("y",-20).attr("width",X).attr("height",W);qb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-G+1).attr("y",t-1).attr("width",la).attr("height",tb);k=q.append("g").attr("transform",J.main);A=za?q.append("g").attr("transform",J.context):null;Aa=Ba?q.append("g").attr("transform",J.legend):null;V=d.select(wa).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",J.x).call(g?oa:H).append("text").attr("class","-axis-x-label").attr("x",r).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?H:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Zd);dc&& k.append("g").attr("class","y2 axis").attr("transform",J.y2).call(gb);b=k.append("g").attr("clip-path",Va).attr("class","grid");Vc&&b.append("g").attr("class","xgrids");Ob&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Ob).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",g?"":"rotate(-90)").attr("dx",g? 0:-t).attr("dy",-6).text(function(a){return a.text}));$d&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?r:-10).attr("y1",g?-10:t).attr("y2",g?-10:s);Wc&&b.append("g").attr("class","ygrids");Pb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Pb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Va).attr("class","regions");k.append("g").attr("clip-path", Va).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ra?"ew-resize":null);ba?ae(b):be(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");k.select(".chart").append("g").attr("class","chart-arcs").attr("transform",J.arc);if(ra)k.insert("rect",ce?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(E).on("dblclick.zoom", null);null!==rb&&I.extent("function"!==typeof rb?rb:rb(lb()));za&&(A.append("g").attr("clip-path",Va).attr("class","chart"),A.select(".chart").append("g").attr("class","chart-bars"),A.select(".chart").append("g").attr("class","chart-lines"),A.append("g").attr("clip-path",Va).attr("class","x brush").call(I).selectAll("rect").attr("height",na),A.append("g").attr("class","x axis").attr("transform",J.subx).call(Ia));Ba&&sb(h.data.targets);Xc(h.data.targets);F({withTransition:!1,withUpdateXDomain:!0}); -if(de){if(B&&"string"===typeof Ca){Ca=pa(Ca);for(a=0;aEb(c,a)?q.select(".event-rect").style("cursor","pointer"):q.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;C(h.data.targets)||(a=d.mouse(this),c=Cc(h.data.targets,a),100>Eb(c,a)&&k.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Zc(this, -c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){$c(d.mouse(this))}).on("dragstart",function(){ad(d.mouse(this))}).on("dragend",function(){bd()})).call(E).on("dblclick.zoom",null)}function Zc(a,b,c){var f=d.select(a),e=f.classed(ka),h=!1,g;"circle"===a.nodeName?(h=Nc(a,1.5*Ua),g=Qc):"rect"===a.nodeName&&(h=Oc(a),g=Sc);if(sa||h)ia&&ja(b)&&(f.classed(ka,!e),g(!e,f,b,c)),fe(b,f)}function $c(a){var b,c,f,e,g,l,n;C(h.data.targets)||!ia||ra&&!E.altDomain||(b=Tb[0],c=Tb[1],f=a[0], -a=a[1],e=Math.min(b,f),g=Math.max(b,f),l=sa?t:Math.min(c,a),n=sa?s:Math.max(c,a),k.select(".dragarea").attr("x",e).attr("y",l).attr("width",g-e).attr("height",n-l),k.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ja(a)}).each(function(a,b){var c=d.select(this),f=c.classed(ka),h=c.classed(Ub),k,p,r,q;k=!1;"circle"===this.nodeName?(k=1*c.attr("cx"),p=1*c.attr("cy"),q=Qc,k=e",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),de=e(["tooltip","init","show"],!1),Ca=e(["tooltip","init","x"],0),Yc=e(["tooltip","init", -"position"],{top:"0px",left:"50px"}),Nb=wa.replace("#","")+"-clip",Va="url(#"+Nb+")",B="timeseries"===hd,aa="categorized"===hd,Db=!B&&(qa||ba),Tb=null,Wa=!1,Sb=!1,ma=Ba?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]}}(me,ne),qd=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)}}(),$b,gc, -bc,cb,fc,hc,r,s,na,ub,va,db,xb,hb,lc,mc,Ab,jc,kc,yb,zb,l,z,$,S,eb,fb,H,oa,gb,Ia,ld=g?"left":"bottom",md=g?wb?"top":"bottom":wb?"right":"left",nd=g?vb?"bottom":"top":vb?"left":"right",od="bottom",J={main:function(){return"translate("+G+","+t+")"},context:function(){return"translate("+n+","+Da+")"},legend:function(){return"translate("+Zb+","+Yb+")"},y2:function(){return"translate("+(g?0:r)+","+(g?10:0)+")"},x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+na+")"},arc:function(){return"translate("+ -r/2+","+s/2+")"}};Ab=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var he=function(){var a=d.svg.line().x(g?function(a){return x(a.id)(a.value)}:ya).y(g?ya:function(a){return x(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Fb(b))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),gd[b.id]?Rd(c,l,x(b.id),gd[b.id]):a(c);d=l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),ie=function(){var a;a=g?d.svg.area().x0(function(a){return x(a.id)(0)}).x1(function(a){return x(a.id)(a.value)}).y(ya): -d.svg.area().x(ya).y0(function(a){return x(a.id)(0)}).y1(function(a){return x(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Na([b],"area")||Na([b],"area-spline"))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d=l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),je=function(){var a=d.svg.line().x(function(a){return S(a.x)}).y(function(a){return Y(a.id)(a.value)});return function(b){var c=Ib(b.values);return Fb(b)?a(c):"M "+S(c[0].x)+" "+Y(b.id)(c[0].value)}}(), -I=d.svg.brush().on("brush",function(){F({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),E=d.behavior.zoom().on("zoomstart",function(){E.altDomain=d.event.sourceEvent.altKey?l.orgDomain():null}).on("zoom",ra?ke:null);I.update=function(){A&&A.select(".x.brush").call(this);return this};E.orgScaleExtent=function(){var a=fd?fd:[1,10];return[a[0],Math.max(Qa()/a[1],a[1])]};E.updateScaleExtent=function(){var a=l.orgDomain(),a=(a[1]-a[0])/(T[1]-T[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]* -a,b[1]*a]);return this};var q,qb,k,A,Aa,U,pb,T;h.focus=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);h.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);C(h.data.targets)&&Ga(a,!0)};h.defocus=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);C(h.data.targets)&&Ha(a)}; -h.revert=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);C(h.data.targets)&&Ha(a)};h.show=function(a){q.selectAll(Za(a)).transition().style("opacity",1)};h.hide=function(a){q.selectAll(Za(a)).transition().style("opacity",0)};h.unzoom=function(){I.clear().update();F({withUpdateXDomain:!0})};h.load=function(a){u(a.done)&&(a.done=function(){});"categories"in a&&aa&& -(Ja=a.categories,H.categories(Ja));if("cacheIds"in a&&Bd(a.cacheIds))Xa(Cd(a.cacheIds),a.done);else if("data"in a)Xa(Pa(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Xa(Pa(c),a.done)});else if("rows"in a)Xa(Pa(rc(a.rows)),a.done);else if("columns"in a)Xa(Pa(sc(a.columns)),a.done);else throw Error("url or rows or columns is required.");};h.unload=function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});q.selectAll(".target-"+a).transition().style("opacity",0).remove(); -Ba&&(q.selectAll(".legend-item-"+a).remove(),sb(h.data.targets));0b.classes.indexOf(a)})});return P}; -h.data.get=function(a){a=h.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=kb(function(b){return b.id===a});return 0Eb(c,a)?q.select(".event-rect").style("cursor","pointer"):q.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;C(h.data.targets)||(a=d.mouse(this),c=Cc(h.data.targets, +a),100>Eb(c,a)&&k.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Zc(this,c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){$c(d.mouse(this))}).on("dragstart",function(){ad(d.mouse(this))}).on("dragend",function(){bd()})).call(E).on("dblclick.zoom",null)}function Zc(a,b,c){var f=d.select(a),e=f.classed(ka),h=!1,g;"circle"===a.nodeName?(h=Nc(a,1.5*Ua),g=Qc):"rect"===a.nodeName&&(h=Oc(a),g=Sc);if(sa||h)ia&&ja(b)&&(f.classed(ka,!e),g(!e,f,b,c)),ge(b,f)} +function $c(a){var b,c,f,e,g,l,n;C(h.data.targets)||!ia||ra&&!E.altDomain||(b=Tb[0],c=Tb[1],f=a[0],a=a[1],e=Math.min(b,f),g=Math.max(b,f),l=sa?t:Math.min(c,a),n=sa?s:Math.max(c,a),k.select(".dragarea").attr("x",e).attr("y",l).attr("width",g-e).attr("height",n-l),k.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ja(a)}).each(function(a,b){var c=d.select(this),f=c.classed(ka),h=c.classed(Ub),k,p,r,q;k=!1;"circle"===this.nodeName?(k=1*c.attr("cx"),p=1*c.attr("cy"),q=Qc,k=e",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),de=e(["tooltip","init","show"],!1),Ca=e(["tooltip","init","x"],0),Yc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Nb=wa.replace("#","")+"-clip",Va="url(#"+Nb+")",B="timeseries"===hd,aa="categorized"===hd,Db=!B&&(qa||ba),Tb=null,Wa=!1,Sb=!1,ma=Ba?40:0,P=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]}}(ne,oe),qd=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)}}(),$b,gc,bc,cb,fc,hc,r,s,na,ub,va,db,xb,hb,lc,mc,Ab,jc,kc,yb,zb,l,z,$,T,eb,fb,H,oa,gb,Ia,ld=g?"left":"bottom",md=g?wb?"top":"bottom":wb?"right":"left",nd=g?vb?"bottom":"top":vb?"left":"right",od="bottom",J={main:function(){return"translate("+G+","+t+")"},context:function(){return"translate("+n+","+Da+")"},legend:function(){return"translate("+Zb+","+Yb+")"}, +y2:function(){return"translate("+(g?0:r)+","+(g?10:0)+")"},x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+na+")"},arc:function(){return"translate("+r/2+","+s/2+")"}};Ab=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var ie=function(){var a=d.svg.line().x(g?function(a){return x(a.id)(a.value)}:ya).y(g?ya:function(a){return x(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Fb(b))return Kc(b)?a.interpolate("cardinal"): +a.interpolate("linear"),gd[b.id]?Rd(c,l,x(b.id),gd[b.id]):a(c);d=l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),je=function(){var a;a=g?d.svg.area().x0(function(a){return x(a.id)(0)}).x1(function(a){return x(a.id)(a.value)}).y(ya):d.svg.area().x(ya).y0(function(a){return x(a.id)(0)}).y1(function(a){return x(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Na([b],"area")||Na([b],"area-spline"))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d= +l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),ke=function(){var a=d.svg.line().x(function(a){return T(a.x)}).y(function(a){return Y(a.id)(a.value)});return function(b){var c=Ib(b.values);return Fb(b)?a(c):"M "+T(c[0].x)+" "+Y(b.id)(c[0].value)}}(),I=d.svg.brush().on("brush",function(){F({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),E=d.behavior.zoom().on("zoomstart",function(){E.altDomain=d.event.sourceEvent.altKey?l.orgDomain():null}).on("zoom",ra? +le:null);I.update=function(){A&&A.select(".x.brush").call(this);return this};E.orgScaleExtent=function(){var a=fd?fd:[1,10];return[a[0],Math.max(Qa()/a[1],a[1])]};E.updateScaleExtent=function(){var a=l.orgDomain(),a=(a[1]-a[0])/(U[1]-U[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var q,qb,k,A,Aa,V,pb,U;h.focus=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);h.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity", +1);C(h.data.targets)&&Ga(a,!0)};h.defocus=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);C(h.data.targets)&&Ha(a)};h.revert=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);C(h.data.targets)&&Ha(a)};h.show=function(a){q.selectAll(Za(a)).transition().style("opacity", +1)};h.hide=function(a){q.selectAll(Za(a)).transition().style("opacity",0)};h.unzoom=function(){I.clear().update();F({withUpdateXDomain:!0})};h.load=function(a){u(a.done)&&(a.done=function(){});"categories"in a&&aa&&(Ja=a.categories,H.categories(Ja));if("cacheIds"in a&&Bd(a.cacheIds))Xa(Cd(a.cacheIds),a.done);else if("data"in a)Xa(Pa(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Xa(Pa(c),a.done)});else if("rows"in a)Xa(Pa(rc(a.rows)),a.done);else if("columns"in a)Xa(Pa(sc(a.columns)), +a.done);else throw Error("url or rows or columns is required.");};h.unload=function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});q.selectAll(".target-"+a).transition().style("opacity",0).remove();Ba&&(q.selectAll(".legend-item-"+a).remove(),sb(h.data.targets));0b.classes.indexOf(a)})});return Q};h.data.get=function(a){a=h.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=kb(function(b){return b.id===a});return 0 Date: Thu, 13 Feb 2014 11:14:16 +0900 Subject: [PATCH 3/3] Fix unload when stacked bar chart --- c3.js | 4 +- c3.min.js | 164 +++++++++++++++++++++++++++--------------------------- 2 files changed, 84 insertions(+), 84 deletions(-) diff --git a/c3.js b/c3.js index 67a691d..896ee0d 100644 --- a/c3.js +++ b/c3.js @@ -458,8 +458,8 @@ if (! isBarType(__data_groups[j][k])) { continue; } if (isUndefined(ys[__data_groups[j][k]])) { continue; } ys[__data_groups[j][k]].forEach(function (v, i) { - if (getAxisId(__data_groups[j][k]) === getAxisId(__data_groups[j][0])) { - ys[__data_groups[j][0]][i] += v * 1; + if (getAxisId(__data_groups[j][k]) === getAxisId(__data_groups[j][0]) && ys[__data_groups[j][0]]) { + ys[__data_groups[j][0]][i] += +v; } }); } diff --git a/c3.min.js b/c3.min.js index 06d8013..44820f2 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,83 +1,83 @@ -(function(M){function id(){function p(d,e){d.attr("transform",function(d){return"translate("+(e(d)+ea)+", 0)"})}function u(d,e){d.attr("transform",function(d){return"translate(0,"+e(d)+")"})}function M(d){var e=d[0];d=d[d.length-1];return ea?0:a}function qc(a){return qa&&a===qa||ba&&Dd(ba,a)}function Ed(a){return!qc(a)}function nb(a){var b= -Oa[a.id];a.name=p(b)?b:a.id;return a}function rc(a){var b=a[0],c={},f=[],m,d;for(m=1;my[c].indexOf(m.id)))for(f=0;fb?a-b:0};return function(a){var d=b?Y(a.id):x(a.id);return c(d(a.value))}}function Ta(a,b){var c=u(a)?ob():a;"string"===typeof c&&(c=[c]);for(var f=0;f=e;e+=s)h+=f(a[d-1],a[d],e,n)}return h}function Mb(a){var b,c;pb=d.select(wa);if(pb.empty())M.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');else{pb.html(""); -h.data.x={};h.data.targets=Pa(a);ua();Xb();l.domain(d.extent(lb(h.data.targets)));z.domain(jb("y"));$.domain(jb("y2"));T.domain(l.domain());eb.domain(z.domain());fb.domain($.domain());H.ticks(10>a.length?a.length:10);oa.ticks(Sd).outerTickSize(0).tickFormat(Td);gb.ticks(Ud).outerTickSize(0).tickFormat(Vd);U=l.domain();I.x(T);ra&&E.x(l);q=d.select(wa).append("svg").attr("width",r+G+fa).attr("height",s+t+L).on("mouseenter",Wd).on("mouseleave",Xd);qb=q.append("defs");qb.append("clipPath").attr("id", -Nb).append("rect").attr("y",t).attr("width",r).attr("height",s-t);qb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-G).attr("y",-20).attr("width",X).attr("height",W);qb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-G+1).attr("y",t-1).attr("width",la).attr("height",tb);k=q.append("g").attr("transform",J.main);A=za?q.append("g").attr("transform",J.context):null;Aa=Ba?q.append("g").attr("transform",J.legend):null;V=d.select(wa).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",J.x).call(g?oa:H).append("text").attr("class","-axis-x-label").attr("x",r).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?H:oa).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Zd);dc&& -k.append("g").attr("class","y2 axis").attr("transform",J.y2).call(gb);b=k.append("g").attr("clip-path",Va).attr("class","grid");Vc&&b.append("g").attr("class","xgrids");Ob&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Ob).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",g?"":"rotate(-90)").attr("dx",g? -0:-t).attr("dy",-6).text(function(a){return a.text}));$d&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?r:-10).attr("y1",g?-10:t).attr("y2",g?-10:s);Wc&&b.append("g").attr("class","ygrids");Pb&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Pb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Va).attr("class","regions");k.append("g").attr("clip-path", -Va).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ra?"ew-resize":null);ba?ae(b):be(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");k.select(".chart").append("g").attr("class","chart-arcs").attr("transform",J.arc);if(ra)k.insert("rect",ce?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",s).style("opacity",0).style("cursor","ew-resize").call(E).on("dblclick.zoom", -null);null!==rb&&I.extent("function"!==typeof rb?rb:rb(lb()));za&&(A.append("g").attr("clip-path",Va).attr("class","chart"),A.select(".chart").append("g").attr("class","chart-bars"),A.select(".chart").append("g").attr("class","chart-lines"),A.append("g").attr("clip-path",Va).attr("class","x brush").call(I).selectAll("rect").attr("height",na),A.append("g").attr("class","x axis").attr("transform",J.subx).call(Ia));Ba&&sb(h.data.targets);Xc(h.data.targets);F({withTransition:!1,withUpdateXDomain:!0}); -if(de){if(B&&"string"===typeof Ca){Ca=pa(Ca);for(a=0;aEb(c,a)?q.select(".event-rect").style("cursor","pointer"):q.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;C(h.data.targets)||(a=d.mouse(this),c=Cc(h.data.targets, -a),100>Eb(c,a)&&k.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Zc(this,c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){$c(d.mouse(this))}).on("dragstart",function(){ad(d.mouse(this))}).on("dragend",function(){bd()})).call(E).on("dblclick.zoom",null)}function Zc(a,b,c){var f=d.select(a),e=f.classed(ka),h=!1,g;"circle"===a.nodeName?(h=Nc(a,1.5*Ua),g=Qc):"rect"===a.nodeName&&(h=Oc(a),g=Sc);if(sa||h)ia&&ja(b)&&(f.classed(ka,!e),g(!e,f,b,c)),ge(b,f)} -function $c(a){var b,c,f,e,g,l,n;C(h.data.targets)||!ia||ra&&!E.altDomain||(b=Tb[0],c=Tb[1],f=a[0],a=a[1],e=Math.min(b,f),g=Math.max(b,f),l=sa?t:Math.min(c,a),n=sa?s:Math.max(c,a),k.select(".dragarea").attr("x",e).attr("y",l).attr("width",g-e).attr("height",n-l),k.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ja(a)}).each(function(a,b){var c=d.select(this),f=c.classed(ka),h=c.classed(Ub),k,p,r,q;k=!1;"circle"===this.nodeName?(k=1*c.attr("cx"),p=1*c.attr("cy"),q=Qc,k=e",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),de=e(["tooltip","init","show"],!1),Ca=e(["tooltip","init","x"],0),Yc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Nb=wa.replace("#","")+"-clip",Va="url(#"+Nb+")",B="timeseries"===hd,aa="categorized"===hd,Db=!B&&(qa||ba),Tb=null,Wa=!1,Sb=!1,ma=Ba?40:0,P=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]}}(ne,oe),qd=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)}}(),$b,gc,bc,cb,fc,hc,r,s,na,ub,va,db,xb,hb,lc,mc,Ab,jc,kc,yb,zb,l,z,$,T,eb,fb,H,oa,gb,Ia,ld=g?"left":"bottom",md=g?wb?"top":"bottom":wb?"right":"left",nd=g?vb?"bottom":"top":vb?"left":"right",od="bottom",J={main:function(){return"translate("+G+","+t+")"},context:function(){return"translate("+n+","+Da+")"},legend:function(){return"translate("+Zb+","+Yb+")"}, -y2:function(){return"translate("+(g?0:r)+","+(g?10:0)+")"},x:function(){return"translate(0,"+s+")"},subx:function(){return"translate(0,"+na+")"},arc:function(){return"translate("+r/2+","+s/2+")"}};Ab=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var ie=function(){var a=d.svg.line().x(g?function(a){return x(a.id)(a.value)}:ya).y(g?ya:function(a){return x(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Fb(b))return Kc(b)?a.interpolate("cardinal"): -a.interpolate("linear"),gd[b.id]?Rd(c,l,x(b.id),gd[b.id]):a(c);d=l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),je=function(){var a;a=g?d.svg.area().x0(function(a){return x(a.id)(0)}).x1(function(a){return x(a.id)(a.value)}).y(ya):d.svg.area().x(ya).y0(function(a){return x(a.id)(0)}).y1(function(a){return x(a.id)(a.value)});return function(b){var c=Ib(b.values),d;if(Na([b],"area")||Na([b],"area-spline"))return Kc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d= -l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),ke=function(){var a=d.svg.line().x(function(a){return T(a.x)}).y(function(a){return Y(a.id)(a.value)});return function(b){var c=Ib(b.values);return Fb(b)?a(c):"M "+T(c[0].x)+" "+Y(b.id)(c[0].value)}}(),I=d.svg.brush().on("brush",function(){F({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),E=d.behavior.zoom().on("zoomstart",function(){E.altDomain=d.event.sourceEvent.altKey?l.orgDomain():null}).on("zoom",ra? -le:null);I.update=function(){A&&A.select(".x.brush").call(this);return this};E.orgScaleExtent=function(){var a=fd?fd:[1,10];return[a[0],Math.max(Qa()/a[1],a[1])]};E.updateScaleExtent=function(){var a=l.orgDomain(),a=(a[1]-a[0])/(U[1]-U[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var q,qb,k,A,Aa,V,pb,U;h.focus=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);h.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity", -1);C(h.data.targets)&&Ga(a,!0)};h.defocus=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);C(h.data.targets)&&Ha(a)};h.revert=function(a){var b=q.selectAll(Za(a)),c=b.filter(Vb),b=b.filter(Wb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);C(h.data.targets)&&Ha(a)};h.show=function(a){q.selectAll(Za(a)).transition().style("opacity", -1)};h.hide=function(a){q.selectAll(Za(a)).transition().style("opacity",0)};h.unzoom=function(){I.clear().update();F({withUpdateXDomain:!0})};h.load=function(a){u(a.done)&&(a.done=function(){});"categories"in a&&aa&&(Ja=a.categories,H.categories(Ja));if("cacheIds"in a&&Bd(a.cacheIds))Xa(Cd(a.cacheIds),a.done);else if("data"in a)Xa(Pa(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Xa(Pa(c),a.done)});else if("rows"in a)Xa(Pa(rc(a.rows)),a.done);else if("columns"in a)Xa(Pa(sc(a.columns)), -a.done);else throw Error("url or rows or columns is required.");};h.unload=function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});q.selectAll(".target-"+a).transition().style("opacity",0).remove();Ba&&(q.selectAll(".legend-item-"+a).remove(),sb(h.data.targets));0b.classes.indexOf(a)})});return Q};h.data.get=function(a){a=h.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=kb(function(b){return b.id===a});return 0a?0:a}function pc(a){return pa&&a===pa||aa&&Cd(aa,a)}function Dd(a){return!pc(a)} +function mb(a){var b=Na[a.id];a.name=p(b)?b:a.id;return a}function qc(a){var b=a[0],c={},f=[],m,d;for(m=1;ms[c].indexOf(m.id)))for(f=0;fb?a-b:0};return function(a){var d=b?X(a.id):x(a.id);return c(d(a.value))}}function Sa(a,b){var c=v(a)?nb():a;"string"===typeof c&&(c=[c]);for(var f=0;f=e;e+=t)h+=f(a[d-1],a[d],e,n)}return h}function Lb(a){var b,c;ob=d.select(va);if(ob.empty())L.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".'); +else{ob.html("");h.data.x={};h.data.targets=Oa(a);ta();Wb();l.domain(d.extent(kb(h.data.targets)));y.domain(ib("y"));Z.domain(ib("y2"));S.domain(l.domain());db.domain(y.domain());eb.domain(Z.domain());G.ticks(10>a.length?a.length:10);na.ticks(Rd).outerTickSize(0).tickFormat(Sd);fb.ticks(Td).outerTickSize(0).tickFormat(Ud);T=l.domain();H.x(S);qa&&D.x(l);q=d.select(va).append("svg").attr("width",r+F+ea).attr("height",t+u+K).on("mouseenter",Vd).on("mouseleave",Wd);pb=q.append("defs");pb.append("clipPath").attr("id", +Mb).append("rect").attr("y",u).attr("width",r).attr("height",t-u);pb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-F).attr("y",-20).attr("width",W).attr("height",V);pb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-F+1).attr("y",u-1).attr("width",ka).attr("height",sb);k=q.append("g").attr("transform",I.main);z=ya?q.append("g").attr("transform",I.context):null;za=Aa?q.append("g").attr("transform",I.legend):null;U=d.select(va).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",I.x).call(g?na:G).append("text").attr("class","-axis-x-label").attr("x",r).attr("dy","-.5em").style("text-anchor","end").text(Xd);k.append("g").attr("class","y axis").attr("clip-path",g?"url(#yaxis-clip)":"").call(g?G:na).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(Yd);cc&& +k.append("g").attr("class","y2 axis").attr("transform",I.y2).call(fb);b=k.append("g").attr("clip-path",Ua).attr("class","grid");Uc&&b.append("g").attr("class","xgrids");Nb&&(c=b.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Nb).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",g?"":"rotate(-90)").attr("dx",g? +0:-u).attr("dy",-6).text(function(a){return a.text}));Zd&&b.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?r:-10).attr("y1",g?-10:u).attr("y2",g?-10:t);Vc&&b.append("g").attr("class","ygrids");Ob&&b.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Ob).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});k.append("g").attr("clip-path",Ua).attr("class","regions");k.append("g").attr("clip-path", +Ua).attr("class","chart");b=k.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",qa?"ew-resize":null);aa?$d(b):ae(b,a);k.select(".chart").append("g").attr("class","chart-bars");k.select(".chart").append("g").attr("class","chart-lines");k.select(".chart").append("g").attr("class","chart-arcs").attr("transform",I.arc);if(qa)k.insert("rect",be?null:"g.grid").attr("class","zoom-rect").attr("width",r).attr("height",t).style("opacity",0).style("cursor","ew-resize").call(D).on("dblclick.zoom", +null);null!==qb&&H.extent("function"!==typeof qb?qb:qb(kb()));ya&&(z.append("g").attr("clip-path",Ua).attr("class","chart"),z.select(".chart").append("g").attr("class","chart-bars"),z.select(".chart").append("g").attr("class","chart-lines"),z.append("g").attr("clip-path",Ua).attr("class","x brush").call(H).selectAll("rect").attr("height",ma),z.append("g").attr("class","x axis").attr("transform",I.subx).call(Ha));Aa&&rb(h.data.targets);Wc(h.data.targets);E({withTransition:!1,withUpdateXDomain:!0}); +if(ce){if(A&&"string"===typeof Ba){Ba=oa(Ba);for(a=0;aDb(c,a)?q.select(".event-rect").style("cursor","pointer"):q.select(".event-rect").style("cursor",null))}).on("click",function(){var a,c;B(h.data.targets)||(a=d.mouse(this),c=Bc(h.data.targets, +a),100>Db(c,a)&&k.select(".-circles-"+c.id).select(".-circle-"+c.index).each(function(){Yc(this,c,c.index)}))}).call(d.behavior.drag().origin(Object).on("drag",function(){Zc(d.mouse(this))}).on("dragstart",function(){$c(d.mouse(this))}).on("dragend",function(){ad()})).call(D).on("dblclick.zoom",null)}function Yc(a,b,c){var f=d.select(a),e=f.classed(ja),h=!1,g;"circle"===a.nodeName?(h=Mc(a,1.5*Ta),g=Pc):"rect"===a.nodeName&&(h=Nc(a),g=Rc);if(ra||h)ha&&ia(b)&&(f.classed(ja,!e),g(!e,f,b,c)),fe(b,f)} +function Zc(a){var b,c,f,e,g,l,n;B(h.data.targets)||!ha||qa&&!D.altDomain||(b=Sb[0],c=Sb[1],f=a[0],a=a[1],e=Math.min(b,f),g=Math.max(b,f),l=ra?u:Math.min(c,a),n=ra?t:Math.max(c,a),k.select(".dragarea").attr("x",e).attr("y",l).attr("width",g-e).attr("height",n-l),k.selectAll(".-shapes").selectAll(".-shape").filter(function(a){return ia(a)}).each(function(a,b){var c=d.select(this),f=c.classed(ja),h=c.classed(Tb),k,p,r,q;k=!1;"circle"===this.nodeName?(k=1*c.attr("cx"),p=1*c.attr("cy"),q=Pc,k=e",c,d,e;for(c=0;c"+e+""+d+"";return b+""}),ce=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Xc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Mb=va.replace("#","")+"-clip",Ua="url(#"+Mb+")",A="timeseries"===gd,$="categorized"===gd,Cb=!A&&(pa||aa),Sb=null,Va=!1,Rb=!1,la=Aa?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]}}(me,ne),pd=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)}}(),Zb,fc,ac,bb,ec,gc,r,t,ma,tb,ua,cb,wb,gb,kc,lc,zb,ic,jc,xb,yb,l,y,Z,S,db,eb,G,na,fb,Ha,kd=g?"left":"bottom",ld=g?vb?"top":"bottom":vb?"right":"left",md=g?ub?"bottom":"top":ub?"left":"right",nd="bottom",I={main:function(){return"translate("+F+","+u+")"},context:function(){return"translate("+n+","+Ca+")"},legend:function(){return"translate("+Yb+","+Xb+")"}, +y2:function(){return"translate("+(g?0:r)+","+(g?10:0)+")"},x:function(){return"translate(0,"+t+")"},subx:function(){return"translate(0,"+ma+")"},arc:function(){return"translate("+r/2+","+t/2+")"}};zb=d.layout.pie().value(function(a){return a.values.reduce(function(a,c){return a+c.value},0)});var he=function(){var a=d.svg.line().x(g?function(a){return x(a.id)(a.value)}:xa).y(g?xa:function(a){return x(a.id)(a.value)});return function(b){var c=Hb(b.values),d;if(Eb(b))return Jc(b)?a.interpolate("cardinal"): +a.interpolate("linear"),fd[b.id]?Qd(c,l,x(b.id),fd[b.id]):a(c);d=l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),ie=function(){var a;a=g?d.svg.area().x0(function(a){return x(a.id)(0)}).x1(function(a){return x(a.id)(a.value)}).y(xa):d.svg.area().x(xa).y0(function(a){return x(a.id)(0)}).y1(function(a){return x(a.id)(a.value)});return function(b){var c=Hb(b.values),d;if(Ma([b],"area")||Ma([b],"area-spline"))return Jc(b)?a.interpolate("cardinal"):a.interpolate("linear"),a(c);d= +l(c[0].x);b=x(b.id)(c[0].value);return g?"M "+b+" "+d:"M "+d+" "+b}}(),je=function(){var a=d.svg.line().x(function(a){return S(a.x)}).y(function(a){return X(a.id)(a.value)});return function(b){var c=Hb(b.values);return Eb(b)?a(c):"M "+S(c[0].x)+" "+X(b.id)(c[0].value)}}(),H=d.svg.brush().on("brush",function(){E({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),D=d.behavior.zoom().on("zoomstart",function(){D.altDomain=d.event.sourceEvent.altKey?l.orgDomain():null}).on("zoom",qa? +ke:null);H.update=function(){z&&z.select(".x.brush").call(this);return this};D.orgScaleExtent=function(){var a=ed?ed:[1,10];return[a[0],Math.max(Pa()/a[1],a[1])]};D.updateScaleExtent=function(){var a=l.orgDomain(),a=(a[1]-a[0])/(T[1]-T[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var q,pb,k,z,za,U,ob,T;h.focus=function(a){var b=q.selectAll(Ya(a)),c=b.filter(Ub),b=b.filter(Vb);h.defocus();c.classed("focused",!0).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity", +1);B(h.data.targets)&&Fa(a,!0)};h.defocus=function(a){var b=q.selectAll(Ya(a)),c=b.filter(Ub),b=b.filter(Vb);c.classed("focused",!1).transition().duration(100).style("opacity",0.3);b.transition().duration(100).style("opacity",0.3);B(h.data.targets)&&Ga(a)};h.revert=function(a){var b=q.selectAll(Ya(a)),c=b.filter(Ub),b=b.filter(Vb);c.classed("focused",!1).transition().duration(100).style("opacity",1);b.transition().duration(100).style("opacity",1);B(h.data.targets)&&Ga(a)};h.show=function(a){q.selectAll(Ya(a)).transition().style("opacity", +1)};h.hide=function(a){q.selectAll(Ya(a)).transition().style("opacity",0)};h.unzoom=function(){H.clear().update();E({withUpdateXDomain:!0})};h.load=function(a){v(a.done)&&(a.done=function(){});"categories"in a&&$&&(Ia=a.categories,G.categories(Ia));if("cacheIds"in a&&Ad(a.cacheIds))Wa(Bd(a.cacheIds),a.done);else if("data"in a)Wa(Oa(a.data),a.done);else if("url"in a)d.csv(a.url,function(b,c){Wa(Oa(c),a.done)});else if("rows"in a)Wa(Oa(qc(a.rows)),a.done);else if("columns"in a)Wa(Oa(rc(a.columns)), +a.done);else throw Error("url or rows or columns is required.");};h.unload=function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});q.selectAll(".target-"+a).transition().style("opacity",0).remove();Aa&&(q.selectAll(".legend-item-"+a).remove(),rb(h.data.targets));0b.classes.indexOf(a)})});return P};h.data.get=function(a){a=h.data.getAsTarget(a);return p(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=jb(function(b){return b.id===a});return 0