Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word Wrap in Raphael JS / SVG

How do you get words to wrap inside a box in RaphaelJS? Or in browser-based SVG in general?

I found this thread on it, but it doesn't make any sense. They say to use "widthToCharNum" but as far as I can tell, this thread is the only place those words have ever been used on the internet. They suggest using a "width" attribute, but this has no effect.

like image 945
Nick Retallack Avatar asked Apr 30 '12 04:04

Nick Retallack


2 Answers

Text-wrapping is not built into Raphael or the SVG spec. Period. Coming from the HTML world, I found the absence of text wrapping pretty shocking.

However, you can do it yourself without too much difficulty. See this question for details and an example. Unfortunately, you have to burn some client-side cycles to make it work dynamically.

like image 176
peteorpeter Avatar answered Sep 23 '22 23:09

peteorpeter


The svg.js library has a svg.textflow.js plugin. It's not ultra fast but it does the trick. It even stores overflowing text in a data attribute so you can use it to create continuously flowing columns. Here the text flow example page.

like image 43
wout Avatar answered Sep 24 '22 23:09

wout