我希望joint.js库读取我的JSON并将其显示为一个单元格:rect和circle
I want joint.js library to read my JSON and display it as a cell: rect and circle
我有一个json数据结构,例如:
var json1 = {
"places": [ { "id":0, "x":0.0, "y":0.0, "width":10.0, "height":10.0 },
{ "id":1, "x":50.0, "y":0, "width":10.0, "height":10.0 },
{ "id":2, "x":0.0, "y":30.0, "width":10.0, "height":10.0 },
{ "id":3, "x":50.0, "y":30.0, "width":10.0, "height":10.0 } ],
"transitions": [ { "id":0, "x":20.0, "y":20.0, "width":20.0, "height":10.0, "label":"Hello" } ],
"ptlinks": [ { "src":0, "dst":0, "expr":"x=0" },
{ "src":1, "dst":0, "expr":"y=0" } ],
"tplinks": [ { "src":0, "dst":1 },
{ "src":0, "dst":3 } ],
"name"": "Client"
}
我想用这些数据画一个图形,元素转换为矩形,放置为带有链接的圆形。。。。
<script language="javascript">
var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
el: $('#main_petri'),
width: 960,
height: 500,
model: graph
});
var rect = new joint.shapes.basic.Rect({
position: { x: 100, y: 30 },
size: { width: 100, height: 30 },
attrs: { rect: { fill: '#FFFFFF' }, text: { text: '#', fill: '#000000' } }
});
var rect2 = rect.clone();
rect2.translate(0,50);
var link = new joint.dia.Link({
source: { id: rect.id },
target: { id: rect2.id }
});
graph.addCells([rect, rect2, link]);
如何在jointjs中使用JSON(位置、大小…)?
您可以在位置/转换和链接上循环,并创建JointJS元素/链接。类似于:
_.each(json1.places, function(p) {
graph.addCell(new joint.shapes.pn.Place({
id: 'place' + p.id,
position: { x: p.x, y: p.y },
size: { width: p.width, height: p.height }
}));
});
_.each(json1.transitions, function(t) {
graph.addCell(new joint.shapes.pn.Transition({
id: 'transition' + t.id,
position: { x: t.x, y: t.y },
size: { width: t.width, height: t.height },
attrs: { '.label': { text: t.label } }
}));
});
_.each(json1.ptlinks, function(l) {
graph.addCell(new joint.dia.Link({
source: { id: 'place' + l.src },
target: { id: 'transition' + l.dst },
labels: [ { position: .5, attrs: { text: { text: l.expr } } } ]
}));
});
_.each(json1.tplinks, function(l) {
graph.addCell(new joint.dia.Link({
source: { id: 'transition' + l.src },
target: { id: 'place' + l.dst },
labels: [ { position: .5 } ]
}));
});
相关文章:
- 在 SlickGrid 中编辑后,根据不同列中的另一个单元格清除单元格
- 申请表要求在提交前一个单元格与其他单元格相等
- 每行仅突出显示一个单元格
- Google Apps 脚本,用于根据一个单元格的值对另一个单元格进行条件颜色格式设置
- 只在表中突出显示一个单元格值
- 当一个单元格被编辑时,是否有一个事件触发,但值没有'不要改变
- 我希望joint.js库读取我的JSON并将其显示为一个单元格:rect和circle
- 用JQuery在廉价的excel表格上标记最后一个单元格
- 在 jQuery 中获取表的上一个或下一个单元格值
- 获取上一个单元格的图像
- 如何将类添加到由摘要功能生成的网格的一个单元格
- 使用查询选择器查找同级行中包含的下一个单元格
- 当按 Tab 键经过最后一个单元格时,自动在 ng-grid 中添加行
- 数组最后一个单元格中不需要的对象
- 在 jqxGrid 中按一个单元格的值选择一行
- 如何在访问子网格视图时获取父网格视图的一个单元格的值
- 为其中一个单元格或 td 查找 colSpan 标头是 Spans
- 将多个具有相同名称的文本输入插入到 MySql 中的一个单元格中
- 如何使用来自另一个单元格的 onChange 事件更新一个单元格
- 下一个单元格上可自动点击的电子邮件地址.应用程序脚本