I’m adding a feature to our app where I use phantomjs to capture a screenshot of our GoJS canvas so users can display a static image on a page. Our nodes use a TextBlock and font icon for the different node types using this code which works just fine:
make('TextBlock',
{
name: 'icon',
alignment: go.Spot.Center,
font: me.iconSize + 'px workpoint',
width: me.iconSize + 2,
height: me.iconSize + 2,
stroke: '#fff'
},
new go.Binding('text', 'iconText'),
new go.Binding('visible', 'iconVisible')
),
Now the users have the option to override our icons by attaching an SVG to the node. When this is done we use a Picture and set the source to the base64 encoded SVG and again GoJS displays it just fine.
make('Picture',
{
name: 'templateIcon',
background: null,
alignment: go.Spot.Center,
width: me.iconSize,
height: me.iconSize,
visible: false
},
new go.Binding('source', 'templateSource'),
new go.Binding('visible', 'templateVisible')
)
The image below shows both of the above methods working just fine in our app.
On to doing the screen capture using phantomjs. We use diagram.makeImageData() to render a PNG or JPEG of the diagram. phantomjs runs our app and captures the output of diagram.makeImageData(). It works just fine for the font icons but doesn’t display the SVG icon.
Doing some searches there are some people having problems with phantomjs not rendering SVG’s and adding a polyfill fixed the problem for some. I applied this polyfill and it didn’t work - maybe because the SVG is in canvas?
After some more playing around I ran phantomjs against the SVG Icons example and it worked!
I was encouraged and starting playing around with Shape and realized it uses Geometry and not a pure SVG. I tried feeding it my base64 SVG but couldn’t get it to work.
So my questions are:
-
Can Shape use an SVG (base64 or not)? These icons are used in other parts of our app so we can’t convert store geometry string in our database that Shape appears to want. Does GoJS have a util to convert SVG to Geometry? I tried go.Geometry.parse() on my base64 SVG and also on window.atob(image) but it didn’t like either one. Since phantomjs renders Shape correctly according to my test I hope there is a way to do it this way.
-
If the above isn’t possibly, are there any other options other than Picture to use SVG icons?