提交 56439d60 编写于 作者: D deqingli

refactor(sankey): refactor the code

上级 7fa25721
...@@ -80,9 +80,8 @@ function getViewRect(seriesModel, api) { ...@@ -80,9 +80,8 @@ 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) {
var kx = computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign); 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);
} }
...@@ -147,9 +146,6 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod ...@@ -147,9 +146,6 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
node.setLayout({x: x}, true); node.setLayout({x: x}, true);
node.setLayout({dx: nodeWidth}, true); node.setLayout({dx: nodeWidth}, true);
} }
// node.setLayout({skDepth: x}, true);
for (var edgeIdx = 0; edgeIdx < node.outEdges.length; edgeIdx++) { for (var edgeIdx = 0; edgeIdx < node.outEdges.length; edgeIdx++) {
var edge = node.outEdges[edgeIdx]; var edge = node.outEdges[edgeIdx];
var indexEdge = edges.indexOf(edge); var indexEdge = edges.indexOf(edge);
...@@ -228,7 +224,12 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod ...@@ -228,7 +224,12 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
if (item.depth > maxDepth) { if (item.depth > maxDepth) {
maxDepth = item.depth; maxDepth = item.depth;
} }
node.setLayout({skDepth: item.depth}, true); if (orient === 'vertical') {
node.setLayout({y: item.depth}, true);
}
else {
node.setLayout({x: item.depth}, true);
}
} }
}); });
...@@ -238,9 +239,8 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod ...@@ -238,9 +239,8 @@ function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nod
else { else {
kx = (width - nodeWidth) / maxDepth; kx = (width - nodeWidth) / maxDepth;
} }
return kx;
// scaleNodeBreadths(nodes, kx, orient); scaleNodeBreadths(nodes, kx, orient);
} }
/** /**
...@@ -272,24 +272,13 @@ function moveSinksRight(nodes, x, orient) { ...@@ -272,24 +272,13 @@ 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 (node.getLayout().skDepth) { if (orient === 'vertical') {
var depth = node.getLayout().skDepth * kx; var nodeY = node.getLayout().y * kx;
if (orient === 'vertical') { node.setLayout({y: nodeY}, true);
node.setLayout({y: depth}, true);
}
else {
node.setLayout({x: depth}, true);
}
} }
else { else {
if (orient === 'vertical') { var nodeX = node.getLayout().x * kx;
var nodeY = node.getLayout().y * kx; node.setLayout({x: nodeX}, true);
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.
先完成此消息的编辑!
想要评论请 注册