Our node templates have a core set of icons which are created using Geometry.parse() and put into a Shape. We also allow our customers to customize the icons using SVG’s which are stored in our database. With GoJS 1.x we handled the custom icons using a Picture instead of a Shape which added more to our templates.
With GoJS 2 is there a way to convert a SVG to a Geometry so we can use Shape for both our canned icons and customer’s custom SVG icons?
That depends on the SVG. Usually the SVG is complicated enough that a single Shape cannot render the whole SVG. That will be clearly true if there are multiple colors or if there is text.
We tell our customers that icons have to be single color and most will use SVGs from IcoMoon or Google Material Design. For example can this icon be converted to Geometry, and if so, how?
Not easily. Basically that would require parsing and translating arbitrary SVG code. But if you have simple path elements, as you can see above, it’s pretty trivial.
See also SVG Tiger Drawing in GoJS, which happens to work for that sample. But it translates the SVG into multiple Shapes in a single Panel.
Thanks Walter. I knew in 1.x it wasn’t easy and didn’t know if GoJS added anything in 2.x for converting SVG to Geometry. I’ll stick with using a Picture which I just got working.