-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphviz.vue
69 lines (67 loc) · 1.42 KB
/
graphviz.vue
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
<template>
<div class="graph-host"></div>
</template>
<script>
export default {
data() {
return {
value: false,
ogma: null,
};
},
methods: {
ErdosRenyi(n = 30, p = 0.2) {
const graph = { nodes: [], edges: [] };
let i, j;
for (i = 0; i < n; i++) {
graph.nodes.push({ id: i });
for (j = 0; j < i; j++) {
if (Math.random() < p) {
graph.edges.push({ source: i, target: j });
}
}
}
return graph;
},
async layout() {
return this.ogma.layouts.force({
autoStop: true,
edgeLength: 50,
// alignSiblings: true,
// charge: 2,
// gravity: 0.03
});
},
create_ogma() {
const hostDiv = document.getElementsByClassName("graph-host")[0];
this.ogma = new Ogma({
container: hostDiv,
renderer: "svg",
options: { backgroundColor: "transparent" },
interactions: {
pan: {
enabled: false,
},
},
});
},
},
async mounted() {
this.create_ogma();
const g = this.ErdosRenyi();
await this.ogma.setGraph(g);
await this.layout();
this.ogma.view.locateGraph();
},
};
</script>
<style>
.graph-host {
background-color: #c6d0dc;
padding: 10px;
width: calc(100vw - 30px);
height: calc(100vh - 30px);
border: 1px solid rgb(64, 73, 103);
border-radius: 4px;
}
</style>