16 lines
739 B
TypeScript
16 lines
739 B
TypeScript
export function createPath(container: DOMRect, start: DOMRect, end: DOMRect) {
|
|
const startX = Math.round(start.x + start.width / 2 - container.x)
|
|
const startY = Math.round(start.bottom - container.y)
|
|
const endX = Math.round(end.x + end.width / 2 - container.x)
|
|
const endY = Math.round(end.top - container.y)
|
|
const mid = Math.round((start.bottom + end.top) / 2 - container.y)
|
|
return `M${startX},${startY} C${startX},${mid} ${endX},${mid} ${endX},${endY}`
|
|
}
|
|
|
|
export function drawLine(container: DOMRect, elem: DOMRect) {
|
|
const x = Math.round(elem.x + elem.width / 2 - container.x)
|
|
const top = Math.round(elem.top - container.y)
|
|
const bottom = Math.round(elem.bottom - container.y)
|
|
return `M${x},${top} L${x},${bottom}`
|
|
}
|