Skip to content

Commit 7edae48

Browse files
authored
Merge pull request #116 from towersxu/master
fix: minimap support register node
2 parents a8dc87c + 3a692e6 commit 7edae48

File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed

docs/guide/extension/component-minimap.md

+10
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ MiniMap.show(leftPosition?: number, topPosition?: number);
3535
MiniMap.hide();
3636
```
3737

38+
## 禁用插件
39+
40+
MiniMap和正常的画布共享LogicFlow,可以在MiniMap中不显示某些插件,例如不显示工具栏。
41+
42+
```ts
43+
MiniMap.init({
44+
disabledPlugins: [Control.name, Snapshot.name, SelectionSelect.name]
45+
})
46+
```
47+
3848
<example href="/examples/#/extension/components/mini-map" :height="350" ></example>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="format-detection" content="telephone=no, email=no">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>LOGIN FLOW</title>
8+
<link rel="stylesheet" href="/core/dist/style/index.css">
9+
<!-- <link rel="stylesheet" href="http://0.0.0.0:9090/src/style/index.css"> -->
10+
<link rel="stylesheet" href="/extension/src/style/index.css">
11+
<style>
12+
html,body {
13+
padding: 0;
14+
margin: 0;
15+
}
16+
body {
17+
background-color: #FFF;
18+
}
19+
#app {
20+
width: 1200px;
21+
height: 500px;
22+
border: 1px solid #efefef;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<button id="mini-map">显示</button>
28+
<div class="rules-graph">
29+
<div id="app"></div>
30+
</div>
31+
<script src="/core/dist/logic-flow.js"></script>
32+
<!-- <script src="http://localhost:9090/logic-flow.js"></script> -->
33+
<script src="/MiniMap.js"></script>
34+
<script>
35+
LogicFlow.use(MiniMap);
36+
</script>
37+
<script src="./index.js"></script>
38+
39+
</body>
40+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
window.addEventListener('DOMContentLoaded', () => {
2+
console.log(document.querySelector('#app'))
3+
const lf = new LogicFlow({
4+
container: document.querySelector('#app'),
5+
edgeTextDraggable: true,
6+
nodeTextDraggable: true,
7+
metaKeyMultipleSelected: true,
8+
grid: {
9+
type: 'dot',
10+
size: 20,
11+
},
12+
keyboard: {
13+
enabled: true,
14+
},
15+
snapline: true,
16+
});
17+
console.log(5);
18+
lf.register('x-node', ({ RectNode, RectNodeModel }) => {
19+
return {
20+
view: RectNode,
21+
model: RectNodeModel,
22+
}
23+
})
24+
lf.render({
25+
nodes: [
26+
{
27+
id: 'c_1',
28+
type: 'circle',
29+
x: 100,
30+
y: 100
31+
},
32+
{
33+
id: 'c_3',
34+
type: 'x-node',
35+
x: 500,
36+
y: 200
37+
},
38+
{
39+
id: 'c_2',
40+
type: 'circle',
41+
x: 300,
42+
y: 200
43+
}
44+
],
45+
edges: [
46+
{
47+
id: 'e_1',
48+
type: 'polyline',
49+
pointsList: [
50+
{
51+
x: 140,
52+
y: 100,
53+
},
54+
{
55+
x: 200,
56+
y: 100
57+
},
58+
{
59+
x: 200,
60+
y: 200,
61+
},
62+
{
63+
x: 250,
64+
y: 200
65+
}
66+
],
67+
sourceNodeId: 'c_1',
68+
targetNodeId: 'c_2'
69+
}
70+
]
71+
});
72+
73+
document.querySelector('#mini-map').addEventListener('click', () => {
74+
console.log(444)
75+
MiniMap.show();
76+
})
77+
})

packages/extension/src/components/mini-map/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,18 @@ const MiniMap: MiniMapPlugin = {
210210
__setView() {
211211
// 1. 获取到图中所有的节点中的位置,将其偏移到原点开始(避免节点位置为负的时候无法展示问题)。
212212
const data = MiniMap.__resetData(MiniMap.__lf.getGraphRawData());
213-
// 2. 将偏移后的数据渲染到minimap画布上
213+
// 由于随时都会有新节点注册进来,需要同步将注册的
214+
const viewMap = MiniMap.__lf.viewMap;
215+
const modelMap = MiniMap.__lf.graphModel.modelMap;
216+
const minimapViewMap = MiniMap.__lfMap.viewMap;
217+
for (let key of viewMap.keys()) {
218+
if (!minimapViewMap.has(key)) {
219+
MiniMap.__lfMap.setView(key, viewMap.get(key));
220+
MiniMap.__lfMap.graphModel.modelMap.set(key, modelMap.get(key));
221+
}
222+
}
214223
MiniMap.__lfMap.render(data);
224+
// 2. 将偏移后的数据渲染到minimap画布上
215225
// 3. 计算出所有节点在一起的边界。
216226
const { left, top, right, bottom } = MiniMap.__getBounds(data);
217227
// 4. 计算所有节点的边界与minimap看板的边界的比例.

0 commit comments

Comments
 (0)