forked from iilab/openoil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_test.html
69 lines (60 loc) · 1.76 KB
/
index_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<meta charset="utf-8">
<title>Force-Directed Graph</title>
<style>
.node {
cursor: pointer;
stroke: #3182bd;
stroke-width: 1.5px;
}
.link {
fill: none;
stroke: #9ecae1;
stroke-width: 1.5px;
}
</style>
<body>
<svg id="openoil"></svg>
<script src="lib/d3.js"></script>
<script src="lib/neod3.js"></script>
<script>
d3.xhr("data/style.grass", "application/grass", function(request){
drawGraph(request.responseText);
});
//drawGraph($('#grass').innerText);
var drawGraph = function(styleContents) {
var graphView = neo.graphView()
.style(styleContents)
.width(1280)
.on('nodeClicked', function(node){
graphModel.nodes.remove(node.id);
})
.on('nodeDblClicked', function(node){
var id = Math.round(Math.random() * 10000);
graphModel.nodes.add({id: id, labels: ['Goonie'], properties: {name: "Goonie"}});
graphModel.relationships.add({id: id, source: node.id, target: id, type: 'SPAWNS'});
})
.on('relationshipClicked', function(relationship){
graphModel.relationships.remove(relationship.id);
})
;
var graphModel = neo.graphModel()
.nodes([
{id: 0, labels: ['Person', 'Gamer'], properties: {name: "Johan"}},
{id: 1, labels: ['Person'], properties: {name: "Sebastian"}},
{id: 2, labels: ['Thing'], properties: {name: "Nintendo"}}
])
.relationships([
{id: 0, source: 0, target: 2, type: 'PLAYS'},
{id: 1, source: 1, target: 2, type: 'OWNS', properties: {since: "1991"}}
])
d3.select("#openoil")
.data([graphModel])
.call(graphView);
setTimeout(function(){
graphModel.nodes.add({id: 3, labels: ['Thing'], properties: {name: "Sega"}})
graphModel.relationships.add({id: 2, source: 0, target: 3, type: 'HATES'})
}, 1000)
}
</script>
</body>