| 1 |
function tooltip(e,callback,on,param) { |
| 2 |
var tt = getE('tooltip'), rect = getE('ttrect'), shadow = getE('ttshdw'), |
| 3 |
offset = {$number:offset}, pos = svgCursorCoords(e), |
| 4 |
x = pos[0] + offset, y = pos[1] + offset, inner, brect, bw, bh, |
| 5 |
sw, sh, de = svgNode(e); |
| 6 |
if(on && !tt) { |
| 7 |
tt = newel('g',{id:'tooltip',visibility:'visible'}); |
| 8 |
rect = newel('rect',{id:'ttrect',stroke:'{$string:stroke}', |
| 9 |
'stroke-width':'{$number:stroke_width}px', |
| 10 |
fill:'{$string:back_colour}'{$string:round_part}, |
| 11 |
width:'10px',height:'10px' |
| 12 |
}); |
| 13 |
{$string:shadow_part} |
| 14 |
tt.appendChild(rect); |
| 15 |
} |
| 16 |
if(tt) { |
| 17 |
if(on) { |
| 18 |
if(tt.parentNode && tt.parentNode != de) |
| 19 |
tt.parentNode.removeChild(tt); |
| 20 |
de.appendChild(tt); |
| 21 |
} |
| 22 |
showhide(tt,on); |
| 23 |
} |
| 24 |
inner = callback(e,tt,on,param); |
| 25 |
if(inner && on) { |
| 26 |
brect = inner.getBBox(); |
| 27 |
bw = Math.ceil(brect.width + {$number:dpad}); |
| 28 |
bh = Math.ceil(brect.height + {$number:dpad}); |
| 29 |
setattr(rect, 'width', bw + 'px'); |
| 30 |
setattr(rect, 'height', bh + 'px'); |
| 31 |
{$string:transform_part} |
| 32 |
if(shadow) { |
| 33 |
setattr(shadow, 'width', (bw + {$number:stroke_width}) + 'px'); |
| 34 |
setattr(shadow, 'height', (bh + {$number:stroke_width}) + 'px'); |
| 35 |
} |
| 36 |
if(bw + x > de.width.baseVal.value - {$number:edge_space}) { |
| 37 |
x -= bw + offset * 2; |
| 38 |
x = Math.max(x, 0); |
| 39 |
} |
| 40 |
if(bh + y > de.height.baseVal.value - {$number:edge_space}) { |
| 41 |
y -= bh + offset * 2; |
| 42 |
y = Math.max(y, 0); |
| 43 |
} |
| 44 |
} |
| 45 |
on && setattr(tt,'transform','translate('+x+' '+y+')'); |
| 46 |
tooltipOn = on ? 1 : 0; |
| 47 |
} |
| 48 |
|