Skip to content

Commit

Permalink
fix(devtools): lines drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Oct 10, 2024
1 parent eacdb02 commit d5a6283
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/devtools/src/Graph/reatomLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ export const reatomLines = (name: string): Lines => {
const containerRec = svg.getBoundingClientRect()
let points = ''

const calc = (to: AtomCache, from: AtomCache): null | AtomCache => {
if (highlighted.has(to)) return null
const calc = (target: AtomCache, cause: AtomCache): undefined | null | AtomCache => {
if (highlighted.has(target)) return null

const toRec = document.getElementById(getId(to))?.getBoundingClientRect()
const fromEl = document.getElementById(getId(from))
const toRec = document.getElementById(getId(target))?.getBoundingClientRect()
const fromEl = document.getElementById(getId(cause))
const fromRec = fromEl?.getBoundingClientRect()

if (!toRec || !fromRec) {
return from
return cause.cause?.cause && calc(target, cause.cause)
}

// @ts-expect-error
if (fromEl?.computedStyleMap().get('display')?.value === 'none') {
return from.cause && calc(to, from.cause)
return cause.cause?.cause && calc(target, cause.cause)
}

const toX = 70 + toRec.x + -containerRec.x
Expand All @@ -61,16 +61,14 @@ export const reatomLines = (name: string): Lines => {

points += `${toX},${toY} ${middleX},${middleY} ${fromX},${fromY} `

highlighted.add(to)
highlighted.add(target)

return from
return cause
}

let target: null | AtomCache = patch
while (target && target.cause) {
target = calc(target, target.cause!)

if (!target?.cause?.cause) break
let target: undefined | null | AtomCache = patch
while (target && target.cause?.cause) {
target = calc(target, target.cause)
}

return (
Expand Down

0 comments on commit d5a6283

Please sign in to comment.