Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG files in Raphael, can they be used?

I have an SVG file that I would like to display via Raphael (each svg file is a node in a tree I'm trying to draw, the actual connections of the tree will be made by raphael). I tried something like:

var vector_image = paper.image("test.svg", 50,50,50,50);

but no dice, seems only "real" image files like png or jpeg are accepted? I find this very strange as Raphael itself uses Scalable Vector Graphics.

Is there anyway (short of parsing the SVG files into javascript snippets and pasting them into the html document) to display existing SVG files using Raphael (or any other vector based javascript graphical engine?)

If parsing it will have to be, is there any easy way to do this, short of just manually scraping the files? I'm running this code on a Ruby on Rails server, so I'd like to avoid solutions outside this framework, if possible (I've heard of one PHP solution through this site...I'd rather code by hand than add another language onto this project).

-Jenny

like image 918
J.R. Avatar asked Jun 28 '10 18:06

J.R.


1 Answers

It's currently not possible to display existing SVG with Raphael, and there are apparently no plans for the implementation of SVG editing (see this forum post). As for alternative JavaScript libraries, a newer alternative is Snap.svg, which can load external SVG files via its Snap.load() function.

like image 167
Daniel Avatar answered Oct 31 '22 23:10

Daniel