react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

On deserialization of diagram, labels are not getting rendered

Open ganesh-sankey opened this issue 8 years ago • 3 comments

In demo serializing example, I added label to link and serialized the model. on that serialized model, performed the deserialization and passed it to engine for rendering. The result was that all the nodes and links got deserialized and rendered properly expect for label.

Here is code from demo serializing example:

import { DiagramEngine, DiagramModel, DefaultNodeModel, LinkModel, DiagramWidget, DefaultLinkModel } from "storm-react-diagrams";
import * as React from "react";
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
import { action } from "@storybook/addon-actions";
import * as beautify from "json-beautify";

export default () => {
	//1) setup the diagram engine
	var engine = new DiagramEngine();
	engine.installDefaultFactories();

	//2) setup the diagram model
	var model = new DiagramModel();

	//3-A) create a default node
	var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
	let port1 = node1.addOutPort("Out");
	node1.setPosition(100, 100);

	//3-B) create another default node
	var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
	let port2 = node2.addInPort("In");
	node2.setPosition(400, 100);

	// link the ports
	let link1 = port1.link(port2);
	(link1 as DefaultLinkModel).addLabel("Hello World!");

	//4) add the models to the root graph
	model.addAll(node1, node2, link1);

	//!------------- SERIALIZING ------------------

	var str = JSON.stringify(model.serializeDiagram());

	//!------------- DESERIALIZING ----------------

	var model2 = new DiagramModel();
	model2.deSerializeDiagram(JSON.parse(str), engine);
	engine.setDiagramModel(model2);

	return (
		<DemoWorkspaceWidget
			buttons={
				<button
					onClick={() => {
						action("Serialized Graph")(beautify(model.serializeDiagram(), null, 2, 80));
					}}
				>
					Serialize Graph
				</button>
			}
		>
			<DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />
		</DemoWorkspaceWidget>
	);
};

snapshot: capture

ganesh-sankey avatar Apr 20 '18 06:04 ganesh-sankey

+1

akhilesh-sankey avatar Apr 20 '18 06:04 akhilesh-sankey

+1

hitesh-sankey avatar Apr 20 '18 06:04 hitesh-sankey

Fixed by https://github.com/projectstorm/react-diagrams/pull/230

dylanvorster avatar Apr 23 '18 15:04 dylanvorster