Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canvas toSVG not saving ids #2697

Closed
suomilapsi opened this issue Dec 20, 2015 · 6 comments · Fixed by #2993
Closed

canvas toSVG not saving ids #2697

suomilapsi opened this issue Dec 20, 2015 · 6 comments · Fixed by #2993
Assignees
Milestone

Comments

@suomilapsi
Copy link

Hello,

It is possible to load SVG with IDs to canvas. With toJSON it is possible to save IDs. With toSVG there seems to be no way to retain IDs?

https://jsfiddle.net/suomilapsi/r9q8anky/1/

Best regads,
suomilapsi

@suomilapsi
Copy link
Author

@asturur
Copy link
Member

asturur commented Dec 20, 2015

Yes, we do not export id to svg elements.

@dumaron
Copy link

dumaron commented Jan 7, 2016

Hi,
I had a similar problem and I've resolved modifying a bit fabric, maybe it can be useful to you too. It's old code, so maybe I'm forgetting something.

Basically I changed this code (in last version on line 7106):

markup.push(instance.toSVG(reviver));

wtih this:

markup.push(instance.toSVG(function(path) {
    return reviver(path, instance);
}));

By doing this, you're giving to the reviver function the object from where the single piece of the SVG is generated, so you can read from it the id (and every personalized attribute) and update the SVG element (the first argumento of reviver, path in my example) accordingly.

@asturur
Copy link
Member

asturur commented Jan 7, 2016

i do not know if adding option of having a callback and let user add pieces to svg is worth over just exporting the id for everything.
The only bad thing is going around all classes and adding

if (this.id && this.id !== '') {
  markup.push(' id="',  this.id, '"');
}

@dumaron
Copy link

dumaron commented Jan 7, 2016

You're right. It was more a temporary solution for @suomilapsi , although I think this is a simple and straight forward way to give user more power over the SVG generation.

@asturur
Copy link
Member

asturur commented Jan 7, 2016

Yes true. But at same time i prefer to listen issues of people with svgs, because i would catch potential good features that could be lost with a "solve it by yourself" approach.

@asturur asturur self-assigned this Jan 7, 2016
@asturur asturur added this to the 1.6.3 milestone May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants