views:

190

answers:

7

i have a pretty map of the US:

http://upload.wikimedia.org/wikipedia/commons/a/a5/Map_of_USA_with_state_names.svg

i would like to implement a tooltip with multiline functionality such as here over the red square:

http://www.carto.net/papers/svg/gui/tooltips/

please help me get started on this. i will be offering a maximum bounty on this.

+1  A: 

Don't.

The title of the page is handed off to the browser and not rendered in the page; usually that means it shows up in the application's title bar. Actually rendering a newline would make the title bar twice as tall (or more, with multiple newlines) - and that's not going to happen.

Matt Ball
updatedupdatedupdatedupdated
I__
A: 

A line break in html is <br />. You can add that anywhere you like.

FYI - there is no tag named 'field1', so your getElementsByTagName call will find nothing.

Ray
thank you very much, ive updated my question. please let me know if i can clarify anything
I__
You can easily replace commas with <br /> tags using the replace function (as partick dw suggested). But, I am still a little confused. You are using getElementsByTagName to look for 'desc' tags - there are no such tags in valid html, and this search will fail.
Ray
as per recommendation below the question then must be HOW DO I PUT LINE BREAKS IN TOOLTIPS?
I__
A: 

Add a <br/> where you want the break.

epascarello
A: 

Well, this depends on where do you want that Line Break to show...
If it should be seen on the page you should add a <br />, if you need that to show only on the page code, you should add a \n.
if you want to do the thing you've asked you simply need to replace in your code the , in <br /> if this text will be shown in an HTML ToolTip. If this will be shown in a Javascript Alert you should use \n.

Jazzinghen
thank you very much, ive updated my question. please let me know if i can clarify anything
I__
+3  A: 

Why not use some jQuery magic and use the title "Attribute" instead of a Title "Tag"?
I think you're confusing the two in your original question

Check out this jsFiddle

http://jsfiddle.net/s5qUw/2/

I've also used the jQuery Tools Tooltip

Markup note: Basically all YOU need to do is add the title attribute and the addtooltip class to any page element that you want to add a tooltip to. Then you can use CSS to style the tooltip however you see fit.

<path
   id="AK"
   class="addtooltip"
   style="fill:#f2d0ff" 
   onmousemove="GetTrueCoords(evt);"
   title="this sis ak<br>with a line break">
</path>

CSS

.tooltip {
    display:none;
    background-color:black;
    font-size:12px;
    height:40px;
    width:160px;
    padding:25px;
    color:#fff;    
}

Script (bottom of your page)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt; </script>
<script src="http://cdn.jquerytools.org/1.2.4/full/jquery.tools.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
    $(document).ready(function () {
        $(".addtooltip").tooltip();
    }); // closes document.ready
</script>
rockinthesixstring
the bottom line is that you're using the `TITLE` tag all wrong. DONT USE IT THAT WAY. You can however use the `title` attribute on all of your page elements. Take a look at my slightly edited answer.
rockinthesixstring
i really appreciate your time, but i cannot change the entire code to do it your way. can you please suggest to me how i can make slight changes in the way i am doing things to solve my issue?
I__
see my edit above.
rockinthesixstring
and no, I can't suggest (in my own good conscience) a way for you to make slight changes in the way you're doing it. Cus you're doing it all wrong. The `Title` tag is not to be used that way... ever.
rockinthesixstring
thank you very much i will try it right now, what do i have to download and can u tell me what i have to include with jquery to make this work. i have not used jquery before
I__
look at the JSFiddle example in the answer. It's just using the jQuery library and the jQuery Tools library (which I have linked to in the answer as well).
rockinthesixstring
thank you. i have done this but it is not working. where should this line go: $(".addtooltip").tooltip();?
I__
I've edited again.
rockinthesixstring
**1)** you're missing the jquery library `<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>`... **2)** you should put all of your script elements at the **bottom** of the page.
rockinthesixstring
i dont understand what you mean. i am putting all the scripts at the bottom of the index.html page. please check edits
I__
here's an example on how to add javascript to your SVG - http://apike.ca/prog_svg_jsanim.html
rockinthesixstring
I'm done now. I can't help you anymore with your problem.
rockinthesixstring
yes but i have the javascript in index.html file not in svg. should i put the function in the svg file instead?
I__
rockinthesixstring, but i am doing everything you are telling me exactly. please help!
I__
hey man are u still there? could you give me a few more minutes of your time please
I__
@rockinthesixstring: hey mate are you still there ey ?
I__
+1  A: 

Apparently, this is a known problem and you have to handle it like this:

<desc>
   <tspan x="10" y="10">An orange</tspan>
   <tspan x="10" y="24.5">circle</tspan>
</desc>
Steve-O-Rama
i just tried this, but now it is not shownig anything
I__
but i feel like you are definitely on to something
I__
i imagine you have to consider what the proper x/y should be for your application. You could be potentially positioning it off screen or at least somewhere invisible. Mess with the x/y? Not sure if they're relative to the element they are in or to the whole document.
Steve-O-Rama
can you show me the source of where you found this known problem
I__
'tspan' elements need a "text content block element" parent to show anything, see http://www.w3.org/TR/SVGTiny12/intro.html#TermTextContentBlockElement (for SVG 1.1 the only such element is 'text'). Although inside a 'desc' element it's not going to do much anyway, unless the script pulls it out and tries to display it somehow.
Erik Dahlström
@Erik Dahlström: thank you very much for your response. can you tell me what should i do?
I__
If you want to use the script you have above, then you'll need to modify the script to handle multiline, since it doesn't seem to be supported. Or you could switch to another solution. You might be able to find a working solution from http://www.carto.net/papers/svg/gui/tooltips/ which shows multiline svg tooltips.
Erik Dahlström
Here's where i found the original response: http://support.adobe.com/devsup/devsup.nsf/docs/50547.htm
Steve-O-Rama
A: 

You never cease to amaze me, I__! How many projects are you working on?

Tooltips are browser-generated quick popups; you should use \n to set the .title attribute in JavaScript.

palswim
they keep throwing me around. i dont even have education in programming. one day im doing SQL the next day SVG. but i get a lot of whining from soverflow for asking too many questions
I__
the problem is that people here are speaking with me as if i am a well seasoned javascript programmer. I DONT KNOW ANYTHING ABOUT JAVASCRIPT
I__
Well, there's no StackOverflow without people asking questions!
palswim
so my friend can you help me with my problem?
I__
Different browsers handle line breaks inside title attributes differently — some render line breaks, some treat them as generic white space, some displaying the unprintable character character. They should be avoided.
David Dorward