var img;
function writeJson(coll) { // assume COLL is a collection of Parts
var tempDiag = new go.Diagram();
tempDiag.model = myDiagram.model.copy(); // doesn't copy data
myDiagram.copyParts(coll, tempDiag, false);
img = tempDiag.makeSvg({
scale: 1,
background: "#E9E9E9",
maxSize: new go.Size(Infinity, Infinity),
});
return tempDiag.model.toJson();
}
But img returned null. Why is this null? tempDiag.makeImage also returned null.
Do you just want a response, or do you want an answer? Sometimes it takes time to develop an answer.
Also you never indicated whether the solution I gave to your initial question solved that problem. Or even acknowledged that I had provided something for you to use.
Here’s my answer: if you want to render a diagram, the diagram needs to be associated with an HTML Div element:
var img;
function writeJson(coll) { // assume COLL is a collection of Parts
if (!coll) coll = myDiagram.selection;
var tempDiag = new go.Diagram();
var dummyDiv = document.createElement("div");
tempDiag.div = dummyDiv;
tempDiag.model = myDiagram.model.copy(); // doesn't copy data
myDiagram.copyParts(coll, tempDiag, false);
img = tempDiag.makeSvg({
scale: 1,
background: "#E9E9E9",
maxSize: new go.Size(Infinity, Infinity)
});
tempDiag.div = null;
return tempDiag.model.toJson();
}
Sorry, I was super busy with coding so I couldn’t reply properly.
And I tried above but tempDiag rendered node templates and links wrong.
So should we add node templates map and link templates of myDiagram to tempDiagram?
I think coordinate system should match on both of diagram as every node data has “loc” (location) property.
For this, I made divs of 2 diagrams ( myDiagram, tempDiag) as same size, position. But still same error.
And what properties of myDiagram should I copy to tempDiag to fix this issue?
I wanna save selected elements as ‘template’. So that’s why I asked how to save selected elements as json. Now I also want to display diagram overview when I hover over that template on the list.
So I used makeSvg. But on original digram, how can I take screenshot of selected elements only?
Is there a way to temporarily backup model data and remove unselected elements from myDiagram and make image and fetch original model data so myDiagram is totally same as before?