* Compute the original y-position for each node
(
nodesByBreadth: GraphNode[][],
edges: GraphEdge[],
height: number,
width: number,
nodeGap: number,
orient: LayoutOrient
)
| 306 | * Compute the original y-position for each node |
| 307 | */ |
| 308 | function initializeNodeDepth( |
| 309 | nodesByBreadth: GraphNode[][], |
| 310 | edges: GraphEdge[], |
| 311 | height: number, |
| 312 | width: number, |
| 313 | nodeGap: number, |
| 314 | orient: LayoutOrient |
| 315 | ) { |
| 316 | let minKy = Infinity; |
| 317 | zrUtil.each(nodesByBreadth, function (nodes) { |
| 318 | const n = nodes.length; |
| 319 | let sum = 0; |
| 320 | zrUtil.each(nodes, function (node) { |
| 321 | sum += node.getLayout().value; |
| 322 | }); |
| 323 | const ky = orient === 'vertical' |
| 324 | ? (width - (n - 1) * nodeGap) / sum |
| 325 | : (height - (n - 1) * nodeGap) / sum; |
| 326 | |
| 327 | if (ky < minKy) { |
| 328 | minKy = ky; |
| 329 | } |
| 330 | }); |
| 331 | |
| 332 | zrUtil.each(nodesByBreadth, function (nodes) { |
| 333 | zrUtil.each(nodes, function (node, i) { |
| 334 | const nodeDy = node.getLayout().value * minKy; |
| 335 | if (orient === 'vertical') { |
| 336 | node.setLayout({x: i}, true); |
| 337 | node.setLayout({dx: nodeDy}, true); |
| 338 | } |
| 339 | else { |
| 340 | node.setLayout({y: i}, true); |
| 341 | node.setLayout({dy: nodeDy}, true); |
| 342 | } |
| 343 | }); |
| 344 | }); |
| 345 | |
| 346 | zrUtil.each(edges, function (edge) { |
| 347 | const edgeDy = +edge.getValue() * minKy; |
| 348 | edge.setLayout({dy: edgeDy}, true); |
| 349 | }); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Resolve the collision of initialized depth (y-position) |
no test coverage detected
searching dependent graphs…