-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 优化画布移动时,小地图的更新策略,减少性能消耗 - 小地图显示区域计算逻辑修改,现在由画布元素与视口共同决定 - 优化小地图预览视窗的拖拽交互 - 修复点击小地图预览视窗会触发不可预期的画布移动的问题 - 新增小地图插件的示例
- Loading branch information
1 parent
aad9fd0
commit 74a0882
Showing
6 changed files
with
376 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
examples/feature-examples/src/pages/extensions/mini-map/index.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.viewport { | ||
position: relative; | ||
height: calc(100vh - 250px); | ||
overflow: hidden; | ||
} |
140 changes: 140 additions & 0 deletions
140
examples/feature-examples/src/pages/extensions/mini-map/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import LogicFlow from '@logicflow/core' | ||
import { Control, MiniMap } from '@logicflow/extension' | ||
|
||
import { Button, Card, Flex, Divider } from 'antd' | ||
import { useState, useEffect, useRef } from 'react' | ||
import styles from './index.less' | ||
|
||
import '@logicflow/core/es/index.css' | ||
import '@logicflow/extension/es/index.css' | ||
|
||
const config: Partial<LogicFlow.Options> = { | ||
isSilentMode: false, | ||
stopScrollGraph: true, | ||
stopZoomGraph: true, | ||
style: { | ||
rect: { | ||
rx: 5, | ||
ry: 5, | ||
strokeWidth: 2, | ||
}, | ||
circle: { | ||
fill: '#f5f5f5', | ||
stroke: '#666', | ||
}, | ||
ellipse: { | ||
fill: '#dae8fc', | ||
stroke: '#6c8ebf', | ||
}, | ||
polygon: { | ||
fill: '#d5e8d4', | ||
stroke: '#82b366', | ||
}, | ||
diamond: { | ||
fill: '#ffe6cc', | ||
stroke: '#d79b00', | ||
}, | ||
text: { | ||
color: '#b85450', | ||
fontSize: 12, | ||
}, | ||
}, | ||
} | ||
|
||
const nodes: LogicFlow.NodeConfig[] = [] | ||
const edges: LogicFlow.EdgeConfig[] = [] | ||
|
||
for (let i = 0; i < 200; i++) { | ||
const nodeStartId = `${i * 2 + 1}` | ||
const nodeEndId = `${i * 2 + 2}` | ||
const nodeStart: LogicFlow.NodeConfig = { | ||
id: nodeStartId, | ||
type: 'rect', | ||
x: 400 * (i % 10) - 200, | ||
y: 100 * Math.floor(i / 10) - 500, | ||
text: `${i}-start`, | ||
} | ||
const nodeEnd: LogicFlow.NodeConfig = { | ||
id: nodeEndId, | ||
type: 'rect', | ||
x: 400 * (i % 10), | ||
y: 100 * Math.floor(i / 10) - 500, | ||
text: `${i}-end`, | ||
} | ||
const edge: LogicFlow.EdgeConfig = { | ||
id: `e_${i}`, | ||
type: 'polyline', | ||
sourceNodeId: nodeStartId, | ||
targetNodeId: nodeEndId, | ||
} | ||
nodes.push(nodeStart) | ||
nodes.push(nodeEnd) | ||
edges.push(edge) | ||
} | ||
|
||
const data: LogicFlow.GraphConfigData = { | ||
nodes, | ||
edges, | ||
} | ||
|
||
export default function MiniMapExtension() { | ||
const lfRef = useRef<LogicFlow>() | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
const [visible, setVisible] = useState(false) | ||
|
||
useEffect(() => { | ||
if (!lfRef.current) { | ||
const lf = new LogicFlow({ | ||
...config, | ||
container: containerRef.current as HTMLElement, | ||
grid: { | ||
size: 20, | ||
}, | ||
plugins: [Control, MiniMap], | ||
pluginsOptions: { | ||
MiniMap: { | ||
isShowHeader: false, | ||
isShowCloseIcon: true, | ||
headerTitle: 'MiniMap', | ||
width: 200, | ||
height: 120, | ||
}, | ||
}, | ||
}) | ||
|
||
lf.render(data) | ||
lfRef.current = lf | ||
} | ||
}, []) | ||
|
||
const toggleVisible = () => { | ||
if (lfRef.current) { | ||
const miniMap = lfRef.current.extension.miniMap as MiniMap | ||
if (visible) { | ||
miniMap.hide() | ||
} else { | ||
miniMap.show(0, 0) | ||
} | ||
setVisible(!visible) | ||
} | ||
} | ||
|
||
const handleReset = () => { | ||
if (lfRef.current) { | ||
;(lfRef.current.extension.miniMap as MiniMap).reset() | ||
} | ||
} | ||
|
||
return ( | ||
<Card title="LogicFlow Extension - MiniMap"> | ||
<Flex wrap="wrap" gap="small"> | ||
<Button onClick={toggleVisible}> | ||
{visible ? '隐藏' : '显示'}小地图 | ||
</Button> | ||
{visible && <Button onClick={handleReset}>重置</Button>} | ||
</Flex> | ||
<Divider /> | ||
<div ref={containerRef} id="graph" className={styles.viewport}></div> | ||
</Card> | ||
) | ||
} |
Oops, something went wrong.