/
Diagram.vue
61 lines (51 loc) · 1.34 KB
/
Diagram.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
<script setup>
import { onMounted, ref } from 'vue'
import * as go from 'gojs'
const props = defineProps({ nodeDataArray: Array, linkDataArray: Array })
const emitter = defineEmits([
"ExternalObjectsDropped",
"SelectionMoved"
])
const diagram = ref(null)
onMounted(function() {
const $ = go.GraphObject.make;
const myDiagram =
new go.Diagram(diagram.value,
{
"undoManager.isEnabled": true
});
myDiagram.addDiagramListener("ExternalObjectsDropped", e => emitter("ExternalObjectsDropped", e))
myDiagram.addDiagramListener("SelectionMoved", e => emitter("SelectionMoved", e))
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape,
{ fill: "white" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text"))
);
myDiagram.linkTemplate =
$(go.Link,
{
relinkableFrom: true, relinkableTo: true,
reshapable: true, resegmentable: true
},
$(go.Shape),
$(go.Shape, { toArrow: "OpenTriangle" })
);
const nda = props.nodeDataArray;
const lda = props.linkDataArray;
myDiagram.model = new go.GraphLinksModel(nda, lda);
})
</script>
<template>
<div ref="diagram" class="goDiagram"></div>
</template>
<style scoped>
.goDiagram {
width: 400px;
height: 400px;
border: solid black 1px;
}
</style>