Explain or demonstrate integration between JointJS and Node.js

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:25:56

问题


I'm coming back to JointJS after a year away and I see that it now claims some kind of Node.js support or compatibility. I'm using Node.js and am wondering whether I can leverage this feature. Is there a tutorial which walks me through this or can someone please explain what Node.js model integration offers me for JointJS?

http://www.jointjs.com/ claims "NodeJS support". The Git commit log contains comments like "create tests for NodeJS environment".


回答1:


Yes, JointJS supports NodeJS environment. Note that only models are supported (element, link, graph). For example, you can build your graph on the server side, then stringify it to JSON, send it to the client and there you can display that graph:

Install jointjs: npm install jointjs

Create your graph in NodeJS:

var joint = require('jointjs');
var graph = new joint.dia.Graph;

var el1 = new joint.shapes.basic.Rect({ position: { x: 50, y: 50 }, attrs: { text: { fill: 'yellow' } }});
var el2 = new joint.shapes.basic.Rect({ position: { x: 300, y: 200 }, attrs: { text: { fill: 'yellow' } }});
var link = new joint.dia.Link({ source: { id: el1.id }, target: { id: el2.id } });
graph.addCells([el1, el2, link]);

Do what you need with the graph:

storeToDBOrSendToClient(graph.toJSON())

As long as you work with JointJS models, you can take advantage of all the features of JointJS in NodeJS environment.



来源:https://stackoverflow.com/questions/20975782/explain-or-demonstrate-integration-between-jointjs-and-node-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!