Browse Source

Hide tooltip when no data on the point

pull/34/merge
Masayuki Tanaka 11 years ago
parent
commit
999ac468dd
  1. 2
      c3.js
  2. 20
      c3.min.js

2
c3.js

@ -875,6 +875,8 @@
function showTooltip(selectedData, mouse) {
var tWidth, tHeight;
var svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight;
// don't show tooltip when no data
if (selectedData.filter(function (d) { return d.value; }).length === 0) { return; }
// Construct tooltip
tooltip.html(__tooltip_contents(selectedData))
.style("visibility", "hidden")

20
c3.min.js vendored

@ -19,16 +19,16 @@ values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}}function
rb(),c;for(c=0;c<b.length;c++)if(b[c]===a)return!0;return!1}function nb(a){return r(a)?g.data.targets.filter(a):g.data.targets}function qc(a){var b={};a.forEach(function(a){b[a.id]=[];a.values.forEach(function(e){b[a.id].push(e.value)})});return b}function zc(a,b){var c=Object.keys(a),e,k,d;for(e=0;e<c.length;e++)for(d=a[c[e]].values,k=0;k<d.length;k++)if(b(d[k].value))return!0;return!1}function rc(a){return zc(a,function(a){return 0>a})}function vd(a){return zc(a,function(a){return 0<a})}function sd(a){return a<
Fa.length?Fa[a]:a}function La(a){return"-shapes -shapes-"+a.id}function Ac(a){return La(a)+" -line -line-"+a.id}function Ld(a){return La(a)+" -circles -circles-"+a.id}function Bc(a){return La(a)+" -bars -bars-"+a.id}function Md(a){return La(a.data)+" -arc -arc-"+a.data.id}function Nd(a){return La(a)+" -area -area-"+a.id}function Od(a,b){return"-shape -shape-"+b+" -circle -circle-"+b}function Cc(a,b){return"-shape -shape-"+b+" -bar -bar-"+b}function Pd(a,b){return"region region-"+b+" "+("classes"in
a?[].concat(a.classes).join(" "):"")}function Dc(a,b){return"event-rect event-rect-"+b}function Qd(a){return a.value?Ec(a)?0.5:1:0}function va(a){return m(a.x)}function Ma(a){return m(B?na(a.value):a.value)}function Na(a){return z(a.value)}function Fc(a,b){var c,e=a[b].x,k=[];for(c=b-1;0<=c&&e===a[c].x;c--)k.push(a[c]);for(c=b;c<a.length&&e===a[c].x;c++)k.push(a[c]);return k}function Gc(a,b,c,e){c=c?c:0;e=e?e:a.length-1;var k=Math.floor((e-c)/2)+c;0<m(a[k].x)-b[0]?e=k:c=k;return 1===e-c?(k=[],a[c].x&&
(k=k.concat(Fc(a,c))),a[e].x&&(k=k.concat(Fc(a,e))),Hc(k,b)):Gc(a,b,c,e)}function Ic(a,b){var c;c=a.map(function(a){return Gc(a.values,b)});return Hc(c,b)}function Hc(a,b){var c,e;a.forEach(function(a){var d=Hb(a,b);if(d<c||!c)c=d,e=a});return e}function Jc(a,b){var c,e,k,d,f;W.html(Kc(a)).style("visibility","hidden").style("display","block");c=W.property("offsetWidth");e=W.property("offsetHeight");h?d=b[0]:(k=n.property("offsetLeft"),d=k+(cb?cb:db?1:40)+m(a[0].x)+20,f=d+c,k=k+(null===Za?ba():Za)-
($a?$a:Ab?ab||h?1:40:20),f>k&&(d-=c+30));c=b[1]+15+e<X()?b[1]+15:b[1]-e;W.style("top",c+"px").style("left",d+"px").style("visibility","visible")}function Lc(a){Ia(g.data.targets,"scatter")||C(g.data.targets)||l.selectAll("line.xgrid-focus").style("visibility","visible").data([a]).attr(h?"y1":"x1",va).attr(h?"y2":"x2",va)}function Mc(){l.select("line.xgrid-focus").style("visibility","hidden")}function wa(a){return a.x||0===a.x?m(a.x):null}function xa(a){return w(a.id)(a.value)}function Rd(){var a=
{},b=0,c,e;nb(sb).forEach(function(k){for(c=0;c<t.length;c++)if(!(0>t[c].indexOf(k.id)))for(e=0;e<t[c].length;e++)if(t[c][e]in a){a[k.id]=a[t[c][e]];break}x(a[k.id])&&(a[k.id]=b++)});a.__max__=b-1;return a}function Sd(a,b,c,e){var k=e?U:m;return b?function(e){var d=e.id in c?c[e.id]:0;return e.x||0===e.x?k(e.x)-a*(b/2-d):0}:function(){return 0}}function Td(a){return function(b){return(a?H(b.id):w(b.id))(b.value)}}function Ud(a,b){var c=Object.keys(a);return function(e,k){var d=b?H(e.id):w(e.id),f=
d(0),g=f;nb(sb).forEach(function(b){b.id!==e.id&&a[b.id]===a[e.id]&&c.indexOf(b.id)<c.indexOf(e.id)&&0<b.values[k].value*e.value&&(g+=d(b.values[k].value)-f)});return g}}function Oa(a,b){var c=x(a)?rb():a;"string"===typeof c&&(c=[c]);for(var e=0;e<c.length;e++)E[c[e]]=b}function Ia(a,b){var c=!1;a.forEach(function(a){E[a.id]===b&&(c=!0);a.id in E||"line"!==b||(c=!0)});return c}function C(a){return Ia(a,"pie")}function Ib(a){a="string"===typeof a?a:a.id;return!(a in E)||"line"===E[a]||"spline"===E[a]||
"area"===E[a]||"area-spline"===E[a]}function Nc(a){a="string"===typeof a?a:a.id;return"spline"===E[a]||"area-spline"===E[a]}function sb(a){return"bar"===E["string"===typeof a?a:a.id]}function Ec(a){return"scatter"===E["string"===typeof a?a:a.id]}function Oc(a){return"pie"===E["string"===typeof a?a:a.id]}function Pc(a){return sb(a)?a.values:[]}function Vd(a){return Ib(a)||Ec(a)?a.values:[]}function na(a){var b;if(!a)throw Error(a+" can not be parsed as d3.time with format "+Jb+". Maybe 'x' of this data is not defined. See data.x or data.xs option.");
b=d.time.format(Jb).parse(a);if(!b)throw Error("Failed to parse '"+a+"' with format "+Jb);return b}function Qc(a,b){var c=d.mouse(a),e=d.select(a),k=1*e.attr("cx"),e=1*e.attr("cy");return Math.sqrt(Math.pow(k-c[0],2)+Math.pow(e-c[1],2))<b}function Rc(a){var b=d.mouse(a),c=d.select(a);a=1*c.attr("x");var e=1*c.attr("y"),c=1*c.attr("width");return a-10<b[0]&&b[0]<a+c+10&&e-10<b[1]}function Wd(a,b){var c;for(c=0;c<b.length;c++)if(b[c].start<a&&a<=b[c].end)return!0;return!1}function Gd(a,b){var c=!1;
Object.keys(a).forEach(function(e){a[e]===b&&(c=!0)});return c}function Hb(a,b){return Math.pow(m(a.x)-b[0],2)+Math.pow(z(a.value)-b[1],2)}function Sc(a,b,c){Xd(a,b);l.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+c).data([b]).enter().append("circle").attr("class",function(){return"selected-circle selected-circle-"+c}).attr("cx",h?xa:wa).attr("cy",h?wa:xa).attr("stroke",function(){return L(b.id)}).attr("r",1.4*Pa).transition().duration(100).attr("r",Pa)}function Kb(a,b,c){Yd(a,b);
l.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+c).transition().duration(100).attr("r",0).remove()}function Tc(a,b,c,e){a?Sc(b,c,e):Kb(b,c,e)}function Zd(){}function Uc(){}function Vc(a,b,c,e){}function Lb(a){return a.filter(function(a){return null!==a.value})}function Mb(a,b){return(b?l.selectAll(".-circles-"+b):l).selectAll(".-circle"+(a||0===a?"-"+a:""))}function Nb(a){Mb(a).filter(function(){return d.select(this).classed($)}).classed($,!1).attr("r",Ob)}function Wc(a){return l.selectAll(".-bar"+
(a||0===a?"-"+a:""))}function $d(a,b,c,e){var d,f,g="M",l,m,ya,p,q,n=[];if(r(e))for(d=0;d<e.length;d++)n[d]={},x(e[d].start)?n[d].start=a[0].x:n[d].start=B?na(e[d].start):e[d].start,x(e[d].end)?n[d].end=a[a.length-1].x:n[d].end=B?na(e[d].end):e[d].end;p=h?function(a){return c(a.value)}:function(a){return b(a.x)};q=h?function(a){return b(a.x)}:function(a){return c(a.value)};e=B?function(a,e,d,k){var f=a.x.getTime();a=e.x-a.x;e=new Date(f+a*(d+k));return"M"+b(new Date(f+a*d))+" "+c(m(d))+" "+b(e)+" "+
c(m(d+k))}:function(a,e,d,k){return"M"+b(l(d))+" "+c(m(d))+" "+b(l(d+k))+" "+c(m(d+k))};for(d=0;d<a.length;d++)if(x(n)||!Wd(a[d].x,n))g+=" "+p(a[d])+" "+q(a[d]);else{l=S(a[d-1].x,a[d].x);m=T(a[d-1].value,a[d].value);f=b(a[d].x)-b(a[d-1].x);ya=c(a[d].value)-c(a[d-1].value);f=Math.sqrt(Math.pow(f,2)+Math.pow(ya,2));ya=2/f;var s=2*ya;for(f=ya;1>=f;f+=s)g+=e(a[d-1],a[d],f,ya)}return g}function Pb(a){var b;tb=d.select(ua);if(tb.empty())P.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');
(k=k.concat(Fc(a,c))),a[e].x&&(k=k.concat(Fc(a,e))),Hc(k,b)):Gc(a,b,c,e)}function Ic(a,b){var c;c=a.map(function(a){return Gc(a.values,b)});return Hc(c,b)}function Hc(a,b){var c,e;a.forEach(function(a){var d=Hb(a,b);if(d<c||!c)c=d,e=a});return e}function Jc(a,b){var c,e,k,d,f;0!==a.filter(function(a){return a.value}).length&&(W.html(Kc(a)).style("visibility","hidden").style("display","block"),c=W.property("offsetWidth"),e=W.property("offsetHeight"),h?d=b[0]:(k=n.property("offsetLeft"),d=k+(cb?cb:
db?1:40)+m(a[0].x)+20,f=d+c,k=k+(null===Za?ba():Za)-($a?$a:Ab?ab||h?1:40:20),f>k&&(d-=c+30)),c=b[1]+15+e<X()?b[1]+15:b[1]-e,W.style("top",c+"px").style("left",d+"px").style("visibility","visible"))}function Lc(a){Ia(g.data.targets,"scatter")||C(g.data.targets)||l.selectAll("line.xgrid-focus").style("visibility","visible").data([a]).attr(h?"y1":"x1",va).attr(h?"y2":"x2",va)}function Mc(){l.select("line.xgrid-focus").style("visibility","hidden")}function wa(a){return a.x||0===a.x?m(a.x):null}function xa(a){return w(a.id)(a.value)}
function Rd(){var a={},b=0,c,e;nb(sb).forEach(function(k){for(c=0;c<t.length;c++)if(!(0>t[c].indexOf(k.id)))for(e=0;e<t[c].length;e++)if(t[c][e]in a){a[k.id]=a[t[c][e]];break}x(a[k.id])&&(a[k.id]=b++)});a.__max__=b-1;return a}function Sd(a,b,c,e){var k=e?U:m;return b?function(e){var d=e.id in c?c[e.id]:0;return e.x||0===e.x?k(e.x)-a*(b/2-d):0}:function(){return 0}}function Td(a){return function(b){return(a?H(b.id):w(b.id))(b.value)}}function Ud(a,b){var c=Object.keys(a);return function(e,k){var d=
b?H(e.id):w(e.id),f=d(0),g=f;nb(sb).forEach(function(b){b.id!==e.id&&a[b.id]===a[e.id]&&c.indexOf(b.id)<c.indexOf(e.id)&&0<b.values[k].value*e.value&&(g+=d(b.values[k].value)-f)});return g}}function Oa(a,b){var c=x(a)?rb():a;"string"===typeof c&&(c=[c]);for(var e=0;e<c.length;e++)E[c[e]]=b}function Ia(a,b){var c=!1;a.forEach(function(a){E[a.id]===b&&(c=!0);a.id in E||"line"!==b||(c=!0)});return c}function C(a){return Ia(a,"pie")}function Ib(a){a="string"===typeof a?a:a.id;return!(a in E)||"line"===
E[a]||"spline"===E[a]||"area"===E[a]||"area-spline"===E[a]}function Nc(a){a="string"===typeof a?a:a.id;return"spline"===E[a]||"area-spline"===E[a]}function sb(a){return"bar"===E["string"===typeof a?a:a.id]}function Ec(a){return"scatter"===E["string"===typeof a?a:a.id]}function Oc(a){return"pie"===E["string"===typeof a?a:a.id]}function Pc(a){return sb(a)?a.values:[]}function Vd(a){return Ib(a)||Ec(a)?a.values:[]}function na(a){var b;if(!a)throw Error(a+" can not be parsed as d3.time with format "+
Jb+". Maybe 'x' of this data is not defined. See data.x or data.xs option.");b=d.time.format(Jb).parse(a);if(!b)throw Error("Failed to parse '"+a+"' with format "+Jb);return b}function Qc(a,b){var c=d.mouse(a),e=d.select(a),k=1*e.attr("cx"),e=1*e.attr("cy");return Math.sqrt(Math.pow(k-c[0],2)+Math.pow(e-c[1],2))<b}function Rc(a){var b=d.mouse(a),c=d.select(a);a=1*c.attr("x");var e=1*c.attr("y"),c=1*c.attr("width");return a-10<b[0]&&b[0]<a+c+10&&e-10<b[1]}function Wd(a,b){var c;for(c=0;c<b.length;c++)if(b[c].start<
a&&a<=b[c].end)return!0;return!1}function Gd(a,b){var c=!1;Object.keys(a).forEach(function(e){a[e]===b&&(c=!0)});return c}function Hb(a,b){return Math.pow(m(a.x)-b[0],2)+Math.pow(z(a.value)-b[1],2)}function Sc(a,b,c){Xd(a,b);l.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+c).data([b]).enter().append("circle").attr("class",function(){return"selected-circle selected-circle-"+c}).attr("cx",h?xa:wa).attr("cy",h?wa:xa).attr("stroke",function(){return L(b.id)}).attr("r",1.4*Pa).transition().duration(100).attr("r",
Pa)}function Kb(a,b,c){Yd(a,b);l.select(".selected-circles-"+b.id).selectAll(".selected-circle-"+c).transition().duration(100).attr("r",0).remove()}function Tc(a,b,c,e){a?Sc(b,c,e):Kb(b,c,e)}function Zd(){}function Uc(){}function Vc(a,b,c,e){}function Lb(a){return a.filter(function(a){return null!==a.value})}function Mb(a,b){return(b?l.selectAll(".-circles-"+b):l).selectAll(".-circle"+(a||0===a?"-"+a:""))}function Nb(a){Mb(a).filter(function(){return d.select(this).classed($)}).classed($,!1).attr("r",
Ob)}function Wc(a){return l.selectAll(".-bar"+(a||0===a?"-"+a:""))}function $d(a,b,c,e){var d,f,g="M",l,m,ya,p,q,n=[];if(r(e))for(d=0;d<e.length;d++)n[d]={},x(e[d].start)?n[d].start=a[0].x:n[d].start=B?na(e[d].start):e[d].start,x(e[d].end)?n[d].end=a[a.length-1].x:n[d].end=B?na(e[d].end):e[d].end;p=h?function(a){return c(a.value)}:function(a){return b(a.x)};q=h?function(a){return b(a.x)}:function(a){return c(a.value)};e=B?function(a,e,d,k){var f=a.x.getTime();a=e.x-a.x;e=new Date(f+a*(d+k));return"M"+
b(new Date(f+a*d))+" "+c(m(d))+" "+b(e)+" "+c(m(d+k))}:function(a,e,d,k){return"M"+b(l(d))+" "+c(m(d))+" "+b(l(d+k))+" "+c(m(d+k))};for(d=0;d<a.length;d++)if(x(n)||!Wd(a[d].x,n))g+=" "+p(a[d])+" "+q(a[d]);else{l=S(a[d-1].x,a[d].x);m=T(a[d-1].value,a[d].value);f=b(a[d].x)-b(a[d-1].x);ya=c(a[d].value)-c(a[d-1].value);f=Math.sqrt(Math.pow(f,2)+Math.pow(ya,2));ya=2/f;var s=2*ya;for(f=ya;1>=f;f+=s)g+=e(a[d-1],a[d],f,ya)}return g}function Pb(a){var b;tb=d.select(ua);if(tb.empty())P.alert('No bind element found. Check the selector specified by "bindto" and existance of that element. Default "bindto" is "#chart".');
else{tb.html("");g.data.x={};g.data.targets=Ka(a);ra();R();m.domain(d.extent(ob(g.data.targets)));z.domain(mb("y"));Y.domain(mb("y2"));U.domain(m.domain());hb.domain(z.domain());ib.domain(Y.domain());J.ticks(10>a.length?a.length:10);ma.ticks(ae).outerTickSize(0).tickFormat(be);jb.ticks(ce).outerTickSize(0).tickFormat(de);V=m.domain();K.x(U);pa&&F.x(m);n=d.select(ua).append("svg").attr("width",q+I+da).attr("height",s+u+O).on("mouseenter",ee).on("mouseleave",fe);ub=n.append("defs");ub.append("clipPath").attr("id",
Qb).append("rect").attr("y",u).attr("width",q).attr("height",s-u);ub.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1-I).attr("y",-20).attr("width",N).attr("height",ca);ub.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-I+1).attr("y",u-1).attr("width",ia).attr("height",yb);l=n.append("g").attr("transform",M.main);A=za?n.append("g").attr("transform",M.context):null;Aa=Ba?n.append("g").attr("transform",M.legend):null;W=d.select(ua).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",M.x).call(h?ma:J).append("text").attr("class","-axis-x-label").attr("x",q).attr("dy","-.5em").style("text-anchor","end").text(ge);l.append("g").attr("class","y axis").attr("clip-path",h?"url(#yaxis-clip)":"").call(h?J:ma).append("text").attr("transform","rotate(-90)").attr("dy","1.2em").attr("dx","-.5em").style("text-anchor","end").text(he);Ab&&

Loading…
Cancel
Save