10 var direction = d3_tip_direction,
11 offset = d3_tip_offset,
20 point = svg.createSVGPoint()
21 document.body.appendChild(node)
27 tip.show = function() {
28 var args = Array.prototype.slice.call(arguments)
29 if(args[args.length - 1] instanceof SVGElement) target = args.pop()
31 var content = html.apply(
this, args),
32 poffset = offset.apply(
this, args),
33 dir = direction.apply(
this, args),
34 nodel = d3.select(node), i = 0,
38 .style({ opacity: 1,
'pointer-events':
'all' })
40 while(i--) nodel.classed(directions[i],
false)
41 coords = direction_callbacks.get(dir).apply(
this)
42 nodel.classed(dir,
true).style({
43 top: (coords.top + poffset[0]) +
'px',
44 left: (coords.left + poffset[1]) +
'px'
53 tip.hide =
function() {
54 nodel = d3.select(node)
55 nodel.style({ opacity: 0,
'pointer-events':
'none' })
65 tip.attr =
function(n, v) {
66 if (arguments.length < 2 && typeof n ===
'string') {
67 return d3.select(node).attr(n)
69 var args = Array.prototype.slice.call(arguments)
70 d3.selection.prototype.attr.apply(d3.select(node), args)
82 tip.style =
function(n, v) {
83 if (arguments.length < 2 && typeof n ===
'string') {
84 return d3.select(node).style(n)
86 var args = Array.prototype.slice.call(arguments)
87 d3.selection.prototype.style.apply(d3.select(node), args)
99 tip.direction =
function(v) {
100 if (!arguments.length)
return direction
101 direction = v == null ? v : d3.functor(v)
111 tip.offset =
function(v) {
112 if (!arguments.length)
return offset
113 offset = v == null ? v : d3.functor(v)
123 tip.html =
function(v) {
124 if (!arguments.length)
return html
125 html = v == null ? v : d3.functor(v)
130 function d3_tip_direction() {
return 'n' }
131 function d3_tip_offset() {
return [0, 0] }
132 function d3_tip_html() {
return ' ' }
134 var direction_callbacks = d3.map({
145 directions = direction_callbacks.keys()
147 function direction_n() {
148 var bbox = getScreenBBox()
150 top: bbox.n.y - node.offsetHeight,
151 left: bbox.n.x - node.offsetWidth / 2
155 function direction_s() {
156 var bbox = getScreenBBox()
159 left: bbox.s.x - node.offsetWidth / 2
163 function direction_e() {
164 var bbox = getScreenBBox()
166 top: bbox.e.y - node.offsetHeight / 2,
171 function direction_w() {
172 var bbox = getScreenBBox()
174 top: bbox.w.y - node.offsetHeight / 2,
175 left: bbox.w.x - node.offsetWidth
179 function direction_nw() {
180 var bbox = getScreenBBox()
182 top: bbox.nw.y - node.offsetHeight,
183 left: bbox.nw.x - node.offsetWidth
187 function direction_ne() {
188 var bbox = getScreenBBox()
190 top: bbox.ne.y - node.offsetHeight,
195 function direction_sw() {
196 var bbox = getScreenBBox()
199 left: bbox.sw.x - node.offsetWidth
203 function direction_se() {
204 var bbox = getScreenBBox()
211 function initNode() {
212 var node = d3.select(document.createElement(
'div'))
214 position:
'absolute',
216 pointerEvents:
'none',
217 boxSizing:
'border-box'
223 function getSVGNode(el) {
225 if(el.tagName.toLowerCase() ==
'svg')
228 return el.ownerSVGElement
244 function getScreenBBox() {
245 var targetel = target || d3.event.target,
247 matrix = targetel.getScreenCTM(),
248 tbbox = targetel.getBBox(),
250 height = tbbox.height,
253 scrollTop = document.documentElement.scrollTop || document.body.scrollTop,
254 scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft
257 point.x = x + scrollLeft
258 point.y = y + scrollTop
259 bbox.nw = point.matrixTransform(matrix)
261 bbox.ne = point.matrixTransform(matrix)
263 bbox.se = point.matrixTransform(matrix)
265 bbox.sw = point.matrixTransform(matrix)
266 point.y -= height / 2
267 bbox.w = point.matrixTransform(matrix)
269 bbox.e = point.matrixTransform(matrix)
271 point.y -= height / 2
272 bbox.n = point.matrixTransform(matrix)
274 bbox.s = point.matrixTransform(matrix)