11import { createPath , createMainPath , createLinkSvg } from './utils/svg'
22import { findEle , Expander } from './utils/dom'
3- import {
4- SIDE ,
5- GAP ,
6- TURNPOINT_R ,
7- PRIMARY_NODE_HORIZONTAL_GAP ,
8- PRIMARY_NODE_VERTICAL_GAP ,
9- } from './const'
3+ import { SIDE , GAP , TURNPOINT_R , PRIMARY_NODE_HORIZONTAL_GAP , PRIMARY_NODE_VERTICAL_GAP } from './const'
104
115/**
126 * Link nodes with svg,
@@ -134,8 +128,7 @@ export default function linkDiv(primaryNode) {
134128 // set position of expander
135129 const expander = el . children [ 0 ] . children [ 1 ]
136130 if ( expander ) {
137- expander . style . top =
138- ( expander . parentNode . offsetHeight - expander . offsetHeight ) / 2 + 'px'
131+ expander . style . top = ( expander . parentNode . offsetHeight - expander . offsetHeight ) / 2 + 'px'
139132 if ( el . className === 'lhs' ) {
140133 expander . style . left = - 10 + 'px'
141134 } else {
@@ -171,17 +164,13 @@ export default function linkDiv(primaryNode) {
171164 if ( typeof link . from === 'string' ) {
172165 this . createLink ( findEle ( link . from ) , findEle ( link . to ) , true , link )
173166 } else {
174- this . createLink (
175- findEle ( link . from . nodeObj . id ) ,
176- findEle ( link . to . nodeObj . id ) ,
177- true ,
178- link
179- )
167+ this . createLink ( findEle ( link . from . nodeObj . id ) , findEle ( link . to . nodeObj . id ) , true , link )
180168 }
181169 }
182170 console . timeEnd ( 'linkDiv' )
183171}
184172
173+ // core function of generate svg3rd
185174let path = ''
186175function loopChildren ( children : HTMLCollection , parent : HTMLElement , first ?: boolean ) {
187176 const parentOT = parent . offsetTop
@@ -207,10 +196,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
207196 xMiddle = parentOL
208197 x2 = parentOL - childT . offsetWidth
209198
210- if (
211- childTOT + childTOH < parentOT + parentOH / 2 + 50 &&
212- childTOT + childTOH > parentOT + parentOH / 2 - 50
213- ) {
199+ if ( childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50 ) {
214200 // 相差+-50内直接直线
215201 path += `M ${ x1 } ${ y1 } H ${ xMiddle } V ${ y2 } H ${ x2 } `
216202 } else if ( childTOT + childTOH >= parentOT + parentOH / 2 ) {
@@ -225,10 +211,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
225211 xMiddle = parentOL + parentOW
226212 x2 = parentOL + parentOW + childT . offsetWidth
227213
228- if (
229- childTOT + childTOH < parentOT + parentOH / 2 + 50 &&
230- childTOT + childTOH > parentOT + parentOH / 2 - 50
231- ) {
214+ if ( childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50 ) {
232215 path += `M ${ x1 } ${ y1 } H ${ xMiddle } V ${ y2 } H ${ x2 } `
233216 } else if ( childTOT + childTOH >= parentOT + parentOH / 2 ) {
234217 path += `M ${ x1 } ${ y1 } H ${ xMiddle } V ${ y2 - TURNPOINT_R } A ${ TURNPOINT_R } ${ TURNPOINT_R } 0 0 0 ${ xMiddle + TURNPOINT_R } ${ y2 } H ${ x2 } `
@@ -239,8 +222,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
239222
240223 const expander = childT . children [ 1 ] as Expander
241224 if ( expander ) {
242- expander . style . top =
243- ( childT . offsetHeight - expander . offsetHeight ) / 2 + 'px'
225+ expander . style . top = ( childT . offsetHeight - expander . offsetHeight ) / 2 + 'px'
244226 if ( direction === 'lhs' ) {
245227 expander . style . left = - 10 + 'px'
246228 } else if ( direction === 'rhs' ) {
0 commit comments