Skip to content

Commit 8774ef1

Browse files
committed
fix: update arrow hotzone position during drag operations
1 parent 49745ec commit 8774ef1

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/arrow.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ function updateArrowPath(
135135
p4y: number,
136136
linkItem: Arrow
137137
) {
138+
const mainPath = `M ${p1x} ${p1y} C ${p2x} ${p2y} ${p3x} ${p3y} ${p4x} ${p4y}`
139+
138140
// Update main path
139-
arrow.line.setAttribute('d', `M ${p1x} ${p1y} C ${p2x} ${p2y} ${p3x} ${p3y} ${p4x} ${p4y}`)
141+
arrow.line.setAttribute('d', mainPath)
140142

141143
// Apply styles to the main line if they exist
142144
if (linkItem.style) {
@@ -148,10 +150,22 @@ function updateArrowPath(
148150
if (style.opacity !== undefined) arrow.line.setAttribute('opacity', String(style.opacity))
149151
}
150152

153+
// Update hotzone for main path (find the first hotzone path which corresponds to the main line)
154+
const hotzones = arrow.querySelectorAll('path[stroke="transparent"]')
155+
if (hotzones.length > 0) {
156+
hotzones[0].setAttribute('d', mainPath)
157+
}
158+
151159
// Update arrow head
152160
const arrowPoint = getArrowPoints(p3x, p3y, p4x, p4y)
153161
if (arrowPoint) {
154-
arrow.arrow1.setAttribute('d', `M ${arrowPoint.x1} ${arrowPoint.y1} L ${p4x} ${p4y} L ${arrowPoint.x2} ${arrowPoint.y2}`)
162+
const arrowPath1 = `M ${arrowPoint.x1} ${arrowPoint.y1} L ${p4x} ${p4y} L ${arrowPoint.x2} ${arrowPoint.y2}`
163+
arrow.arrow1.setAttribute('d', arrowPath1)
164+
165+
// Update hotzone for arrow1
166+
if (hotzones.length > 1) {
167+
hotzones[1].setAttribute('d', arrowPath1)
168+
}
155169

156170
// Apply styles to arrow head
157171
if (linkItem.style) {
@@ -167,7 +181,13 @@ function updateArrowPath(
167181
if (linkItem.bidirectional) {
168182
const arrowPointStart = getArrowPoints(p2x, p2y, p1x, p1y)
169183
if (arrowPointStart) {
170-
arrow.arrow2.setAttribute('d', `M ${arrowPointStart.x1} ${arrowPointStart.y1} L ${p1x} ${p1y} L ${arrowPointStart.x2} ${arrowPointStart.y2}`)
184+
const arrowPath2 = `M ${arrowPointStart.x1} ${arrowPointStart.y1} L ${p1x} ${p1y} L ${arrowPointStart.x2} ${arrowPointStart.y2}`
185+
arrow.arrow2.setAttribute('d', arrowPath2)
186+
187+
// Update hotzone for arrow2
188+
if (hotzones.length > 2) {
189+
hotzones[2].setAttribute('d', arrowPath2)
190+
}
171191

172192
// Apply styles to start arrow head
173193
if (linkItem.style) {

0 commit comments

Comments
 (0)