提交 27687a7a 编写于 作者: 1 100pah 提交者: sushuang

fix: tweak #12191 (when edge value sum is 0, edge and node disappear)

上级 8c2267d4
......@@ -400,7 +400,13 @@ function relaxRightToLeft(nodesByBreadth, alpha, orient) {
zrUtil.each(nodes, function (node) {
if (node.outEdges.length) {
var y = sum(node.outEdges, weightedTarget, orient)
/ sum(node.outEdges, getEdgeValue, orient);
/ sum(node.outEdges, getEdgeValue, orient);
if (isNaN(y)) {
var len = node.outEdges.length;
y = len ? sum(node.outEdges, centerTarget, orient) / len : 0;
}
if (orient === 'vertical') {
var nodeX = node.getLayout().x + (y - center(node, orient)) * alpha;
node.setLayout({x: nodeX}, true);
......@@ -417,10 +423,16 @@ function relaxRightToLeft(nodesByBreadth, alpha, orient) {
function weightedTarget(edge, orient) {
return center(edge.node2, orient) * edge.getValue();
}
function centerTarget(edge, orient) {
return center(edge.node2, orient);
}
function weightedSource(edge, orient) {
return center(edge.node1, orient) * edge.getValue();
}
function centerSource(edge, orient) {
return center(edge.node1, orient);
}
function center(node, orient) {
return orient === 'vertical'
......@@ -456,9 +468,15 @@ function relaxLeftToRight(nodesByBreadth, alpha, orient) {
zrUtil.each(nodesByBreadth, function (nodes) {
zrUtil.each(nodes, function (node) {
if (node.inEdges.length) {
var y = sum(node.inEdges, weightedSource, orient)
/ sum(node.inEdges, getEdgeValue, orient);
isNaN(y) && (y = 0);
/ sum(node.inEdges, getEdgeValue, orient);
if (isNaN(y)) {
var len = node.inEdges.length;
y = len ? sum(node.inEdges, centerSource, orient) / len : 0;
}
if (orient === 'vertical') {
var nodeX = node.getLayout().x + (y - center(node, orient)) * alpha;
node.setLayout({x: nodeX}, true);
......
......@@ -83,7 +83,7 @@ under the License.
{
source: 'a',
target: 'b1',
value: 3
value: 0
},
{
source: 'b1',
......@@ -93,16 +93,24 @@ under the License.
{
source: 'b1',
target: 'c',
value: 2
value: 3
},
{
source: 'b',
target: 'c',
value: 1
value: 3
}
]
};
for (var i = 0; i < testData.nodes.length; i++) {
testData.nodes[i].tooltip = {
formatter: function () {
return 'hello';
}
}
}
chart.setOption({
color: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061'],
tooltip: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册