fix(canvas): 节点间连线去重并放大弯折点
This commit is contained in:
@@ -726,7 +726,7 @@ defineExpose({
|
|||||||
class="cv-edge-bend"
|
class="cv-edge-bend"
|
||||||
:cx="p.handle.x"
|
:cx="p.handle.x"
|
||||||
:cy="p.handle.y"
|
:cy="p.handle.y"
|
||||||
r="5"
|
r="8"
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
@@ -123,10 +123,14 @@ export function normalizeDoc(raw) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Array.isArray(raw.edges)) {
|
if (Array.isArray(raw.edges)) {
|
||||||
|
const pairs = new Set() // 同一对节点只保留一条线(旧文档可能有重复)
|
||||||
for (const e of raw.edges) {
|
for (const e of raw.edges) {
|
||||||
if (!e || typeof e.id !== 'string') continue
|
if (!e || typeof e.id !== 'string') continue
|
||||||
if (typeof e.from !== 'string' || typeof e.to !== 'string') continue
|
if (typeof e.from !== 'string' || typeof e.to !== 'string') continue
|
||||||
if (!ids.has(e.from) || !ids.has(e.to) || e.from === e.to) continue
|
if (!ids.has(e.from) || !ids.has(e.to) || e.from === e.to) continue
|
||||||
|
const pair = e.from < e.to ? `${e.from}|${e.to}` : `${e.to}|${e.from}`
|
||||||
|
if (pairs.has(pair)) continue
|
||||||
|
pairs.add(pair)
|
||||||
const edge = { id: e.id, from: e.from, to: e.to }
|
const edge = { id: e.id, from: e.from, to: e.to }
|
||||||
if (['top', 'right', 'bottom', 'left'].includes(e.fromSide)) edge.fromSide = e.fromSide
|
if (['top', 'right', 'bottom', 'left'].includes(e.fromSide)) edge.fromSide = e.fromSide
|
||||||
if (['top', 'right', 'bottom', 'left'].includes(e.toSide)) edge.toSide = e.toSide
|
if (['top', 'right', 'bottom', 'left'].includes(e.toSide)) edge.toSide = e.toSide
|
||||||
|
|||||||
@@ -378,7 +378,8 @@ function deleteSelection() {
|
|||||||
|
|
||||||
// ---- 手动连线 ----
|
// ---- 手动连线 ----
|
||||||
function onLinkCreate({ from, to, fromSide, toSide }) {
|
function onLinkCreate({ from, to, fromSide, toSide }) {
|
||||||
if (doc.edges.some((e) => e.from === from && e.to === to)) return // 去重
|
// 任意方向去重:两个节点之间只允许一条连线
|
||||||
|
if (doc.edges.some((e) => (e.from === from && e.to === to) || (e.from === to && e.to === from))) return
|
||||||
doc.edges.push({ id: newId('e'), from, to, fromSide, toSide })
|
doc.edges.push({ id: newId('e'), from, to, fromSide, toSide })
|
||||||
pushHistory()
|
pushHistory()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user