forked from caged/d3-tip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3.tip.min.js
1 lines (1 loc) · 2.75 KB
/
d3.tip.min.js
1
d3.tip=function(){function tip(vis){svg=get_svg_node(vis),point=svg.createSVGPoint(),document.body.appendChild(node)}function d3_svg_direction(){return"n"}function d3_svg_offset(){return[0,0]}function d3_svg_text(){return" "}function direction_n(){var bbox=get_screen_bbox();return{top:bbox.n.y-node.offsetHeight,left:bbox.n.x-node.offsetWidth/2}}function direction_s(){var bbox=get_screen_bbox();return{top:bbox.s.y,left:bbox.s.x-node.offsetWidth/2}}function direction_e(){var bbox=get_screen_bbox();return{top:bbox.e.y-node.offsetHeight/2,left:bbox.e.x}}function direction_w(){var bbox=get_screen_bbox();return{top:bbox.w.y-node.offsetHeight/2,left:bbox.w.x-node.offsetWidth}}function init_node(){var node=document.createElement("div");return node.style.position="absolute",node.style.display="none",node.style.boxSizing="border-box",node}function get_svg_node(el){if(el=el.node(),"svg"==el.tagName.toLowerCase())return el;for(;el.parentNode;)if(el=el.parentNode,"svg"==el.tagName.toLowerCase())return el;return null}function get_screen_bbox(){var target=d3.event.target,bbox={},matrix=target.getScreenCTM(),tbbox=target.getBBox(),width=tbbox.width,height=tbbox.height,x=tbbox.x,y=tbbox.y;return point.x=x+document.body.scrollLeft,point.y=y+document.body.scrollTop,bbox.nw=point.matrixTransform(matrix),point.x+=width,bbox.ne=point.matrixTransform(matrix),point.y+=height,bbox.se=point.matrixTransform(matrix),point.x-=width,bbox.sw=point.matrixTransform(matrix),point.y-=height/2,bbox.w=point.matrixTransform(matrix),point.x+=width,bbox.e=point.matrixTransform(matrix),point.x-=width/2,point.y-=height/2,bbox.n=point.matrixTransform(matrix),point.y+=height,bbox.s=point.matrixTransform(matrix),bbox}var direction=d3_svg_direction,offset=d3_svg_offset,text=d3_svg_text,node=init_node(),svg=null,point=null;tip.show=function(){var coords,content=text.apply(this,arguments),poffset=offset.apply(this,arguments),dir=direction.apply(this,arguments),dirs=direction_callbacks.keys(),nodel=d3.select(node),i=0;for(nodel.html(content).style("display","block"),i;dirs.length>i;i++)nodel.classed(dirs[i],!1);return coords=direction_callbacks.get(dir).apply(this),nodel.classed(dir,!0).style({top:coords.top+poffset[0]+"px",left:coords.left+poffset[1]+"px"}),tip},tip.hide=function(){return node.style.display="none",node.innerText="",tip},tip.attr=function(n,v){return 2>arguments.length?d3.select(node).attr(n):(d3.select(node).attr(n,v),tip)},tip.direction=function(v){return arguments.length?(direction=null==v?v:d3.functor(v),tip):direction},tip.offset=function(v){return arguments.length?(offset=null==v?v:d3.functor(v),tip):offset},tip.text=function(v){return arguments.length?(text=null==v?v:d3.functor(v),tip):text};var direction_callbacks=d3.map({n:direction_n,s:direction_s,e:direction_e,w:direction_w});return tip};