提交 7fa25721 编写于 作者: D deqingli

feat(sankey): support specify the node depth with constant y position

上级 527f8416
...@@ -80,8 +80,9 @@ function getViewRect(seriesModel, api) { ...@@ -80,8 +80,9 @@ function getViewRect(seriesModel, api) {
} }
function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign) { 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); computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient);
scaleNodeBreadths(nodes, kx, orient);
computeEdgeDepths(nodes, orient); computeEdgeDepths(nodes, orient);
} }
...@@ -227,12 +228,7 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod ...@@ -227,12 +228,7 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
if (item.depth > maxDepth) { if (item.depth > maxDepth) {
maxDepth = item.depth; maxDepth = item.depth;
} }
if (orient === 'vertical') { node.setLayout({skDepth: item.depth}, true);
node.setLayout({y: item.depth}, true);
}
else {
node.setLayout({x: item.depth}, true);
}
} }
}); });
...@@ -242,7 +238,9 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod ...@@ -242,7 +238,9 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
else { else {
kx = (width - nodeWidth) / maxDepth; kx = (width - nodeWidth) / maxDepth;
} }
scaleNodeBreadths(nodes, kx, orient); return kx;
// scaleNodeBreadths(nodes, kx, orient);
} }
/** /**
...@@ -274,13 +272,24 @@ function moveSinksRight(nodes, x, orient) { ...@@ -274,13 +272,24 @@ function moveSinksRight(nodes, x, orient) {
*/ */
function scaleNodeBreadths(nodes, kx, orient) { function scaleNodeBreadths(nodes, kx, orient) {
zrUtil.each(nodes, function (node) { zrUtil.each(nodes, function (node) {
if (orient === 'vertical') { if (node.getLayout().skDepth) {
var nodeY = node.getLayout().y * kx; var depth = node.getLayout().skDepth * kx;
node.setLayout({y: nodeY}, true); if (orient === 'vertical') {
node.setLayout({y: depth}, true);
}
else {
node.setLayout({x: depth}, true);
}
} }
else { else {
var nodeX = node.getLayout().x * kx; if (orient === 'vertical') {
node.setLayout({x: nodeX}, true); var nodeY = node.getLayout().y * kx;
node.setLayout({y: nodeY}, true);
}
else {
var nodeX = node.getLayout().x * kx;
node.setLayout({x: nodeX}, true);
}
} }
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册