XML Elves

XML Elves

<community>of XML and SVG Developers</community>


tool tips

This is a discussion on tool tips within the SVG Questions forums, part of the SVG Forums category; Hi does anyone know how to implement tooltips for each element in svg? Possibly using java script...


Go Back   XML Elves > SVG Forums > SVG Questions

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices


Click here to register

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-17-2005, 10:40 PM
joe
Guest
 
Posts: n/a
Default tool tips

Hi does anyone know how to implement tooltips for each element in svg? Possibly using java script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-18-2005, 01:55 AM
flo
Guest
 
Posts: n/a
Default tool tips

Nothing already exists in SVG spec like "alt" in HTML, so i have implemented something like this but it must be optimized to be more global (position...etc.) :

function GetTrueCoords(evt) {

newScale = SVGRoot.currentScale;
translation = SVGRoot.currentTranslate;
TrueCoords.x = (evt.clientX - translation.x)/newScale;
TrueCoords.y = (evt.clientY - translation.y)/newScale;

}


function ShowTooltip(evt, turnOn, text) {
try {
if (!evt || !turnOn) {

var node = SVGDocument.getElementById('tooltip')
var nodeText = SVGDocument.getElementById('tooltipText')
SVGRoot.removeChild(node)
SVGRoot.removeChild(nodeText)

} else {
GetTrueCoords(evt);
var xRectPos = TrueCoords.x - 50;
var yRectPos = TrueCoords.y - 35;
var xTextPos = xRectPos + 8;
var yTextPos = yRectPos + 15;

// Create rect node
var myRect = evt.target.ownerDocument.createElementNS(null,"rec t");
myRect.setAttributeNS(null,"id","tooltip");
myRect.setAttributeNS(null,"x",xRectPos);
myRect.setAttributeNS(null,"y",yRectPos);
myRect.setAttributeNS(null,"rx","3");
myRect.setAttributeNS(null,"ry","3");
myRect.setAttributeNS(null,"fill-opacity", "0.7");
myRect.setAttributeNS(null,"width",text.length*8);
myRect.setAttributeNS(null,"height","20");
myRect.setAttributeNS(null,"fill","white");
myRect.setAttributeNS(null,"stroke","blue");
SVGRoot.appendChild(myRect);

// Create text node to insert
var textNode = evt.target.ownerDocument.createElementNS(null,"tex t");
textNode.setAttributeNS(null,"id","tooltipText");
textNode.setAttributeNS(null,"x",xTextPos);
textNode.setAttributeNS(null,"y",yTextPos);
textNode.setAttributeNS(null,"style","fill:blue;fo nt-size:13;text-anchor:start;");
textNode.appendChild(evt.target.ownerDocument.crea teTextNode(text));

SVGRoot.appendChild(textNode);
}

} catch(er){}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-18-2005, 02:54 AM
joe
Guest
 
Posts: n/a
Default java script and svg tool tip

okay now how would i call those functions inside the svg from an external java script that has been written?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-18-2005, 02:58 AM
joe
Guest
 
Posts: n/a
Default java script and svg tool tip

How do i use this code in svg now so users can move the mouse on an svg element and have a tool tip? This javascript must be used extenally though in an extenal js file rather then inbedded in the svg file





function GetTrueCoords(evt) {

newScale = SVGRoot.currentScale;
translation = SVGRoot.currentTranslate;
TrueCoords.x = (evt.clientX - translation.x)/newScale;
TrueCoords.y = (evt.clientY - translation.y)/newScale;

}


function ShowTooltip(evt, turnOn, text) {
try {
if (!evt || !turnOn) {

var node = SVGDocument.getElementById('tooltip')
var nodeText = SVGDocument.getElementById('tooltipText')
SVGRoot.removeChild(node)
SVGRoot.removeChild(nodeText)

} else {
GetTrueCoords(evt);
var xRectPos = TrueCoords.x - 50;
var yRectPos = TrueCoords.y - 35;
var xTextPos = xRectPos + 8;
var yTextPos = yRectPos + 15;

// Create rect node
var myRect = evt.target.ownerDocument.createElementNS(null,"rec t");
myRect.setAttributeNS(null,"id","tooltip");
myRect.setAttributeNS(null,"x",xRectPos);
myRect.setAttributeNS(null,"y",yRectPos);
myRect.setAttributeNS(null,"rx","3");
myRect.setAttributeNS(null,"ry","3");
myRect.setAttributeNS(null,"fill-opacity", "0.7");
myRect.setAttributeNS(null,"width",text.length*8);
myRect.setAttributeNS(null,"height","20");
myRect.setAttributeNS(null,"fill","white");
myRect.setAttributeNS(null,"stroke","blue");
SVGRoot.appendChild(myRect);

// Create text node to insert
var textNode = evt.target.ownerDocument.createElementNS(null,"tex t");
textNode.setAttributeNS(null,"id","tooltipText");
textNode.setAttributeNS(null,"x",xTextPos);
textNode.setAttributeNS(null,"y",yTextPos);
textNode.setAttributeNS(null,"style","fill:blue;fo nt-size:13;text-anchor:start;");
textNode.appendChild(evt.target.ownerDocument.crea teTextNode(text));

SVGRoot.appendChild(textNode);
}

} catch(er){}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
tips, tool


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -6. The time now is 09:36 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0

Inkjet Printer Inks
Buy inkjet printer inks online and save.

Hard Disk Drive Data Recovery Lancashire
Best service on hard disk data recovery. Contact the professionals.

ink cartridges Free UK Delivery on ink cartridges such as Canon, Dell, Epson, hp & Lexmark.

1 2 3 4 5 6 7 8 9 10