2019-04-08 09:06:57 +08:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.css" type="text/css" />
|
|
|
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis-network.min.js"> </script>
|
|
|
|
|
|
|
|
<!-- <link rel="stylesheet" href="../node_modules/vis/dist/vis.min.css" type="text/css" />
|
|
|
|
<script type="text/javascript" src="../node_modules/vis/dist/vis.js"> </script>-->
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
#mynetwork {
|
|
|
|
width: 500px;
|
|
|
|
height: 500px;
|
|
|
|
background-color: #ffffff;
|
|
|
|
border: 1px solid lightgray;
|
|
|
|
position: relative;
|
|
|
|
float: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<div id = "mynetwork"></div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
// initialize global variables.
|
|
|
|
var edges;
|
|
|
|
var nodes;
|
|
|
|
var network;
|
|
|
|
var container;
|
|
|
|
var options, data;
|
|
|
|
|
|
|
|
|
|
|
|
// This method is responsible for drawing the graph, returns the drawn network
|
|
|
|
function drawGraph() {
|
|
|
|
var container = document.getElementById('mynetwork');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// parsing and collecting nodes and edges from the python
|
2019-04-08 09:29:45 +08:00
|
|
|
nodes = new vis.DataSet([{"color": "#70ec84", "id": 0, "label": 0, "shape": "dot"}, {"color": "#70ec84", "id": 1, "label": 1, "shape": "dot"}, {"color": "#ffa07a", "id": 2, "label": 2, "shape": "dot"}, {"color": "#ffa07a", "id": 3, "label": 3, "shape": "dot"}, {"color": "#005582", "id": 4, "label": 4, "shape": "dot"}, {"color": "#005582", "id": 5, "label": 5, "shape": "dot"}, {"id": "sender", "label": "sender", "shape": "dot"}]);
|
|
|
|
edges = new vis.DataSet([{"from": "sender", "to": 0}, {"from": "sender", "to": 2}, {"from": "sender", "to": 4}, {"from": 0, "to": 1}, {"from": 2, "to": 3}, {"from": 4, "to": 5}]);
|
2019-04-08 09:06:57 +08:00
|
|
|
|
|
|
|
// adding nodes and edges to the graph
|
|
|
|
data = {nodes: nodes, edges: edges};
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
"configure": {
|
|
|
|
"enabled": false
|
|
|
|
},
|
|
|
|
"edges": {
|
|
|
|
"color": {
|
|
|
|
"inherit": true
|
|
|
|
},
|
|
|
|
"smooth": {
|
|
|
|
"enabled": false,
|
|
|
|
"type": "continuous"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"interaction": {
|
|
|
|
"dragNodes": true,
|
|
|
|
"hideEdgesOnDrag": false,
|
|
|
|
"hideNodesOnDrag": false
|
|
|
|
},
|
|
|
|
"physics": {
|
|
|
|
"barnesHut": {
|
|
|
|
"avoidOverlap": 0,
|
|
|
|
"centralGravity": 0.3,
|
|
|
|
"damping": 0.09,
|
|
|
|
"gravitationalConstant": -80000,
|
|
|
|
"springConstant": 0.001,
|
|
|
|
"springLength": 250
|
|
|
|
},
|
|
|
|
"enabled": true,
|
|
|
|
"stabilization": {
|
|
|
|
"enabled": true,
|
|
|
|
"fit": true,
|
|
|
|
"iterations": 1000,
|
|
|
|
"onlyDynamicEdges": false,
|
|
|
|
"updateInterval": 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// default to using dot shape for nodes
|
|
|
|
options.nodes = {
|
|
|
|
shape: "dot"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
network = new vis.Network(container, data, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return network;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
drawGraph();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|