2017-07-13 77 views
0

我想,使各節點的一些團體在我的圖形行爲不同於其他節點。 例如,我有一個名爲屬性的組,我動態添加到圖中。我需要改變這個組的重力常數或權重,以使它們更接近父節點,然後更接近其餘的節點。更改物理 - visjs

example

我希望這個例子可以幫助可視化的問題。 (已有黑色,因爲敏感信息的標籤)

我怎麼會在vis.js

回答

1

//

的Json嗨做到這一點。

見附圖代碼段。 希望它可以幫助你。

// create an array with nodes 
 
    var nodes = new vis.DataSet([ 
 
    {id: 1, label: 'Node 1', group: 1}, 
 
    {id: 2, label: 'Node 2', group: 2}, 
 
    {id: 3, label: 'Node 3', group: 1}, 
 
    {id: 4, label: 'Node 4', group: 2}, 
 
    {id: 5, label: 'Node 5', group: 2} 
 
    ]); 
 

 
    // create an array with edges 
 
    var edges = new vis.DataSet([ 
 
    {from: 1, to: 3}, 
 
    {from: 2, to: 4}, 
 
    {from: 2, to: 5} 
 
    ]); 
 

 
    // create a network 
 
    var container = document.getElementById('mynetwork'); 
 
    var data = { 
 
    nodes: nodes, 
 
    edges: edges 
 
    }; 
 
    var options = { 
 
    groups: { 
 
     1: { color: 'red', mass: 500 },// try to change this value 
 
     2: { color: 'blue', mass: 5 } 
 
    }, 
 
    physics: true 
 
    }; 
 
    var network = new vis.Network(container, data, options); 
 
#mynetwork { 
 
     width: 600px; 
 
     height: 400px; 
 
     border: 1px solid lightgray; 
 
    } 
 

 
    p { 
 
     max-width: 600px; 
 
    }
<!doctype html> 
 
<html> 
 
<head> 
 
    <title>Network | Basic usage</title> 
 
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.js"></script> 
 
    <link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.css" rel="stylesheet" type="text/css"/> 
 
</head> 
 
<body> 
 
<div id="mynetwork"></div> 
 

 

 

 
</body> 
 
</html>

+0

非常感謝!任何方式與其他物理模型一起使用這樣的東西?像「forceAtlas2Based」? – Jason

+0

@Jason據我瞭解應該是一樣的。 嘗試添加: 「邊緣」:{ 「平穩」:{ 「forceDirection」: 「無」 } }, 「物理學」:{ 「forceAtlas2Based」:{ 「centralGravity」:0.03, 「springLength」:100 }, 「minVelocity」:0.75, 「solver」:「forceAtlas2Based」 } 到您的選項。 – TERMIN

+0

thx你一直很好的幫助。奇蹟般有效 – Jason