MCPcopy Index your code
hub / github.com/apache/echarts / initializeNodeDepth

Function initializeNodeDepth

src/chart/sankey/sankeyLayout.ts:308–350  ·  view source on GitHub ↗

* Compute the original y-position for each node

(
    nodesByBreadth: GraphNode[][],
    edges: GraphEdge[],
    height: number,
    width: number,
    nodeGap: number,
    orient: LayoutOrient
)

Source from the content-addressed store, hash-verified

306 * Compute the original y-position for each node
307 */
308function 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)

Callers 1

computeNodeDepthsFunction · 0.85

Calls 4

getLayoutMethod · 0.65
setLayoutMethod · 0.65
getValueMethod · 0.65
eachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…