DmitryBaranovskiy / rappar

Small SVG to Raphaël parser
82 stars 25 forks source link

keep id's intact #3

Open GeoffreyPlitt opened 12 years ago

GeoffreyPlitt commented 12 years ago

Hi,

My SVG file has elements with ids, like: <ellipse id='george' ...>

And these id's seem to get discarded by vectron. Would it be too hard to keep id's intact?

-G

gbatha commented 11 years ago

I haven't made a pulled request, but I forked @tomasAlabes' updated fork of this library (with newer node version support) and added support for IDs. Raphael ignores these IDs when adding the object, which is probably why it wasn't originally included, but you can store the IDs from the array Rappar outputs by using a simple loop:

var IDs = {};
//rapparOutput is the array generated by rappar
var rapparLen = rapparOutput.length;
while(rapparLen --){
    IDs[rapparOutput[rapparLen].id] = rapparLen;
}
//you can now access the index of the element by its ID using IDs['desiredIDname']
//in the created raphael element, it would look something like el.items[IDs['desiredIDname']]

https://github.com/gbatha/rappar