How do I create nodes with labels that added to these nodes, so I can save and restore them via JSON? I tried to use JSON writer/reader in this way
$(window).load(function () {
var canvas = new draw2d.Canvas("gfx_holder");
// unmarshal the JSON document into the canvas
// (load)
var reader = new draw2d.io.json.Reader();
reader.unmarshal(canvas, jsonDocument);
// display the JSON document in the preview DIV
//
displayJSON(canvas);
// add an event listener to the Canvas for change notifications.
// We just dump the current canvas document into the DIV
//
canvas.getCommandStack().addEventListener(function(e){
if(e.isPostChangeEvent()){
displayJSON(canvas);
}
});
});
function displayJSON(canvas){
var writer = new draw2d.io.json.Writer();
writer.marshal(canvas,function(json){
$("#json").text(JSON.stringify(json, null, 2));
});
}
Its write all nodes that I added to the canvas directly but don't write the child nodes so if I add a label to start node, for example, it will write and draw a start node but without the label inside it how can I solve that?
I found a solution that can make the writer able to write the labels inside nodes in JSON you have to create a custom node and make it inherits from the shape that you want to create it and rather than creat instance of the original node make it from the custom one
here is the node that you have to creat
now these two methods will make the writer includes the child labels in JSON at the end of obj like this