边缘数据格式

时间:2019-06-06 17:48:46

标签: cytoscape.js

我正在尝试找到最有效的方法来返回网络图的数据,该网络图将由前端的cytoscape js构建。我知道添加边缘和节点的标准方法是:

select comp_id, sum(total) from (
(
SELECT CASE
         WHEN AVG(amount) < 10 THEN 0 
         WHEN COUNT(p_id) < SUM(amount)*.5
         THEN SUM(amount)*.5
         ELSE COUNT(p_id) 
        END as total, avg(amount), comp_id
FROM p_container INNER JOIN chg ON chg_p_id = p_id 
INNER JOIN c_type ON c_type_id = chtype_id
where correction_name like '%correction word%'
AND p_date BETWEEN GETDATE () - 9 AND GETDATE () - 2
group by comp_id
) UNION ALL (
SELECT CASE
         WHEN AVG(amount) < 5 THEN 0 
         WHEN COUNT(p_id) < SUM(amount)*.06
         THEN SUM(amount)*.06 
         ELSE COUNT(p_id) 
        END as total, avg(amount), comp_id
FROM p_container INNER JOIN chg ON chg_p_id = p_id 
INNER JOIN c_type ON c_type_id = chtype_id
where correction_name like '%correction word%'
AND p_date BETWEEN GETDATE () - 17  AND GETDATE () - 10 
group by comp_id
)) group by comp_id

来自他们的文档

我想知道是否有一种方法可以有效地执行以下操作:

// can use reference to eles later
var eles = cy.add([
  { group: 'nodes', data: { id: 'n0' }, position: { x: 100, y: 100 } },
  { group: 'nodes', data: { id: 'n1' }, position: { x: 200, y: 200 } },
  { group: 'nodes', data: { id: 'n2' }, position: { x: 300, y: 300 } },
  { group: 'edges', data: { id: 'e0', source: 'n0', target: 'n1' } },
  { group: 'edges', data: { id: 'e0', source: 'n0', target: 'n2' } }
]);

这样,我可以从服务器返回邻接列表,而不是边缘/节点列表。

1 个答案:

答案 0 :(得分:0)

引人入胜的格式,但是不幸的是,如果没有新的扩展名,这种格式将无法正常工作。

问题是,图的每个元素都必须具有ID!因此,当您在图形上添加一条边并分配多个目标时,每个边应有2个ID。

如果您要优化cy实例,则可以翻阅文档的this部分。