-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.html
67 lines (60 loc) · 1.43 KB
/
graph.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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#cy {
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
}
</style>
<div id="cy"></div>
<!-- <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> -->
<script src="https://unpkg.com/d3@4.13.0/build/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.2.11/cytoscape.min.js"></script>
<script>
var cy = cytoscape({
container: document.getElementById('cy'),
style: [{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(label)'
}
}, {
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle'
}
}]
});
d3.json('big-sister-cities.json', (error, data) => {
if (error) throw error;
// Add cities as nodes.
for (let id in data.cities) {
let city = data.cities[id];
cy.add({data: {
id: id,
label: city.label
}});
}
// Add sisters as edges.
for (let [aid, bid] of data.sisters) {
cy.add({data: {
id: `${aid}-${bid}`,
source: aid,
target: bid
}});
}
let options = {
name: 'cose',
nodeOverlap: 4,
gravity: 0.1
};
cy.layout(options).run();
});
</script>