Skip to content

Commit 9ec09df

Browse files
author
fanyang
committed
fix(extension): 合并snapshot冲突
1 parent bc27d7a commit 9ec09df

File tree

7 files changed

+360
-160
lines changed

7 files changed

+360
-160
lines changed

examples/feature-examples/src/pages/extensions/snapshot/data.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ export default {
22
nodes: [
33
{
44
type: 'uml',
5-
x: 100,
6-
y: 100,
5+
x: 0,
6+
y: 0,
77
id: 'uml_1',
88
properties: {
99
name: 'haod',
@@ -12,36 +12,39 @@ export default {
1212
},
1313
{
1414
type: 'rect',
15-
x: 300,
16-
y: 200,
15+
x: 150,
16+
y: 0,
1717
text: {
1818
value: '你好',
19-
x: 300,
20-
y: 200,
19+
x: 150,
20+
y: 0,
2121
},
2222
id: 'rect_1',
2323
},
2424
{
2525
type: 'rect',
26-
x: 500,
27-
y: 300,
26+
x: 400,
27+
y: 100,
2828
text: {
2929
value: '你好2',
30-
x: 500,
31-
y: 300,
30+
x: 400,
31+
y: 100,
3232
},
3333
id: 'rect_2',
3434
},
3535
{
36-
type: 'rect',
37-
x: 700,
38-
y: 300,
39-
text: {
40-
value: '你好3',
41-
x: 700,
42-
y: 300,
43-
},
44-
id: 'rect_3',
36+
id: '3',
37+
type: 'image',
38+
x: 550,
39+
y: 100,
40+
text: '云',
41+
},
42+
{
43+
id: '5',
44+
type: 'image',
45+
x: 350,
46+
y: 250,
47+
text: '菱形',
4548
},
4649
],
4750
edges: [
@@ -51,5 +54,11 @@ export default {
5154
sourceNodeId: 'rect_1',
5255
targetNodeId: 'rect_2',
5356
},
57+
{
58+
id: 'e_3',
59+
type: 'polyline',
60+
sourceNodeId: '4',
61+
targetNodeId: '5',
62+
},
5463
],
5564
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.viewport {
2-
height: calc(100vh - 250px);
3-
overflow: hidden;
1+
#graph {
2+
width: 800px;
3+
height: 500px;
44
}

examples/feature-examples/src/pages/extensions/snapshot/index.tsx

Lines changed: 152 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import LogicFlow from '@logicflow/core'
2-
import { Snapshot } from '@logicflow/extension'
3-
4-
import { Button, Card, Col, Divider, Flex, Row, Space } from 'antd'
52
import { useEffect, useRef, useState } from 'react'
3+
import { Snapshot, DndPanel } from '@logicflow/extension'
4+
5+
import {
6+
Button,
7+
Card,
8+
Col,
9+
Divider,
10+
Flex,
11+
Row,
12+
Space,
13+
Select,
14+
Input,
15+
} from 'antd'
616
import ImageNode from './imageNode'
17+
import Uml from './uml'
18+
import data from './data'
719

820
import styles from './index.less'
921
import '@logicflow/core/es/index.css'
@@ -13,7 +25,7 @@ const config: Partial<LogicFlow.Options> = {
1325
isSilentMode: false,
1426
stopScrollGraph: false,
1527
stopZoomGraph: false,
16-
stopMoveGraph: true,
28+
stopMoveGraph: false,
1729
style: {
1830
rect: {
1931
rx: 5,
@@ -41,80 +53,15 @@ const config: Partial<LogicFlow.Options> = {
4153
fontSize: 12,
4254
},
4355
},
56+
grid: {
57+
size: 20,
58+
},
4459
}
4560

46-
const data = {
47-
nodes: [
48-
{
49-
id: '1',
50-
type: 'rect',
51-
x: 150,
52-
y: 100,
53-
text: '矩形',
54-
},
55-
{
56-
id: '2',
57-
type: 'circle',
58-
x: 350,
59-
y: 100,
60-
text: '圆形',
61-
},
62-
{
63-
id: '3',
64-
type: 'image',
65-
x: 550,
66-
y: 100,
67-
text: '云',
68-
},
69-
{
70-
id: '4',
71-
type: 'polygon',
72-
x: 150,
73-
y: 250,
74-
text: '多边形',
75-
},
76-
{
77-
id: '5',
78-
type: 'image',
79-
x: 350,
80-
y: 250,
81-
text: '菱形',
82-
},
83-
{
84-
id: '6',
85-
type: 'text',
86-
x: 550,
87-
y: 250,
88-
text: '纯文本节点',
89-
},
90-
{
91-
id: '7',
92-
type: 'html',
93-
x: 150,
94-
y: 400,
95-
text: 'html节点',
96-
},
97-
],
98-
edges: [
99-
{
100-
id: 'e_1',
101-
type: 'polyline',
102-
sourceNodeId: '1',
103-
targetNodeId: '2',
104-
},
105-
{
106-
id: 'e_2',
107-
type: 'polyline',
108-
sourceNodeId: '2',
109-
targetNodeId: '3',
110-
},
111-
{
112-
id: 'e_3',
113-
type: 'polyline',
114-
sourceNodeId: '4',
115-
targetNodeId: '5',
116-
},
117-
],
61+
interface SnapshotResponse {
62+
data: Blob
63+
width: number
64+
height: number
11865
}
11966

12067
/**
@@ -123,6 +70,13 @@ const data = {
12370
export default function SnapshotExample() {
12471
const lfRef = useRef<LogicFlow>()
12572
const containerRef = useRef<HTMLDivElement>(null)
73+
74+
const [fileName, setFileName] = useState<string>() // 文件名
75+
const [fileType, setFileType] = useState<string>('png') // 下载的图片类型
76+
const [width, setWidth] = useState<string>() // 宽度
77+
const [height, setHeight] = useState<string>() // 高度
78+
const [padding, setPaddding] = useState<string>() //padding
79+
12680
const [blobData, setBlobData] = useState('')
12781
const [base64Data, setBase64Data] = useState('')
12882

@@ -132,12 +86,10 @@ export default function SnapshotExample() {
13286
const lf = new LogicFlow({
13387
...config,
13488
container: containerRef.current!,
135-
grid: {
136-
size: 20,
137-
},
138-
stopMoveGraph: false,
139-
plugins: [Snapshot],
89+
plugins: [Snapshot, DndPanel],
14090
})
91+
92+
lf.register(Uml)
14193
lf.register(ImageNode)
14294

14395
lf.on(
@@ -146,8 +98,34 @@ export default function SnapshotExample() {
14698
console.log('get selection area:', topLeft, bottomRight)
14799
},
148100
)
101+
102+
lf.setPatternItems([
103+
{
104+
type: 'circle',
105+
text: 'circle',
106+
label: 'circle',
107+
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAABGdBTUEAALGPC/xhBQAAAnBJREFUOBGdVL1rU1EcPfdGBddmaZLiEhdx1MHZQXApraCzQ7GKLgoRBxMfcRELuihWKcXFRcEWF8HBf0DdDCKYRZpnl7p0svLe9Zzbd29eQhTbC8nv+9zf130AT63jvooOGS8Vf9Nt5zxba7sXQwODfkWpkbjTQfCGUd9gIp3uuPP8bZ946g56dYQvnBg+b1HB8VIQmMFrazKcKSvFW2dQTxJnJdQ77urmXWOMBCmXM2Rke4S7UAW+/8ywwFoewmBps2tu7mbTdp8VMOkIRAkKfrVawalJTtIliclFbaOBqa0M2xImHeVIfd/nKAfVq/LGnPss5Kh00VEdSzfwnBXPUpmykNss4lUI9C1ga+8PNrBD5YeqRY2Zz8PhjooIbfJXjowvQJBqkmEkVnktWhwu2SM7SMx7Cj0N9IC0oQXRo8xwAGzQms+xrB/nNSUWVveI48ayrFGyC2+E2C+aWrZHXvOuz+CiV6iycWe1Rd1Q6+QUG07nb5SbPrL4426d+9E1axKjY3AoRrlEeSQo2Eu0T6BWAAr6COhTcWjRaYfKG5csnvytvUr/WY4rrPMB53Uo7jZRjXaG6/CFfNMaXEu75nG47X+oepU7PKJvvzGDY1YLSKHJrK7vFUwXKkaxwhCW3u+sDFMVrIju54RYYbFKpALZAo7sB6wcKyyrd+aBMryMT2gPyD6GsQoRFkGHr14TthZni9ck0z+Pnmee460mHXbRAypKNy3nuMdrWgVKj8YVV8E7PSzp1BZ9SJnJAsXdryw/h5ctboUVi4AFiCd+lQaYMw5z3LGTBKjLQOeUF35k89f58Vv/tGh+l+PE/wG0rgfIUbZK5AAAAABJRU5ErkJggg==',
108+
},
109+
{
110+
type: 'rect',
111+
label: 'rect',
112+
text: 'circle',
113+
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAEFVwZaAAAABGdBTUEAALGPC/xhBQAAAqlJREFUOBF9VM9rE0EUfrMJNUKLihGbpLGtaCOIR8VjQMGDePCgCCIiCNqzCAp2MyYUCXhUtF5E0D+g1t48qAd7CCLqQUQKEWkStcEfVGlLdp/fm3aW2QQdyLzf33zz5m2IsAZ9XhDpyaaIZkTS4ASzK41TFao88GuJ3hsr2pAbipHxuSYyKRugagICGANkfFnNh3HeE2N0b3nN2cgnpcictw5veJIzxmDamSlxxQZicq/mflxhbaH8BLRbuRwNtZp0JAhoplVRUdzmCe/vO27wFuuA3S5qXruGdboy5/PRGFsbFGKo/haRtQHIrM83bVeTrOgNhZReWaYGnE4aUQgTJNvijJFF4jQ8BxJE5xfKatZWmZcTQ+BVgh7s8SgPlCkcec4mGTmieTP4xd7PcpIEg1TX6gdeLW8rTVMVLVvb7ctXoH0Cydl2QOPJBG21STE5OsnbweVYzAnD3A7PVILuY0yiiyDwSm2g441r6rMSgp6iK42yqroI2QoXeJVeA+YeZSa47gZdXaZWQKTrG93rukk/l2Al6Kzh5AZEl7dDQy+JjgFahQjRopSxPbrbvK7GRe9ePWBo1wcU7sYrFZtavXALwGw/7Dnc50urrHJuTPSoO2IMV3gUQGNg87IbSOIY9BpiT9HV7FCZ94nPXb3MSnwHn/FFFE1vG6DTby+r31KAkUktB3Qf6ikUPWxW1BkXSPQeMHHiW0+HAd2GelJsZz1OJegCxqzl+CLVHa/IibuHeJ1HAKzhuDR+ymNaRFM+4jU6UWKXorRmbyqkq/D76FffevwdCp+jN3UAN/C9JRVTDuOxC/oh+EdMnqIOrlYteKSfadVRGLJFJPSB/ti/6K8f0CNymg/iH2gO/f0DwE0yjAFO6l8JaR5j0VPwPwfaYHqOqrCI319WzwhwzNW/aQAAAABJRU5ErkJggg==',
114+
},
115+
])
116+
117+
lf.extension.snapshot.useGlobalRules = false
118+
lf.extension.snapshot.customCssRules = `
119+
.uml-wrapper {
120+
line-height: 1.2;
121+
text-align: center;
122+
color: blue;
123+
}
124+
`
125+
149126
lf.render(data)
150-
lf.fitView()
127+
lf.translateCenter()
128+
151129
lfRef.current = lf
152130
}
153131
}, [])
@@ -201,17 +179,108 @@ export default function SnapshotExample() {
201179
)
202180
}
203181
}
182+
// 下载
183+
const downLoad = () => {
184+
lfRef.current &&
185+
lfRef.current.getSnapshot(fileName, {
186+
fileType,
187+
height: height,
188+
padding: padding,
189+
backgroundColor: 'yellow',
190+
partialElement: true,
191+
...(width ? { width } : {}),
192+
...(height ? { height } : {}),
193+
...(padding ? { padding } : {}),
194+
})
195+
}
196+
197+
// 预览
198+
// const preview = () => {
199+
// lfRef.current &&
200+
// lfRef.current
201+
// .getSnapshotBlob('#FFFFFF', fileType)
202+
// .then(({ data }: SnapshotResponse) => {
203+
// if (imgRef.current) {
204+
// imgRef.current.width = 500
205+
// imgRef.current.height = 400
206+
// imgRef.current.src = window.URL.createObjectURL(data)
207+
// }
208+
// })
209+
// }
210+
211+
// 打印base64地址
212+
const logBase64 = () => {
213+
lfRef.current &&
214+
lfRef.current
215+
.getSnapshotBase64(undefined, fileType)
216+
.then(({ data, width, height }: SnapshotResponse) => {
217+
// document.getElementById('img').src = data
218+
console.log(width, height, data)
219+
})
220+
}
204221

205222
return (
206223
<Card title="LogicFlow Extension - Snapshot">
224+
<div style={{ marginBottom: '10px' }}>
225+
<Space>
226+
<span>文件名:</span>
227+
<Input
228+
placeholder="文件名"
229+
value={fileName}
230+
onChange={(e) => setFileName(e.target.value)}
231+
/>
232+
<span>文件类型(默认png):</span>
233+
<Select
234+
defaultValue={fileType}
235+
style={{ width: 120 }}
236+
onChange={(value) => setFileType(value)}
237+
options={[
238+
{ value: 'png', label: 'png' },
239+
{ value: 'jpeg', label: 'jpeg' },
240+
{ value: 'webp', label: 'webp' },
241+
{ value: 'gif', label: 'gif' },
242+
]}
243+
/>
244+
<span>宽度</span>
245+
<Input
246+
placeholder="width"
247+
value={width}
248+
onChange={(e) => setWidth(e.target.value)}
249+
/>
250+
<span>高度</span>
251+
<Input
252+
placeholder="height"
253+
value={height}
254+
onChange={(e) => setHeight(e.target.value)}
255+
/>
256+
<span>padding</span>
257+
<Input
258+
placeholder="padding"
259+
value={padding}
260+
onChange={(e) => setPaddding(e.target.value)}
261+
/>
262+
<Button id="download" onClick={downLoad}>
263+
下载快照
264+
</Button>
265+
</Space>
266+
</div>
267+
<Divider />
268+
<Space>
269+
{/* <Button id="preview" onClick={preview}>
270+
预览
271+
</Button> */}
272+
<Button id="base64" onClick={logBase64}>
273+
打印base64
274+
</Button>
275+
</Space>
276+
<Divider />
207277
<Flex wrap="wrap" gap="middle" align="center" justify="space-between">
208278
<Space>
209279
<Button onClick={handleGetSnapshot}>下载快照</Button>
210280
<Button onClick={handlePreviewSnapshotBlob}>预览(blob)</Button>
211281
<Button onClick={handlePreviewSnapshotBase64}>预览(base64)</Button>
212282
</Space>
213283
</Flex>
214-
<Divider />
215284
<Row>
216285
<Col span={12}>
217286
<div ref={containerRef} id="graph" className={styles.viewport}></div>

0 commit comments

Comments
 (0)