How to use the @projectstorm/react-diagrams.DefaultNodeModel function in @projectstorm/react-diagrams

To help you get started, we’ve selected a few @projectstorm/react-diagrams examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-right-angles-routing / index.tsx View on Github external
export default () => {
	// setup the diagram engine
	const engine = createEngine();
	engine.getLinkFactories().registerFactory(new RightAngleLinkFactory());

	// setup the diagram model
	const model = new DiagramModel();

	// create four nodes in a way that straight links wouldn't work
	const node1 = new DefaultNodeModel('Node A', 'rgb(0,192,255)');
	const port1 = node1.addPort(new RightAnglePortModel(false, 'out-1', 'Out'));
	node1.setPosition(340, 350);

	const node2 = new DefaultNodeModel('Node B', 'rgb(255,255,0)');
	const port2 = node2.addPort(new RightAnglePortModel(false, 'out-1', 'Out'));
	node2.setPosition(240, 80);
	const node3 = new DefaultNodeModel('Node C', 'rgb(192,255,255)');
	const port3 = node3.addPort(new RightAnglePortModel(true, 'in-1', 'In'));
	node3.setPosition(540, 180);
	const node4 = new DefaultNodeModel('Node D', 'rgb(192,0,255)');
	const port4 = node4.addPort(new RightAnglePortModel(true, 'in-1', 'In'));
	node4.setPosition(95, 185);

	// linking things together
	const link1 = port1.link(port4);
	const link2 = port2.link(port3);

	// add all to the main model
	model.addAll(node1, node2, node3, node4, link1, link2);
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-listeners / index.tsx View on Github external
export default () => {
	// setup the diagram engine
	var engine = createEngine();

	var model = new DiagramModel();

	// sample for link with simple line
	var node1 = new DefaultNodeModel('Node 1', 'rgb(255,99,66)');
	var port1 = node1.addOutPort('Out');
	node1.setPosition(100, 100);

	var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
	var port2 = node2.addInPort('In');
	node2.setPosition(400, 40);

	var node3 = new DefaultNodeModel('Node 3', 'rgb(128,99,255)');
	var port3 = node3.addInPort('In');
	node3.setPosition(300, 160);

	//link the nodes
	let link1 = port1.link(port2);
	let link2 = port1.link(port3);

	// add all the models
	let models = model.addAll(node1, node2, node3, link1, link2);

	// add a selection listener to each
	models.forEach(item => {
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-simple / index.tsx View on Github external
export default () => {
	//1) setup the diagram engine
	var engine = createEngine();

	//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);

	//5) load model into engine
	engine.setModel(model);

	//6) render the diagram!
	return (
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-right-angles-routing / index.tsx View on Github external
// setup the diagram model
	const model = new DiagramModel();

	// create four nodes in a way that straight links wouldn't work
	const node1 = new DefaultNodeModel('Node A', 'rgb(0,192,255)');
	const port1 = node1.addPort(new RightAnglePortModel(false, 'out-1', 'Out'));
	node1.setPosition(340, 350);

	const node2 = new DefaultNodeModel('Node B', 'rgb(255,255,0)');
	const port2 = node2.addPort(new RightAnglePortModel(false, 'out-1', 'Out'));
	node2.setPosition(240, 80);
	const node3 = new DefaultNodeModel('Node C', 'rgb(192,255,255)');
	const port3 = node3.addPort(new RightAnglePortModel(true, 'in-1', 'In'));
	node3.setPosition(540, 180);
	const node4 = new DefaultNodeModel('Node D', 'rgb(192,0,255)');
	const port4 = node4.addPort(new RightAnglePortModel(true, 'in-1', 'In'));
	node4.setPosition(95, 185);

	// linking things together
	const link1 = port1.link(port4);
	const link2 = port2.link(port3);

	// add all to the main model
	model.addAll(node1, node2, node3, node4, link1, link2);

	// load model into engine and render
	engine.setModel(model);

	return (
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-cloning / index.tsx View on Github external
export default () => {
	//1) setup the diagram engine
	var engine = createEngine();

	//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 port = 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 = port.link(port2);

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

	//5) load model into engine
	engine.setModel(model);

	//6) render the diagram!
	return ;
};
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-zoom-to-fit / index.tsx View on Github external
function generateNodes(model: DiagramModel, offsetX: number, offsetY: number) {
	//3-A) create a default node
	var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
	var port1 = node1.addOutPort('Out');
	node1.setPosition(100 + offsetX, 100 + offsetY);

	//3-B) create another default node
	var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
	var port2 = node2.addInPort('In');
	node2.setPosition(200 + offsetX, 100 + offsetY);

	//3-C) link the 2 nodes together
	var link1 = port1.link(port2);

	//4) add the models to the root graph
	model.addAll(node1, node2, link1);
}
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-custom-node1 / index.tsx View on Github external
var node3 = new DefaultNodeModel('Node 3', 'red');
	var port3 = node3.addInPort('In');
	node3.setPosition(500, 100);

	//3-C) link the 2 nodes together
	var link1 = port1.link(node2.getPort(PortModelAlignment.LEFT));
	var link2 = port3.link(node2.getPort(PortModelAlignment.RIGHT));

	var node4 = new DefaultNodeModel('Node 4', 'rgb(0,192,255)');
	var port4 = node4.addOutPort('Out');
	node4.setPosition(200, 10);

	var link3 = port4.link(node2.getPort(PortModelAlignment.TOP));

	var node5 = new DefaultNodeModel('Node 5', 'mediumpurple');
	var port5 = node5.addInPort('In');
	node5.setPosition(400, 300);

	var link4 = port5.link(node2.getPort(PortModelAlignment.BOTTOM));

	//4) add the models to the root graph
	model.addAll(node1, node2, node3, link1, link2, node4, link3, link4, node5);

	//5) load model into engine
	engine.setModel(model);

	//6) render the diagram!
	return (
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-zoom-to-fit / index.tsx View on Github external
function generateNodes(model: DiagramModel, offsetX: number, offsetY: number) {
	//3-A) create a default node
	var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
	var port1 = node1.addOutPort('Out');
	node1.setPosition(100 + offsetX, 100 + offsetY);

	//3-B) create another default node
	var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
	var port2 = node2.addInPort('In');
	node2.setPosition(200 + offsetX, 100 + offsetY);

	//3-C) link the 2 nodes together
	var link1 = port1.link(port2);

	//4) add the models to the root graph
	model.addAll(node1, node2, link1);
}
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-performance / index.tsx View on Github external
function generateNodes(model: DiagramModel, offsetX: number, offsetY: number) {
	//3-A) create a default node
	var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
	var port1 = node1.addOutPort('Out');
	node1.setPosition(100 + offsetX, 100 + offsetY);

	//3-B) create another default node
	var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
	var port2 = node2.addInPort('In');
	node2.setPosition(200 + offsetX, 100 + offsetY);

	//3-C) link the 2 nodes together
	var link1 = port1.link(port2);

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