How to use @projectstorm/react-diagrams - 10 common examples

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-project / src / main.tsx View on Github external
import createEngine, { DefaultLinkModel, DiagramModel } from '@projectstorm/react-diagrams';
import { JSCustomNodeFactory } from './custom-node-js/JSCustomNodeFactory';
import { TSCustomNodeFactory } from './custom-node-ts/TSCustomNodeFactory';
import { JSCustomNodeModel } from './custom-node-js/JSCustomNodeModel';
import { TSCustomNodeModel } from './custom-node-ts/TSCustomNodeModel';
import { BodyWidget } from './BodyWidget';

// create an instance of the engine
const engine = createEngine();

// register the two engines
engine.getNodeFactories().registerFactory(new JSCustomNodeFactory() as any);
engine.getNodeFactories().registerFactory(new TSCustomNodeFactory());

// create a diagram model
const model = new DiagramModel();

//####################################################
// now create two nodes of each type, and connect them

const node1 = new JSCustomNodeModel({ color: 'rgb(192,255,0)' });
node1.setPosition(50, 50);

const node2 = new TSCustomNodeModel({ color: 'rgb(0,192,255)' });
node2.setPosition(200, 50);

const link1 = new DefaultLinkModel();
link1.setSourcePort(node1.getPort('out'));
link1.setTargetPort(node2.getPort('in'));

model.addAll(node1, node2, link1);
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-drag-and-drop / Application.ts View on Github external
public newModel() {
		this.activeModel = new SRD.DiagramModel();
		this.diagramEngine.setDiagramModel(this.activeModel);

		//3-A) create a default node
		var node1 = new SRD.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 SRD.DefaultNodeModel('Node 2', 'rgb(192,255,0)');
		let port2 = node2.addInPort('In');
		node2.setPosition(400, 100);

		// link the ports
		let link1 = port.link(port2);

		this.activeModel.addAll(node1, node2, link1);
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);
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-simple-flow / index.tsx View on Github external
export default () => {
	//1) setup the diagram engine
	var engine = createEngine();

	// ############################################ MAGIC HAPPENS HERE
	const state = engine.getStateMachine().getCurrentState();
	if (state instanceof DefaultDiagramState) {
		state.dragNewLink.config.allowLooseLinks = false;
	}
	// ############################################ MAGIC HAPPENS HERE

	//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)');
	var port1 = node1.addOutPort('Out');
	node1.setPosition(100, 100);

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

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

	//3-D) create an orphaned node
	var node3 = new DefaultNodeModel('Node 3', 'rgb(0,192,255)');
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-labelled-links / index.tsx View on Github external
export default () => {
	// setup the diagram engine
	const engine = createEngine();

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

	// create four nodes
	const node1 = new DefaultNodeModel('Node A', 'rgb(0,192,255)');
	const port1 = node1.addOutPort('Out');
	node1.setPosition(100, 100);

	const node2 = new DefaultNodeModel('Node B', 'rgb(255,255,0)');
	const port2 = node2.addInPort('In');
	node2.setPosition(400, 50);

	const node3 = new DefaultNodeModel('Node C (no label)', 'rgb(192,255,255)');
	const port3 = node3.addInPort('In');
	node3.setPosition(450, 180);

	const node4 = new DefaultNodeModel('Node D', 'rgb(192,0,255)');
	const port4 = node4.addInPort('In');