From 7fa2572129a3bd76b6eadd6267499a957adc5c30 Mon Sep 17 00:00:00 2001 From: deqingli Date: Thu, 18 Oct 2018 21:20:26 +0800 Subject: [PATCH] feat(sankey): support specify the node depth with constant y position --- src/chart/sankey/sankeyLayout.js | 35 ++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/chart/sankey/sankeyLayout.js b/src/chart/sankey/sankeyLayout.js index 37fde8712..8ea50205c 100644 --- a/src/chart/sankey/sankeyLayout.js +++ b/src/chart/sankey/sankeyLayout.js @@ -80,8 +80,9 @@ function getViewRect(seriesModel, api) { } function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign) { - computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign); + var kx = computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign); computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient); + scaleNodeBreadths(nodes, kx, orient); computeEdgeDepths(nodes, orient); } @@ -227,12 +228,7 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod if (item.depth > maxDepth) { maxDepth = item.depth; } - if (orient === 'vertical') { - node.setLayout({y: item.depth}, true); - } - else { - node.setLayout({x: item.depth}, true); - } + node.setLayout({skDepth: item.depth}, true); } }); @@ -242,7 +238,9 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod else { kx = (width - nodeWidth) / maxDepth; } - scaleNodeBreadths(nodes, kx, orient); + return kx; + + // scaleNodeBreadths(nodes, kx, orient); } /** @@ -274,13 +272,24 @@ function moveSinksRight(nodes, x, orient) { */ function scaleNodeBreadths(nodes, kx, orient) { zrUtil.each(nodes, function (node) { - if (orient === 'vertical') { - var nodeY = node.getLayout().y * kx; - node.setLayout({y: nodeY}, true); + if (node.getLayout().skDepth) { + var depth = node.getLayout().skDepth * kx; + if (orient === 'vertical') { + node.setLayout({y: depth}, true); + } + else { + node.setLayout({x: depth}, true); + } } else { - var nodeX = node.getLayout().x * kx; - node.setLayout({x: nodeX}, true); + if (orient === 'vertical') { + var nodeY = node.getLayout().y * kx; + node.setLayout({y: nodeY}, true); + } + else { + var nodeX = node.getLayout().x * kx; + node.setLayout({x: nodeX}, true); + } } }); } -- GitLab