Browse Source

Bind onenter/onleave to root svg

pull/1/head
Masayuki Tanaka 11 years ago
parent
commit
e88fca3d0e
  1. 8
      c3.js
  2. 16
      c3.min.js

8
c3.js

@ -863,7 +863,9 @@
// Define svgs
svg = d3.select(__bindto).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
.attr("height", height + margin.top + margin.bottom)
.on('mouseenter', __onenter)
.on('mouseleave', __onleave);
// Define defs
defs = svg.append("defs");
@ -986,9 +988,7 @@
// Define g for chart area
main.append('g')
.attr("clip-path", clipPath)
.attr('class', 'chart')
.on('mouseenter', __onenter)
.on('mouseleave', __onleave);
.attr('class', 'chart');
// Cover whole with rects for events
main.select('.chart').append("g")

16
c3.min.js vendored

@ -18,11 +18,11 @@ Y["string"===typeof a?a:a.id]}function Cc(a){return mb(a)?a.values:[]}function T
c,d){Ec(a,c);g.select(".selected-circles-"+c.id).selectAll(".selected-circle-"+d).data([c]).enter().append("circle").attr("class",function(a){return"selected-circle selected-circle-"+d}).attr("cx",e?X:W).attr("cy",e?W:X).attr("stroke",function(){return Q(c.id)}).attr("r",1.4*Ga).transition().duration(100).attr("r",Ga)}function nb(a,c,d){Fc(a,c);g.select(".selected-circles-"+c.id).selectAll(".selected-circle-"+d).transition().duration(100).attr("r",0).remove()}function Xb(a,c,d,b){a?Wb(c,d,b):nb(c,
d,b)}function Gc(a,c,d){}function Yb(a,c,d){}function Zb(a,c,d,b){}function Hc(a,c,d,b){var f,g,n="M",k,m,h,r,t,s=[];if(l(b))for(f=0;f<b.length;f++)s[f]={},u(b[f].start)?s[f].start=a[0].x:D&&(s[f].start=ia(b[f].start)),u(b[f].end)?s[f].end=a[a.length-1].x:D&&(s[f].end=ia(b[f].end));r=e?function(a){return d(a.value)}:function(a){return c(a.x)};t=e?function(a){return c(a.x)}:function(a){return d(a.value)};b=D?function(a,b,f,e){var n=a.x.getTime();a=b.x-a.x;b=new Date(n+a*(f+e));return"M"+c(new Date(n+
a*f))+" "+d(m(f))+" "+c(b)+" "+d(m(f+e))}:function(a,b,f,e){return"M"+c(k(f))+" "+d(m(f))+" "+c(k(f+e))+" "+d(m(f+e))};for(f=0;f<a.length;f++)if(u(s)||!Dc(a[f].x,s))n+=" "+r(a[f])+" "+t(a[f]);else for(k=L(a[f-1].x,a[f].x),m=y(a[f-1].value,a[f].value),g=c(a[f].x)-c(a[f-1].x),h=d(a[f].value)-d(a[f-1].value),g=Math.sqrt(Math.pow(g,2)+Math.pow(h,2)),h=2/g,diffx2=2*h,g=h;1>=g;g+=diffx2)n+=b(a[f-1],a[f],g,h);return n}function ob(a){var c=k.data.targets=da(a),d,b;N();S();m.domain(d3.extent(a.map(function(a){return a.x})));
x.domain(B(c,"y"));O.domain(B(c,"y2"));V.domain(m.domain());Qa.domain(x.domain());Ra.domain(O.domain());M.ticks(10>a.length?a.length:10);ga.ticks(Ic).outerTickSize(0).tickFormat(Jc);Sa.ticks(Kc).outerTickSize(0).tickFormat(Lc);P=m.domain();E.x(V);ja&&F.x(m);Ha=d3.select(ya).append("svg").attr("width",t+H+C).attr("height",s+v+U);Ya=Ha.append("defs");Ya.append("clipPath").attr("id",pb).append("rect").attr("y",v).attr("width",t).attr("height",s-v);Ya.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",
-1).attr("y",-1).attr("width",t+2).attr("height",40);Ya.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-H+1).attr("y",v-1).attr("width",H).attr("height",s-v+2);g=Ha.append("g").attr("transform",I.main);w=qa?Ha.append("g").attr("transform",I.context):null;ra=sa?Ha.append("g").attr("transform",I.legend):null;Z=d3.select(ya).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",e?"":"url(#xaxis-clip)").attr("transform",I.x).call(e?ga:M);g.append("g").attr("class","y axis").attr("clip-path",e?"url(#yaxis-clip)":"").call(e?M:ga).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Mc);Fb&&g.append("g").attr("class","y2 axis").attr("transform",I.y2).call(Sa);d=g.append("g").attr("clip-path",Ia).attr("class","grid");$b&&d.append("g").attr("class","xgrids");qb&&(b=d.append("g").attr("class",
"xgrid-lines").selectAll(".xgrid-line").data(qb).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-v).attr("dy",-6).text(function(a){return a.text}));Nc&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",e?t:-10).attr("y1",e?-10:v).attr("y2",
e?-10:s);ac&&d.append("g").attr("class","ygrids");rb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(rb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Ia).attr("class","regions");g.append("g").attr("clip-path",Ia).attr("class","chart").on("mouseenter",Oc).on("mouseleave",Pc);g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ja?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",
x.domain(B(c,"y"));O.domain(B(c,"y2"));V.domain(m.domain());Qa.domain(x.domain());Ra.domain(O.domain());M.ticks(10>a.length?a.length:10);ga.ticks(Ic).outerTickSize(0).tickFormat(Jc);Sa.ticks(Kc).outerTickSize(0).tickFormat(Lc);P=m.domain();E.x(V);ja&&F.x(m);Ha=d3.select(ya).append("svg").attr("width",t+H+C).attr("height",s+v+U).on("mouseenter",Mc).on("mouseleave",Nc);Ya=Ha.append("defs");Ya.append("clipPath").attr("id",pb).append("rect").attr("y",v).attr("width",t).attr("height",s-v);Ya.append("clipPath").attr("id",
"xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",t+2).attr("height",40);Ya.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-H+1).attr("y",v-1).attr("width",H).attr("height",s-v+2);g=Ha.append("g").attr("transform",I.main);w=qa?Ha.append("g").attr("transform",I.context):null;ra=sa?Ha.append("g").attr("transform",I.legend):null;Z=d3.select(ya).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",e?"":"url(#xaxis-clip)").attr("transform",I.x).call(e?ga:M);g.append("g").attr("class","y axis").attr("clip-path",e?"url(#yaxis-clip)":"").call(e?M:ga).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Oc);Fb&&g.append("g").attr("class","y2 axis").attr("transform",I.y2).call(Sa);d=g.append("g").attr("clip-path",Ia).attr("class","grid");$b&&d.append("g").attr("class","xgrids");
qb&&(b=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(qb).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-v).attr("dy",-6).text(function(a){return a.text}));Pc&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",
e?t:-10).attr("y1",e?-10:v).attr("y2",e?-10:s);ac&&d.append("g").attr("class","ygrids");rb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(rb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Ia).attr("class","regions");g.append("g").attr("clip-path",Ia).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).style("cursor",ja?"ew-resize":null).selectAll(".event-rects").data(a).enter().append("rect").attr("class",
function(a,c){return"event-rect event-rect-"+c}).style("cursor",$&&ka?"pointer":null).on("mouseover",function(a,c){if(!Za){var d=k.data.targets.map(function(a){return ca(a.values[c])}),b,p;if(0<Object.keys(Da).length){p=[];for(var h in Da)for(b=0;b<d.length;b++)if(d[b].id===h){p.push(d[b]);d.shift(b);break}d=p.concat(d)}bc&&g.selectAll(".-circle-"+c).classed(aa,!0).attr("r",cc);g.selectAll(".-bar-"+c).classed(aa,!0);g.selectAll("line.xgrid-focus").style("visibility","visible").data([d[0]]).attr(e?
"y1":"x1",Xa).attr(e?"y2":"x2",Xa);Z.style("top",d3.mouse(this)[1]+30+"px").style("left",(e?d3.mouse(this)[0]:m(d[0].x))+60+"px");Z.html(dc(d));Z.style("visibility","visible")}}).on("mouseout",function(a,c){g.select("line.xgrid-focus").style("visibility","hidden");Z.style("visibility","hidden");g.selectAll(".-circle-"+c).filter(function(){return d3.select(this).classed(aa)}).classed(aa,!1).attr("r",sb);g.selectAll(".-bar-"+c).classed(aa,!1)}).on("mousemove",function(a,c){$&&!Za&&(ka||g.selectAll(".-shape-"+
c).filter(function(a){return la(a)}).each(function(a){a=d3.select(this).classed(aa,!0);"circle"===this.nodeName&&a.attr("r",cc);d3.select(".event-rect-"+c).style("cursor",null)}).filter(function(a){a=d3.select(this);if("circle"===this.nodeName)return Ub(this,Ga);if("rect"===this.nodeName)return Vb(this,a.attr("x"),a.attr("y"))}).each(function(a){a=d3.select(this);a.classed(aa)||(a.classed(aa,!0),"circle"===this.nodeName&&a.attr("r",Ga));d3.select(".event-rect-"+c).style("cursor","pointer")}))}).on("click",
@ -45,10 +45,10 @@ c=w.select(".chart-lines").selectAll(".chart-line").data(a),c=c.enter().append("
z();c()}function $a(a,c){var b=ib(a),e,f=t/2-La*Object.keys(a).length/2,g;c=u(c)?{}:c;g=l(c.withTransition)?c.withTransition:!0;e=ra.selectAll(".legend-item").data(b).enter().append("g").attr("class",function(a){return"legend-item legend-item-"+a}).style("cursor","pointer").on("click",function(a){Xc(a)}).on("mouseover",function(a){d3.selectAll(".legend-item").filter(function(c){return c!==a}).transition().duration(100).style("opacity",0.3);k.focus(a)}).on("mouseout",function(a){d3.selectAll(".legend-item").transition().duration(100).style("opacity",
1);k.revert()});e.append("rect").attr("class","legend-item-event").style("fill-opacity",0).attr("x",-200).attr("y",function(){return ea/2-16}).attr("width",La).attr("height",24);e.append("rect").attr("class","legend-item-tile").style("fill",function(a){return Q(a)}).attr("x",-200).attr("y",function(){return ea/2-9}).attr("width",10).attr("height",10);e.append("text").text(function(a){return l(Da[a])?Da[a]:a}).attr("x",-200).attr("y",function(a,c){return ea/2});ra.selectAll("rect.legend-item-event").data(b).transition().duration(g?
250:0).attr("x",function(a,c){return f+La*c});ra.selectAll("rect.legend-item-tile").data(b).transition().duration(g?250:0).attr("x",function(a,c){return f+La*c});ra.selectAll("text").data(b).transition().duration(g?250:0).attr("x",function(a,c){return f+La*c+14})}function Ma(a){return l(a)?".target-"+a:".target"}var k={data:{}},Ua={},aa="_expanded_",ba="_selected_",vb="_included_",ya=b(["bindto"],"#chart"),Ab=b(["size","width"],null),Bb=b(["size","height"],null),ja=b(["zoom","enabled"],!1),gc=b(["zoom",
"extent"],null),Rc=b(["zoom","privileged"],!1),Oc=b(["onenter"],function(){}),Pc=b(["onleave"],function(){});if(!("data"in R))throw Error("data is required in config");var Va=b(["data","x"],"x"),Yc=b(["data","x_format"],"%Y-%m-%d"),xc=b(["data","id_converter"],function(a){return a}),Da=b(["data","names"],{}),q=b(["data","groups"],[]),Lb=b(["data","axes"],{}),Y=b(["data","types"],{}),hc=b(["data","regions"],{}),Zc=b(["data","colors"],{}),$=b(["data","selection","enabled"],!1),ka=b(["data","selection",
"extent"],null),Rc=b(["zoom","privileged"],!1),Mc=b(["onenter"],function(){}),Nc=b(["onleave"],function(){});if(!("data"in R))throw Error("data is required in config");var Va=b(["data","x"],"x"),Yc=b(["data","x_format"],"%Y-%m-%d"),xc=b(["data","id_converter"],function(a){return a}),Da=b(["data","names"],{}),q=b(["data","groups"],[]),Lb=b(["data","axes"],{}),Y=b(["data","types"],{}),hc=b(["data","regions"],{}),Zc=b(["data","colors"],{}),$=b(["data","selection","enabled"],!1),ka=b(["data","selection",
"grouped"],!1),la=b(["data","selection","isselectable"],function(a){return!0}),qa=b(["subchart","show"],!1),Db=qa?b(["subchart","size","height"],60):0,$c=b(["color","pattern"],null),sa=b(["legend","show"],!0),La=b(["legend","item","width"],80),Xc=b(["legend","item","onclick"],function(){}),ic=b(["axis","x","type"],"indexed"),gb=b(["axis","x","categories"],[]),pc=b(["axis","x","tick","centered"],!1),Ja=b(["axis","x","default"],null),tc=b(["axis","y","max"],null),rc=b(["axis","y","min"],null),vc=b(["axis",
"y","center"],null),Mc=b(["axis","y","text"],null);b(["axis","y","rescale"],!0);var db=b(["axis","y","inner"],!1),Jc=b(["axis","y","format"],function(a){return a}),Ba=b(["axis","y","padding"],null),Ic=b(["axis","y","ticks"],10),Fb=b(["axis","y2","show"],!1),sc=b(["axis","y2","max"],null),qc=b(["axis","y2","min"],null),uc=b(["axis","y2","center"],null);b(["axis","y2","text"],null);b(["axis","y2","rescale"],!0);var cb=b(["axis","y2","inner"],!1),Lc=b(["axis","y2","format"],function(a){return a}),Ca=
b(["axis","y2","padding"],null),Kc=b(["axis","y2","ticks"],10),e=b(["axis","rotated"],!1),$b=b(["grid","x","show"],!1),Tc=b(["grid","x","type"],"tick"),qb=b(["grid","x","lines"],null),ac=b(["grid","y","show"],!1);b(["grid","y","type"],"tick");var rb=b(["grid","y","lines"],null),sb=b(["point","show"],!0)?b(["point","r"],2.5):0,Nc=b(["point","focus","line","enabled"],!0),bc=b(["point","focus","expand","enabled"],!0),cc=b(["point","focus","expand","r"],bc?4:sb),Ga=b(["point","focus","select","r"],8),
"y","center"],null),Oc=b(["axis","y","text"],null);b(["axis","y","rescale"],!0);var db=b(["axis","y","inner"],!1),Jc=b(["axis","y","format"],function(a){return a}),Ba=b(["axis","y","padding"],null),Ic=b(["axis","y","ticks"],10),Fb=b(["axis","y2","show"],!1),sc=b(["axis","y2","max"],null),qc=b(["axis","y2","min"],null),uc=b(["axis","y2","center"],null);b(["axis","y2","text"],null);b(["axis","y2","rescale"],!0);var cb=b(["axis","y2","inner"],!1),Lc=b(["axis","y2","format"],function(a){return a}),Ca=
b(["axis","y2","padding"],null),Kc=b(["axis","y2","ticks"],10),e=b(["axis","rotated"],!1),$b=b(["grid","x","show"],!1),Tc=b(["grid","x","type"],"tick"),qb=b(["grid","x","lines"],null),ac=b(["grid","y","show"],!1);b(["grid","y","type"],"tick");var rb=b(["grid","y","lines"],null),sb=b(["point","show"],!0)?b(["point","r"],2.5):0,Pc=b(["point","focus","line","enabled"],!0),bc=b(["point","focus","expand","enabled"],!0),cc=b(["point","focus","expand","r"],bc?4:sb),Ga=b(["point","focus","select","r"],8),
Qc=b(["point","onclick"],function(){}),Ec=b(["point","onselected"],function(){}),Fc=b(["point","onunselected"],function(){}),J=b(["regions"],[]),dc=b(["tooltip","contents"],function(a){var c="<table class='-tooltip'><tr><th colspan='2'>"+(D?a[0].x.getFullYear()+"."+(a[0].x.getMonth()+1)+"."+a[0].x.getDate():ha?a[0].x<gb.length?gb[a[0].x]:a[0].x:a[0].x)+"</th></tr>",b,e,f;for(b=0;b<a.length;b++)l(a[b])?(e=l(a[b].value)?(Math.round(100*a[b].value)/100).toFixed(2):"-",f=a[b].name):f=e="-",c+="<tr class='-tooltip-name-"+
a[b].id+"'><td class='name'><span style='background-color:"+Q(a[b].id)+"'></span>"+f+"</td><td class='value'>"+e+"</td></tr>";return c+"</table>"}),Sc=b(["tooltip","init","show"],!1),ta=b(["tooltip","init","x"],0),fc=b(["tooltip","init","position"],{top:"0px",left:"50px"}),pb=ya.replace("#","")+"-clip",Ia="url(#"+pb+")",D="timeseries"===ic,ha="categorized"===ic,ub=null,Za=!1,tb=!1,ea=sa?40:0,ia=d3.time.format(Yc).parse,Q=function(a,c){var b=[],e=null!==c?c:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");
return function(c){if(c in a)return a[c];0<=b.indexOf(c)||b.push(c);return e[b.indexOf(c)%e.length]}}(Zc,$c),oc=function(){var a=[[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()}],

Loading…
Cancel
Save