index.vue
2.58 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
<!--
* @Date: 2025-03-10 16:52:35
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-13 21:05:08
* @FilePath: /logic-flow2/src/views/mini-map/index.vue
* @Description: 小地图
-->
<template>
<div class="container">
<div ref="container" class="flow-container"></div>
<div class="mini-map-container">
<el-button type="primary" @click="toggleVisible">
{{ visible ? "隐藏" : "显示" }}
</el-button>
<el-button type="primary" @click="handleReset">重置</el-button>
<el-button type="primary" @click="updatePositionWithObject1">
左上角
</el-button>
<el-button type="primary" @click="updatePositionWithObject2">
右下角
</el-button>
</div>
</div>
</template>
<script setup>
import LogicFlow from "@logicflow/core";
import { MiniMap } from "@logicflow/extension";
const container = ref(null);
let lf = null;
const miniMapOptions = {
isShowHeader: false,
isShowCloseIcon: true,
headerTitle: "MiniMap",
width: 200,
height: 120,
rightPosition: 100,
bottomPosition: 100,
};
const visible = ref(false);
const position = ref(false);
onMounted(() => {
lf = new LogicFlow({
container: container.value,
grid: true,
plugins: [MiniMap],
pluginsOptions: {
miniMap: {
...miniMapOptions,
},
},
});
lf.on("miniMap:close", () => {
visible.value = false;
});
lf.render({
nodes: [
{ id: "node1", type: "rect", x: 200, y: 100 },
{ id: "node2", type: "circle", x: 400, y: 100 },
],
edges: [{ id: "edge1", sourceNodeId: "node1", targetNodeId: "node2" }],
});
});
const toggleVisible = () => {
if (lf) {
const miniMap = lf.extension.miniMap;
if (visible.value) {
miniMap.hide();
} else {
miniMap.show();
}
visible.value = !visible.value;
}
};
const handleReset = () => {
if (lf) {
lf.extension.miniMap.reset();
}
};
const updatePosition = (position) => {
if (lf) {
const miniMap = lf.extension.miniMap;
miniMap.updatePosition(position);
position.value = position;
}
};
const updatePositionWithObject1 = () => {
(lf?.extension.miniMap).updatePosition({
left: 100,
top: 100,
});
};
const updatePositionWithObject2 = () => {
(lf?.extension.miniMap).updatePosition({
right: 100,
bottom: 100,
});
};
</script>
<style scoped>
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.flow-container {
flex: 1;
width: 100%;
height: 100%;
}
.mini-map-container {
position: absolute;
bottom: 20px;
right: 20px;
}
</style>