@@ -20,7 +20,7 @@ export default function linkDiv(primaryNode) {
2020 const root = this . root
2121 root . style . cssText = `top:${ 10000 - root . offsetHeight / 2 } px;left:${ 10000 - root . offsetWidth / 2 } px;`
2222 const primaryNodeList = this . box . children
23- this . svg2nd . innerHTML = ''
23+ this . lines . innerHTML = ''
2424
2525 // 1. calculate position of primary nodes
2626 let totalHeight = 0
@@ -136,7 +136,7 @@ export default function linkDiv(primaryNode) {
136136 }
137137 }
138138 }
139- this . svg2nd . appendChild ( createMainPath ( primaryPath ) )
139+ this . lines . appendChild ( createMainPath ( primaryPath ) )
140140
141141 // 3. generate link inside primary node
142142 for ( let i = 0 ; i < primaryNodeList . length ; i ++ ) {
@@ -145,14 +145,13 @@ export default function linkDiv(primaryNode) {
145145 continue
146146 }
147147 if ( el . childElementCount ) {
148- const svg = createLinkSvg ( 'svg3rd ' )
148+ const svg = createLinkSvg ( 'subLines ' )
149149 // svg tag name is lower case
150150 if ( el . lastChild . tagName === 'svg' ) el . lastChild . remove ( )
151151 el . appendChild ( svg )
152152 const parent = el . children [ 0 ]
153153 const children = el . children [ 1 ] . children
154- path = ''
155- loopChildren ( children , parent , true )
154+ const path = traverseChildren ( children , parent , true )
156155 svg . appendChild ( createPath ( path ) )
157156 }
158157 }
@@ -170,9 +169,9 @@ export default function linkDiv(primaryNode) {
170169 console . timeEnd ( 'linkDiv' )
171170}
172171
173- // core function of generate svg3rd
174- let path = ''
175- function loopChildren ( children : HTMLCollection , parent : HTMLElement , first ?: boolean ) {
172+ // core function of generate subLines
173+ function traverseChildren ( children : HTMLCollection , parent : HTMLElement , first ?: boolean ) : string {
174+ let path = ''
176175 const parentOT = parent . offsetTop
177176 const parentOL = parent . offsetLeft
178177 const parentOW = parent . offsetWidth
@@ -197,7 +196,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
197196 x2 = parentOL - childT . offsetWidth + GAP
198197
199198 if ( childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50 ) {
200- // straight line
199+ // draw straight line if the distance is between +-50
201200 path += `M ${ x1 } ${ y1 } H ${ xMiddle } V ${ y2 } H ${ x2 } `
202201 } else if ( childTOT + childTOH >= parentOT + parentOH / 2 ) {
203202 // child bottom lower than parent
@@ -234,8 +233,9 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
234233 // expander not exist
235234 continue
236235 }
237- // traversal
236+
238237 const nextChildren = child . children [ 1 ] . children
239- if ( nextChildren . length > 0 ) loopChildren ( nextChildren , childT )
238+ if ( nextChildren . length > 0 ) { path += traverseChildren ( nextChildren , childT ) }
240239 }
240+ return path
241241}
0 commit comments