Roh*_*olm 8 vis.js vis.js-network
I have a vis.js network graph that contains multiple edges between nodes and I am trying to have it setup with a hierarchical layout as well. If I do a normal graph without the hierarchical layout options then multiple lines are shown between nodes, however, once I turn on/place in the hierarchical layout option only one line is drawn.
Below are two plunkers showing what I mean:
https://plnkr.co/edit/c8SuBc0XjDZnn6im2vdg (Plunker with hierarchical layout off)
var options = {
height: '400px',
edges: { smooth: true, shadow: true},
layout: {
randomSeed: 1,
improvedLayout: true,
hierarchical: {
enabled: false, //change to true to see the other graph
direction: 'UD',
sortMethod: 'directed'
}
}
}
Run Code Online (Sandbox Code Playgroud)
https://plnkr.co/edit/L22bHk6kh1XKXulTjESD (Plunker with hierarchical layout on)
var options = {
height: '400px',
edges: { smooth: true, shadow: true},
layout: {
randomSeed: 1,
improvedLayout: true,
hierarchical: {
enabled: true, //change to true to see the other graph
direction: 'UD',
sortMethod: 'directed'
}
}
}
Run Code Online (Sandbox Code Playgroud)
As you can see, in the second one 2 edges from node 1 to node 3 collapse into one visually. Any help would be great.
我需要同样的东西,因此我搜索并找到了您的问题:)
似乎没有其他方法可以做到这一点,只能通过边属性来做到这一点(请参见下面的工作片段):
var edges = new vis.DataSet([
{from: 1, to: 3, arrows: 'to', label: "+++++", smooth: {type: "curvedCCW", roundness: 0.4}},
{from: 1, to: 3, arrows: 'to', label: "-----", smooth: {type: "curvedCCW", roundness: 0.2}},
{from: 1, to: 3, arrows: 'to', label: "11111", smooth: {type: "curvedCW", roundness: 0.2}},
{from: 1, to: 3, arrows: 'to', label: "22222", smooth: {type: "curvedCW", roundness: 0.4}},
]);
Run Code Online (Sandbox Code Playgroud)
请分享您对这个问题的发现
var edges = new vis.DataSet([
{from: 1, to: 3, arrows: 'to', label: "+++++", smooth: {type: "curvedCCW", roundness: 0.4}},
{from: 1, to: 3, arrows: 'to', label: "-----", smooth: {type: "curvedCCW", roundness: 0.2}},
{from: 1, to: 3, arrows: 'to', label: "11111", smooth: {type: "curvedCW", roundness: 0.2}},
{from: 1, to: 3, arrows: 'to', label: "22222", smooth: {type: "curvedCW", roundness: 0.4}},
]);
Run Code Online (Sandbox Code Playgroud)
// create an array with nodes
var nodes = new vis.DataSet([
{id: 1, label: 'Node 1', level: 0},
{id: 2, label: 'Node 2', level: 1},
{id: 3, label: 'Node 3', level: 1},
{id: 4, label: 'Node 4', level: 2},
{id: 5, label: 'Node 5', level: 2}
]);
// create an array with edges
var edges = new vis.DataSet([
{from: 1, to: 3, arrows: 'to', label: "+++++", smooth: {type: "curvedCCW", roundness: 0.4}},
{from: 1, to: 3, arrows: 'to', label: "-----", smooth: {type: "curvedCCW", roundness: 0.2}},
{from: 1, to: 3, arrows: 'to', label: "11111", smooth: {type: "curvedCW", roundness: 0.2}},
{from: 1, to: 3, arrows: 'to', label: "22222", smooth: {type: "curvedCW", roundness: 0.4}},
{from: 1, to: 2, arrows: 'to'},
{from: 2, to: 4, arrows: 'to'},
{from: 2, to: 5},
{from: 3, to: 3}
]);
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
interaction: {
hover:true,
tooltipDelay: 300
},
height: '400px',
edges: { smooth: true
},
layout: {
randomSeed: 1,
improvedLayout: true,
hierarchical: {
enabled: true, //change to true to see the other graph
direction: 'UD',
nodeSpacing: 150,
sortMethod: 'directed'
}
},
configure: {},
"physics": {
"enabled": false,
"minVelocity": 0.75
}
};
var network = new vis.Network(container, data, options);Run Code Online (Sandbox Code Playgroud)
#mynetwork {
width: 600px;
height: 400px;
border: 1px solid lightgray;
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3381 次 |
| 最近记录: |