Cytoscape js-使用cytoscape-graphml.js初始化图形

问题描述 投票:0回答:1

我有一个graphML文件。我想在浏览器中显示来自我的graphML文件的图。我正在使用cytoscape.js。据我了解,我们可以使用cytoscape扩展cytoscape-graphml.js从graphML文件中导入图形。但是我不知道该怎么做。这是我要实现的示例。

var cy;
fetch('http://localhost/Development/example.graphml')
.then(response => response.text())
.then((data) => {
   cy = cytoscape({
     container: document.getElementById('cy'),
     elements: data
   });
});
cytoscape.js
1个回答
0
投票

嗯,正如您可以在cytoscape.js-graphml的docs中看到的那样,您只需要使用graphml数据和这样的布局来初始化cytoscape:

var cy;
fetch('http://localhost/Development/example.graphml')
.then(response => response.text())
.then((data) => {
   cy = cytoscape({
     container: document.getElementById('cy'),
     style: [
        {
            selector: 'node',
            style: {
                'content': 'data(id)'
            }
        },
        {
            selector: 'edge',
            style: {
                'target-arrow-shape': 'triangle'
            }
        }
    ],         
    ready: function () {
        this.graphml({layoutBy: 'cose'});
        this.graphml(data);
    }
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.