I needed to use a text-overflow: ellipsis; CSS declaration in Raphael text elements, but couldn’t find an existing cross-browser solution (perhaps my search skills failed me?).
So I created my own Raphael plugin fitText that does exactly what I want. It fits text to a certain width. It’s not perfect, but it works. Here’s a fiddle and a github page.
Now I’m thinking…
- Is my solution an overkill? In other word, do easier ways exist to tackle the problem?
- Is it worth the effort continuing to work on the plugin?
certainly not an overkill, as the
text-overflow: ellipsisis not widely supported yet, and won’t be for non-modern browsers. i’ve encountered this very issue myself, and tackled it with a similar approach.regardless, after looking at the source, several suggestions:
getBBox()text,width) is redundant, as this information can be retrieved from the element itself. the API end-user will probably want to just callfillText()on an element and forget about it.