{
"nodes"
:[{
"name"
:
"A"
,
"x"
: -100,
"y"
: -50,
"id"
: 1}, {
"name"
:
"B"
,
"id"
: 2}],
"edges"
: [{
"name"
:
"Edge"
,
"from"
:1,
"to"
:2}]}
function
translateToQuneeElements(json, graph){
var
map = {};
if
(json.nodes){
Q.forEach(json.nodes,
function
(data){
var
node = graph.createNode(data.name, data.x || 0, data.y || 0);
node.set(
"data"
, data);
map[data.id] = node;
// 节点加入图元容器,这个会在数据呈现部分说明
model.add(node);
});
}
if
(json.edges){
Q.forEach(json.edges,
function
(data){
var
from = map[data.from];
var
to = map[data.to];
if
(!from || !to){
return
;
}
var
edge = graph.createEdge(data.name, from, to);
edge.set(
"data"
, data);
}, graph);
}
}
|