We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm back to Processing after some time, now playing with p5.js to write a Sankey library. After fiddling with the diagram (I can drag around the nodes to read better the graph) I would like to export the image to SVG.
Giving a look around I am very confused about this "save as SVG". In Processing (Java) I was used to insert beginRecord()...endRecord() and it was done. With p5.js it doesn't look this is possible.
I found some libraries in github (i.e. zenozeng/p5.js-svg v0.6.0), an old stackoverflow discussion (https://stackoverflow.com/questions/35681381/p5js-svg-export), an old issue (https://github.com/processing/p5.js/issues/458), lot of examples that I cannot make it work at all.
Is there somewhere an example I can use as a base? Which library (if any) is the most promising? My knowledge of JS if alas very limited and it is well above my skills to go deep into this issue...
Thanks in advance
Comments
I also found this blog that refers to p5.svg.js: https://makeyourownalgorithmicart.blogspot.de/2018/03/creating-svg-with-p5js.html?showComment=1525354208596#c4312630150660284850
For the ones interested, this is the solution I found. It is suboptimal but enough for my use. Pay attention: if you load fonts, they will be transformed in geometry inside the SVG. This means that the SVG is huge and slow to load and visualize. Standard text font works perfectly.
I create two canvases: one normal, the second is SVG (using Zeno Zeng p5.svg.js at https://github.com/zenozeng/p5.js-svg/tree/master/dist)
SVG lives in a hidden div. When I am happy after playing with the normal canvas, I create the SVG using the latest parameters: of course they need to be global to be shared among the two objects.