How to use the @projectstorm/react-diagrams.DiagramModel 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-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');
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({
		name: 'Node 1',
		color: 'rgb(0,192,255)'
	});
	node1.setPosition(100, 100);
	let port1 = node1.addOutPort('Out');

	//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);
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-dagre / index.tsx View on Github external
export default () => {
	//1) setup the diagram engine
	let engine = createEngine();

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

	//3) create a default nodes
	let nodesFrom: NodeModel[] = [];
	let nodesTo: NodeModel[] = [];

	nodesFrom.push(createNode('from-1'));
	nodesFrom.push(createNode('from-2'));
	nodesFrom.push(createNode('from-3'));

	nodesTo.push(createNode('to-1'));
	nodesTo.push(createNode('to-2'));
	nodesTo.push(createNode('to-3'));

	//4) link nodes together
	let links = nodesFrom.map((node, index) => {
		return connectNodes(node, nodesTo[index], engine);
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-performance / 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();

	for (var i = 0; i < 8; i++) {
		for (var j = 0; j < 8; j++) {
			generateNodes(model, i * 200, j * 100);
		}
	}

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

	//6) render the diagram!
	return ;
};
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-mutate-graph / 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)');
	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);

	//4) add the models to the root graph
	model.addAll(node1, node2, link1);
github projectstorm / react-diagrams / packages / diagrams-demo-gallery / demos / demo-mutate-graph / index.tsx View on Github external
updatePositionViaSerialize() {
		let { engine } = this.props;
		let model = engine.getModel();
		let str = JSON.stringify(model.serialize());
		let model2 = new DiagramModel();
		let obj: ReturnType = JSON.parse(str);
		let node: ReturnType = _.values(obj.layers[0].models)[0] as any;
		node.x += 30;
		node.y += 30;
		model2.deserializeModel(obj, engine);
		engine.setModel(model2);
	}