-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.html
More file actions
executable file
·159 lines (151 loc) · 5.14 KB
/
graph.html
File metadata and controls
executable file
·159 lines (151 loc) · 5.14 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!--
This is an example html file with some options added. The minimum html file for
the graph visualization is:
<!DOCTYPE html>
<html>
<head>
<title>Graph Visualization</title>
<script type="text/javascript" src="build/graph.min.js"></script>
</head>
<body onload="new Drawing.SimpleGraph({layout: '3d', showStats: true, showInfo: true})">
</bod>
</html>
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Graph Visualization</title>
<script type="text/javascript" src="js/graph/build/graph.min.js"></script>
<script type="text/javascript" src="js/graph.js"></script>
<script type="text/javascript" src="js/papa-parse/papaparse.js"></script>
<script type="text/javascript">
var drawing;
function createDrawing() {
drawing = new Drawing.SimpleGraph(
{
layout: '3d',
selection: true,
graphLayout:
{
attraction: 1,
repulsion: 3.5
},
showStats: true,
showInfo: true
}
);
var stack = [];
let csv = 'http://local.canvas.com/data/product-customer.csv';
Papa.parse(csv, {
download: true,
step: function(row) {
stack.push(row.data[0]);
},
complete: function() {
drawing.init();
createGraph();
drawing.animate();
}
});
/**
* Creates a graph with random nodes and edges.
* Number of nodes and edges can be set with
* numNodes and numEdges.
*/
function createGraph() {
let nodes = [];
let added = [];
while(stack.length > 0) {
if (Math.random() > 0.01){
stack.shift();
continue;
}
//console.log(stack.length);
let relation = stack.shift();
//console.log(relation[0] + '-' + relation[1]);
//console.log('added');
//console.log(added);
//console.log('nodes');
//console.log(nodes);
if (!added.includes(relation[0])) {
let node1 = new GRAPHVIS.Node(relation[0]);
node1.data.title = relation[0];
drawing.graph.addNode(node1);
drawing.drawNode(node1);
nodes[relation[0]] = node1;
added.push(relation[0]);
////console.log('Added node ' + relation[0] + '(1 if)');
} else {
//console.log('Not added ' + relation[0] + '(1 if)');
}
if (!added.includes(relation[1])) {
let node2 = new GRAPHVIS.Node(relation[1]);
node2.data.title = relation[1];
drawing.graph.addNode(node2);
drawing.drawNode(node2);
nodes[relation[1]] = node2;
added.push(relation[1]);
//console.log('Added node ' + relation[1] + '(2 if)');
}
//console.log(nodes[relation[0]]);
//console.log(nodes[relation[1]]);
if(drawing.graph.addEdge(nodes[relation[0]], nodes[relation[1]])) {
drawing.drawEdge(nodes[relation[0]], nodes[relation[1]]);
//console.log('Added edge ' + relation[0] + '-' + relation[1]);
}
}
drawing.layout_options.width = drawing.layout_options.width || 2000;
drawing.layout_options.height = drawing.layout_options.height || 2000;
drawing.layout_options.iterations = drawing.layout_options.iterations || 100000;
drawing.layout_options.layout = drawing.layout_options.layout || drawing.layout;
drawing.graph.layout = new Layout.ForceDirected(drawing.graph, drawing.layout_options);
drawing.graph.layout.init();
drawing.info_text.nodes = "Nodes " + drawing.graph.nodes.length;
drawing.info_text.edges = "Edges " + drawing.graph.edges.length;
}
}
</script>
<style type="text/css">
body {
margin: 0;
padding: 0;
font: 11px courier;
overflow: hidden;
}
#graph-info {
position: absolute;
top: 0px;
left: 40%;
margin: 10px;
background-color: #ffffe0;
color: #333;
padding: 5px 10px;
}
#options {
position: absolute;
top: 0;
right: 0;
z-index: 10;
}
</style>
</head>
<body onload="createDrawing()">
<div id="options">
<form>
<p>
<input type="checkbox" id="show_labels" onclick="drawing.show_labels = this.checked;">
<label for="show_labels">Show labels</label>
</p>
<p>
<input type="button" value="Stop layout" onclick="drawing.stop_calculating();">
</p>
</form>
</div>
<div style="position: absolute; bottom: 0;">
Rotate: Left Mouse Button and Move<br />
Zoom: Press Key S + Left Mouse Button and Move<br />
Drag: Press Key D + Left Mouse Button and Move
</div>
</body>
</html>